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

1.4       paf         1: /** @file
1.18      paf         2:        Parser: @b file parser type decl.
1.4       paf         3: 
1.78      moko        4:        Copyright (c) 2001-2015 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.83    ! moko       11: #define IDENT_PA_VFILE_H "$Id: pa_vfile.h,v 1.82 2016/08/04 22:12:50 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.53      paf        57:        override VFile* as_vfile(String::Language /*lang*/, 
                     58:                const Request_charsets* /*charsets*/) { return this; }
1.16      paf        59: 
1.68      misha      60:        /// VFile: json-string
1.72      moko       61:        override const String* get_json_string(Json_options& options);
1.68      misha      62: 
1.47      paf        63:        /// VFile: method,field
1.65      misha      64:        override Value* get_element(const String& aname);
1.1       paf        65: 
1.82      moko       66:        /// VFile: fields
1.83    ! moko       67:        override HashStringValue *get_hash();
1.82      moko       68: 
1.1       paf        69: public: // usage
                     70: 
1.74      moko       71:        VFile(): fvalue_ptr(0), fvalue_size(0), ftext_tainted(false), fis_text_mode(false), fis_text_content(false){}
1.57      paf        72: 
1.74      moko       73:        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        74: 
1.53      paf        75:        /// WARNING: when setting text files be sure to append terminating zero to avalue_ptr
1.73      misha      76:        /// WARNING: the content can be modified while creating "text" vfile
1.74      moko       77:        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       78:        void set(VFile& avfile, bool *ais_text_mode, const String* afile_name=0, Value* acontent_type=0, Request* r=0);
1.74      moko       79:        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       80:        void set_binary_string(bool atainted, const char* avalue_ptr, size_t avalue_size);
1.64      misha      81: 
1.66      misha      82:        void save(Request_charsets& charsets, const String& file_spec, bool is_text, Charset* asked_charset=0);
1.1       paf        83: 
1.69      misha      84:        static bool is_text_mode(const String& mode);
                     85:        static bool is_valid_mode (const String& mode);
                     86: 
1.53      paf        87:        const char* value_ptr() const { 
1.18      paf        88:                if(!fvalue_ptr)
1.74      moko       89:                        throw Exception(PARSER_RUNTIME, 0, "getting value of stat-ed file");
1.18      paf        90:                return fvalue_ptr; 
                     91:        }
1.74      moko       92: 
1.16      paf        93:        size_t value_size() const { return fvalue_size; }
1.80      moko       94:        bool is_text_mode() const { return fis_text_mode; }
1.74      moko       95: 
1.53      paf        96:        HashStringValue& fields() { return ffields; }
1.16      paf        97: 
1.80      moko       98:        Charset* detect_binary_charset(Charset* charset);
1.79      moko       99:        void transcode(Charset& from_charset, Charset& to_charset);
                    100: 
1.1       paf       101: private:
1.73      misha     102:        const char* text_cstr();
1.74      moko      103: 
1.77      moko      104:        void set_all(bool atainted, bool ais_text_mode, const char* avalue_ptr, size_t avalue_size, const String* afile_name);
1.74      moko      105: 
                    106:        void set_mode(bool ais_text);
                    107: 
                    108:        void set_name(const String* afile_name);
                    109: 
                    110:        void set_content_type(Value* acontent_type, const String* afile_name=0, Request* r=0);
                    111: 
1.1       paf       112: };
                    113: 
                    114: #endif

E-mail: