Annotation of parser3/src/types/pa_vfile.h, revision 1.61
1.4 paf 1: /** @file
1.18 paf 2: Parser: @b file parser type decl.
1.4 paf 3:
1.58 paf 4: Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.40 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
8: #ifndef PA_VFILE_H
9: #define PA_VFILE_H
1.43 paf 10:
1.61 ! misha 11: static const char * const IDENT_VFILE_H="$Date: 2007/02/26 13:41:27 $";
1.53 paf 12:
13: // include
1.1 paf 14:
15: #include "pa_common.h"
16: #include "pa_globals.h"
1.3 paf 17: #include "pa_vstateless_object.h"
1.53 paf 18: #include "pa_vbool.h"
19:
20: // defines
21:
22: #define NONAME_DAT "noname.dat"
1.60 misha 23: #define VFILE_TYPE "file"
1.23 paf 24:
1.53 paf 25: // forwards
26:
27: class Methoded;
1.1 paf 28:
1.22 paf 29: /** holds received from user or read from disk file.
1.1 paf 30:
1.4 paf 31: @see VForm
32: */
1.53 paf 33: class VFile: public VStateless_object {
34:
35: const char* ffile_name_cstr;
36: const char* fvalue_ptr;
37: size_t fvalue_size;
38: HashStringValue ffields;
39:
1.1 paf 40: public: // Value
41:
1.60 misha 42: override const char* type() const { return VFILE_TYPE; }
1.53 paf 43: override VStateless_class *get_class();
1.11 paf 44:
1.2 paf 45: /// VFile: true
1.53 paf 46: override bool as_bool() const { return true; }
1.35 parser 47:
48: /// VFile: true
1.54 paf 49: override Value& as_expr_result(bool /*return_string_as_is=false*/) { return *new VBool(as_bool()); }
1.2 paf 50:
1.16 paf 51: /// VFile: this
1.53 paf 52: override VFile* as_vfile(String::Language /*lang*/,
53: const Request_charsets* /*charsets*/) { return this; }
1.16 paf 54:
1.47 paf 55: /// VFile: method,field
1.53 paf 56: override Value* get_element(const String& aname, Value& aself, bool looking_up);
1.1 paf 57:
58: public: // usage
59:
1.59 misha 60: VFile(): fvalue_ptr(0), fvalue_size(0) {}
1.57 paf 61:
1.59 misha 62: VFile(HashStringValue& afields): ffields(afields) {}
1.1 paf 63:
1.53 paf 64: /// WARNING: when setting text files be sure to append terminating zero to avalue_ptr
65: void set(
66: bool tainted,
67: const char* avalue_ptr, size_t avalue_size,
68: const char* afile_name_cstr=0,
69: Value* acontent_type=0);
1.13 paf 70:
1.29 parser 71: void save(const String& file_spec, bool is_text) {
1.13 paf 72: if(fvalue_ptr)
1.38 paf 73: file_write(file_spec, fvalue_ptr, fvalue_size, is_text);
1.13 paf 74: else
1.61 ! misha 75: throw Exception(PARSER_RUNTIME,
1.13 paf 76: &file_spec,
1.18 paf 77: "saving stat-ed file");
1.1 paf 78: }
79:
1.53 paf 80: const char* value_ptr() const {
1.18 paf 81: if(!fvalue_ptr)
1.61 ! misha 82: throw Exception(PARSER_RUNTIME,
1.18 paf 83: 0,
84: "getting value of stat-ed file");
85:
86: return fvalue_ptr;
87: }
1.16 paf 88: size_t value_size() const { return fvalue_size; }
1.53 paf 89: HashStringValue& fields() { return ffields; }
1.16 paf 90:
1.1 paf 91: private:
92:
1.53 paf 93: Value* fields_element();
1.1 paf 94:
95: };
96:
97: #endif
E-mail: