Annotation of parser3/src/types/pa_vfile.h, revision 1.87
1.4 paf 1: /** @file
1.18 paf 2: Parser: @b file parser type decl.
1.4 paf 3:
1.87 ! moko 4: Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com)
! 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1 paf 6: */
7:
8: #ifndef PA_VFILE_H
9: #define PA_VFILE_H
1.43 paf 10:
1.87 ! moko 11: #define IDENT_PA_VFILE_H "$Id: pa_vfile.h,v 1.86 2021/10/19 16:16:36 moko Exp $"
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.69 misha 25: #define MODE_NAME "mode"
26: static const String mode_name(MODE_NAME);
1.64 misha 27:
1.53 paf 28: // forwards
29:
30: class Methoded;
1.1 paf 31:
1.22 paf 32: /** holds received from user or read from disk file.
1.1 paf 33:
1.4 paf 34: @see VForm
35: */
1.53 paf 36: class VFile: public VStateless_object {
37:
1.74 moko 38: const char* fvalue_ptr;
1.53 paf 39: size_t fvalue_size;
1.63 misha 40: bool ftext_tainted;
1.73 misha 41: bool fis_text_mode;
1.74 moko 42: bool fis_text_content;
1.53 paf 43: HashStringValue ffields;
44:
1.1 paf 45: public: // Value
46:
1.60 misha 47: override const char* type() const { return VFILE_TYPE; }
1.53 paf 48: override VStateless_class *get_class();
1.11 paf 49:
1.2 paf 50: /// VFile: true
1.53 paf 51: override bool as_bool() const { return true; }
1.35 parser 52:
53: /// VFile: true
1.71 moko 54: override Value& as_expr_result() { return VBool::get(true); }
1.2 paf 55:
1.16 paf 56: /// VFile: this
1.86 moko 57: override VFile* as_vfile() { return this; }
1.16 paf 58:
1.68 misha 59: /// VFile: json-string
1.72 moko 60: override const String* get_json_string(Json_options& options);
1.68 misha 61:
1.47 paf 62: /// VFile: method,field
1.65 misha 63: override Value* get_element(const String& aname);
1.1 paf 64:
1.82 moko 65: /// VFile: fields
1.83 moko 66: override HashStringValue *get_hash();
1.82 moko 67:
1.1 paf 68: public: // usage
69:
1.74 moko 70: VFile(): fvalue_ptr(0), fvalue_size(0), ftext_tainted(false), fis_text_mode(false), fis_text_content(false){}
1.57 paf 71:
1.74 moko 72: VFile(HashStringValue& afields): fvalue_ptr(0), fvalue_size(0), ftext_tainted(false), fis_text_mode(false), fis_text_content(false), ffields(afields) {}
1.1 paf 73:
1.53 paf 74: /// WARNING: when setting text files be sure to append terminating zero to avalue_ptr
1.73 misha 75: /// WARNING: the content can be modified while creating "text" vfile
1.74 moko 76: void set(bool atainted, bool ais_text_mode, char* avalue_ptr, size_t avalue_size, const String* afile_name=0, Value* acontent_type=0, Request* r=0);
1.81 moko 77: void set(VFile& avfile, bool *ais_text_mode, const String* afile_name=0, Value* acontent_type=0, Request* r=0);
1.74 moko 78: void set_binary(bool atainted, const char* avalue_ptr, size_t avalue_size, const String* afile_name=0, Value* acontent_type=0, Request* r=0);
1.76 moko 79: void set_binary_string(bool atainted, const char* avalue_ptr, size_t avalue_size);
1.64 misha 80:
1.66 misha 81: void save(Request_charsets& charsets, const String& file_spec, bool is_text, Charset* asked_charset=0);
1.1 paf 82:
1.69 misha 83: static bool is_text_mode(const String& mode);
84: static bool is_valid_mode (const String& mode);
85:
1.53 paf 86: const char* value_ptr() const {
1.18 paf 87: if(!fvalue_ptr)
1.74 moko 88: throw Exception(PARSER_RUNTIME, 0, "getting value of stat-ed file");
1.18 paf 89: return fvalue_ptr;
90: }
1.74 moko 91:
1.16 paf 92: size_t value_size() const { return fvalue_size; }
1.80 moko 93: bool is_text_mode() const { return fis_text_mode; }
1.74 moko 94:
1.53 paf 95: HashStringValue& fields() { return ffields; }
1.16 paf 96:
1.80 moko 97: Charset* detect_binary_charset(Charset* charset);
1.79 moko 98: void transcode(Charset& from_charset, Charset& to_charset);
99:
1.1 paf 100: private:
1.73 misha 101: const char* text_cstr();
1.74 moko 102:
1.77 moko 103: void set_all(bool atainted, bool ais_text_mode, const char* avalue_ptr, size_t avalue_size, const String* afile_name);
1.74 moko 104:
105: void set_mode(bool ais_text);
106:
107: void set_name(const String* afile_name);
108:
109: void set_content_type(Value* acontent_type, const String* afile_name=0, Request* r=0);
110:
1.1 paf 111: };
112:
113: #endif
E-mail: