Annotation of parser3/src/types/pa_vfile.h, revision 1.36
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)
5: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
6:
1.36 ! parser 7: $Id: pa_vfile.h,v 1.35 2001/10/09 08:13:04 parser Exp $
1.1 paf 8: */
9:
10: #ifndef PA_VFILE_H
11: #define PA_VFILE_H
12:
1.25 paf 13: #include "classes.h"
1.1 paf 14: #include "pa_common.h"
15: #include "pa_globals.h"
1.3 paf 16: #include "pa_vstateless_object.h"
1.23 paf 17:
18: extern Methoded *file_class;
1.1 paf 19:
1.22 paf 20: /** holds received from user or read from disk file.
1.1 paf 21:
1.4 paf 22: @see VForm
23: */
1.3 paf 24: class VFile : public VStateless_object {
1.1 paf 25: public: // Value
26:
27: const char *type() const { return "file"; }
1.11 paf 28:
1.2 paf 29: /// VFile: true
1.33 parser 30: bool as_bool() const { return true; }
1.35 parser 31:
32: /// VFile: true
33: Value *as_expr_result(bool return_string_as_is=false) { return NEW VBool(pool(), as_bool()); }
1.2 paf 34:
1.16 paf 35: /// VFile: this
1.27 parser 36: VFile *as_vfile(String::Untaint_lang lang=String::UL_UNSPECIFIED,
37: bool origins_mode=false) {
1.19 paf 38: return this;
39: }
1.16 paf 40:
1.28 parser 41: /// VFile: CLASS,method,field
1.1 paf 42: Value *VFile::get_element(const String& aname) {
1.28 parser 43: // $CLASS,$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.31 parser 66: Value *amime_type=0);
1.13 paf 67:
1.29 parser 68: void save(const String& file_spec, bool is_text) {
1.13 paf 69: if(fvalue_ptr)
1.29 parser 70: file_write(pool(), file_spec, fvalue_ptr, fvalue_size, is_text);
1.13 paf 71: else
1.36 ! parser 72: throw Exception(0, 0,
1.13 paf 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)
1.36 ! parser 79: throw Exception(0, 0,
1.18 paf 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.30 parser 88:
89: private:
90:
91: Value *fields_element();
1.16 paf 92:
1.1 paf 93: private:
94:
1.12 paf 95: const void *fvalue_ptr;
1.1 paf 96: size_t fvalue_size;
1.16 paf 97: Hash ffields;
1.1 paf 98:
99: };
100:
101: #endif
E-mail: