Annotation of parser3/src/types/pa_vfile.h, revision 1.26
1.4 paf 1: /** @file
1.18 paf 2: Parser: @b file parser type decl.
1.4 paf 3:
1.1 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.4 paf 5:
1.1 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
7:
1.26 ! paf 8: $Id: pa_vfile.h,v 1.25 2001/04/28 15:22:50 paf Exp $
1.1 paf 9: */
10:
11: #ifndef PA_VFILE_H
12: #define PA_VFILE_H
13:
1.25 paf 14: #include "classes.h"
1.1 paf 15: #include "pa_common.h"
16: #include "pa_globals.h"
1.3 paf 17: #include "pa_vstateless_object.h"
1.23 paf 18:
19: extern Methoded *file_class;
1.1 paf 20:
1.22 paf 21: /** holds received from user or read from disk file.
1.1 paf 22:
1.4 paf 23: @see VForm
24: */
1.3 paf 25: class VFile : public VStateless_object {
1.1 paf 26: public: // Value
27:
28: const char *type() const { return "file"; }
29:
1.2 paf 30: /// VFile: this
1.11 paf 31: Value *as_expr_result(bool return_string_as_is=false) { return this; }
32:
1.2 paf 33: /// VFile: true
1.11 paf 34: bool as_bool() { return true; }
1.2 paf 35:
1.16 paf 36: /// VFile: this
1.19 paf 37: const VFile *as_vfile(String::Untaint_lang lang=String::UL_UNSPECIFIED) const {
38: return this;
39: }
1.16 paf 40:
1.2 paf 41: /// VFile: CLASS,BASE,method,field
1.1 paf 42: Value *VFile::get_element(const String& aname) {
43: // $CLASS,$BASE,$method
1.3 paf 44: if(Value *result=VStateless_object::get_element(aname))
1.1 paf 45: return result;
46:
1.12 paf 47: // $name, $size, $text
1.16 paf 48: return static_cast<Value *>(ffields.get(aname));
1.1 paf 49: }
1.7 paf 50:
51: protected: // VAliased
52:
1.10 paf 53: /// disable .CLASS element. @see VAliased::get_element
1.15 paf 54: bool hide_class() { return true; }
1.1 paf 55:
56: public: // usage
57:
1.13 paf 58: VFile::VFile(Pool& apool) : VStateless_object(apool, *file_class),
59: fvalue_ptr(0),
60: fvalue_size(0),
1.16 paf 61: ffields(apool) {
1.13 paf 62: }
1.1 paf 63:
1.17 paf 64: void set(bool tainted,
65: const void *avalue_ptr, size_t avalue_size, const char *afile_name=0,
1.14 paf 66: const String *amime_type=0);
1.13 paf 67:
1.6 paf 68: void save(const String& file_spec) {
1.13 paf 69: if(fvalue_ptr)
70: file_write(pool(), file_spec, fvalue_ptr, fvalue_size, false);
71: else
72: THROW(0, 0,
73: &file_spec,
1.18 paf 74: "saving stat-ed file");
1.1 paf 75: }
76:
1.18 paf 77: const void *value_ptr() const {
78: if(!fvalue_ptr)
79: THROW(0, 0,
80: 0,
81: "getting value of stat-ed file");
82:
83: return fvalue_ptr;
84: }
1.16 paf 85: size_t value_size() const { return fvalue_size; }
1.21 paf 86: Hash& fields() { return ffields; }
87: const Hash& fields() const { return ffields; }
1.16 paf 88:
1.1 paf 89: private:
90:
1.12 paf 91: const void *fvalue_ptr;
1.1 paf 92: size_t fvalue_size;
1.16 paf 93: Hash ffields;
1.1 paf 94:
95: };
96:
97: #endif
E-mail: