Annotation of parser3/src/types/pa_vfile.h, revision 1.68
1.4 paf 1: /** @file
1.18 paf 2: Parser: @b file parser type decl.
1.4 paf 3:
1.62 misha 4: Copyright (c) 2001-2009 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.68 ! misha 11: static const char * const IDENT_VFILE_H="$Date: 2010-01-26 07:21:29 $";
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.64 misha 25: #define TEXT_MODE_NAME "text"
26: #define BINARY_MODE_NAME "binary"
27:
28: static const String text_mode_name(TEXT_MODE_NAME);
29: static const String binary_mode_name(BINARY_MODE_NAME);
30:
1.53 paf 31: // forwards
32:
33: class Methoded;
1.1 paf 34:
1.22 paf 35: /** holds received from user or read from disk file.
1.1 paf 36:
1.4 paf 37: @see VForm
38: */
1.53 paf 39: class VFile: public VStateless_object {
40:
41: const char* ffile_name_cstr;
42: const char* fvalue_ptr;
43: size_t fvalue_size;
1.63 misha 44: bool ftext_tainted;
1.53 paf 45: HashStringValue ffields;
46:
1.1 paf 47: public: // Value
48:
1.60 misha 49: override const char* type() const { return VFILE_TYPE; }
1.53 paf 50: override VStateless_class *get_class();
1.11 paf 51:
1.2 paf 52: /// VFile: true
1.53 paf 53: override bool as_bool() const { return true; }
1.35 parser 54:
55: /// VFile: true
1.62 misha 56: override Value& as_expr_result(bool /*return_string_as_is=false*/) { return VBool::get(as_bool()); }
1.2 paf 57:
1.16 paf 58: /// VFile: this
1.53 paf 59: override VFile* as_vfile(String::Language /*lang*/,
60: const Request_charsets* /*charsets*/) { return this; }
1.16 paf 61:
1.68 ! misha 62: /// VFile: json-string
! 63: override const String* get_json_string(Json_options* options=0);
! 64:
1.47 paf 65: /// VFile: method,field
1.65 misha 66: override Value* get_element(const String& aname);
1.1 paf 67:
68: public: // usage
69:
1.59 misha 70: VFile(): fvalue_ptr(0), fvalue_size(0) {}
1.57 paf 71:
1.59 misha 72: VFile(HashStringValue& afields): ffields(afields) {}
1.1 paf 73:
1.53 paf 74: /// WARNING: when setting text files be sure to append terminating zero to avalue_ptr
75: void set(
1.67 misha 76: bool atainted,
77: const char* avalue_ptr,
78: size_t avalue_size,
1.53 paf 79: const char* afile_name_cstr=0,
80: Value* acontent_type=0);
1.64 misha 81:
1.67 misha 82: void set_mode(bool aas_text);
1.13 paf 83:
1.66 misha 84: void save(Request_charsets& charsets, const String& file_spec, bool is_text, Charset* asked_charset=0);
1.1 paf 85:
1.53 paf 86: const char* value_ptr() const {
1.18 paf 87: if(!fvalue_ptr)
1.61 misha 88: throw Exception(PARSER_RUNTIME,
1.18 paf 89: 0,
90: "getting value of stat-ed file");
91:
92: return fvalue_ptr;
93: }
1.16 paf 94: size_t value_size() const { return fvalue_size; }
1.53 paf 95: HashStringValue& fields() { return ffields; }
1.16 paf 96:
1.1 paf 97: private:
98:
1.53 paf 99: Value* fields_element();
1.1 paf 100:
101: };
102:
103: #endif
E-mail: