Annotation of parser3/src/types/pa_vfile.h, revision 1.70

1.4       paf         1: /** @file
1.18      paf         2:        Parser: @b file parser type decl.
1.4       paf         3: 
1.70    ! moko        4:        Copyright (c) 2001-2012 Art. Lebedev Studio (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.70    ! moko       11: #define IDENT_PA_VFILE_H "$Id: 2011-11-23 12:17:23 $"
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: 
                     38:        const char* fvalue_ptr;
                     39:        size_t fvalue_size;
1.63      misha      40:        bool ftext_tainted;
1.53      paf        41:        HashStringValue ffields;
                     42: 
1.1       paf        43: public: // Value
                     44:        
1.60      misha      45:        override const char* type() const { return VFILE_TYPE; }
1.53      paf        46:        override VStateless_class *get_class();
1.11      paf        47: 
1.2       paf        48:        /// VFile: true
1.53      paf        49:        override bool as_bool() const { return true; }
1.35      parser     50: 
                     51:        /// VFile: true
1.62      misha      52:        override Value& as_expr_result(bool /*return_string_as_is=false*/) { return VBool::get(as_bool()); }
1.2       paf        53: 
1.16      paf        54:        /// VFile: this
1.53      paf        55:        override VFile* as_vfile(String::Language /*lang*/, 
                     56:                const Request_charsets* /*charsets*/) { return this; }
1.16      paf        57: 
1.68      misha      58:        /// VFile: json-string
                     59:        override const String* get_json_string(Json_options* options=0);
                     60: 
1.47      paf        61:        /// VFile: method,field
1.65      misha      62:        override Value* get_element(const String& aname);
1.1       paf        63: 
                     64: public: // usage
                     65: 
1.59      misha      66:        VFile(): fvalue_ptr(0), fvalue_size(0) {}
1.57      paf        67: 
1.59      misha      68:        VFile(HashStringValue& afields): ffields(afields) {}
1.1       paf        69: 
1.53      paf        70:        /// WARNING: when setting text files be sure to append terminating zero to avalue_ptr
                     71:        void set(
1.67      misha      72:                bool atainted,
                     73:                const char* avalue_ptr,
                     74:                size_t avalue_size,
1.69      misha      75:                const String* afile_name=0,
                     76:                Value* acontent_type=0,
                     77:                Request* r=0);
                     78: 
                     79:        void set(VFile& avfile);
                     80: 
                     81:        void set_mode(bool ais_text);
                     82: 
                     83:        void set_name(const String* afile_name);
                     84: 
                     85:        void set_content_type(Value* acontent_type, const String* afile_name=0, Request* r=0);
1.64      misha      86: 
1.66      misha      87:        void save(Request_charsets& charsets, const String& file_spec, bool is_text, Charset* asked_charset=0);
1.1       paf        88: 
1.69      misha      89:        static bool is_text_mode(const String& mode);
                     90:        static bool is_valid_mode (const String& mode);
                     91: 
1.53      paf        92:        const char* value_ptr() const { 
1.18      paf        93:                if(!fvalue_ptr)
1.61      misha      94:                        throw Exception(PARSER_RUNTIME,
1.18      paf        95:                                0,
                     96:                                "getting value of stat-ed file");
                     97: 
                     98:                return fvalue_ptr; 
                     99:        }
1.16      paf       100:        size_t value_size() const { return fvalue_size; }
1.53      paf       101:        HashStringValue& fields() { return ffields; }
1.16      paf       102: 
1.1       paf       103: private:
                    104: 
1.53      paf       105:        Value* fields_element();
1.1       paf       106: 
                    107: };
                    108: 
                    109: #endif

E-mail: