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

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.73    ! misha      11: #define IDENT_PA_VFILE_H "$Id: pa_vfile.h,v 1.72 2012-05-28 19:47:52 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.73    ! misha      38:        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;
        !            42:        bool feols_normalized;
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: 
                     66: public: // usage
                     67: 
1.59      misha      68:        VFile(): fvalue_ptr(0), fvalue_size(0) {}
1.57      paf        69: 
1.59      misha      70:        VFile(HashStringValue& afields): ffields(afields) {}
1.1       paf        71: 
1.53      paf        72:        /// WARNING: when setting text files be sure to append terminating zero to avalue_ptr
1.73    ! misha      73:        /// WARNING: the content can be modified while creating "text" vfile
1.53      paf        74:        void set(
1.67      misha      75:                bool atainted,
1.73    ! misha      76:                bool ais_text_mode,
        !            77:                char* avalue_ptr,
1.67      misha      78:                size_t avalue_size,
1.69      misha      79:                const String* afile_name=0,
                     80:                Value* acontent_type=0,
                     81:                Request* r=0);
                     82: 
                     83:        void set(VFile& avfile);
                     84: 
1.73    ! misha      85:        void set_name(const String* afile_name);
        !            86: 
1.69      misha      87:        void set_mode(bool ais_text);
                     88: 
                     89:        void set_content_type(Value* acontent_type, const String* afile_name=0, Request* r=0);
1.64      misha      90: 
1.66      misha      91:        void save(Request_charsets& charsets, const String& file_spec, bool is_text, Charset* asked_charset=0);
1.1       paf        92: 
1.69      misha      93:        static bool is_text_mode(const String& mode);
                     94:        static bool is_valid_mode (const String& mode);
                     95: 
1.73    ! misha      96:        void fix_line_breaks_set();
        !            97: 
1.53      paf        98:        const char* value_ptr() const { 
1.18      paf        99:                if(!fvalue_ptr)
1.61      misha     100:                        throw Exception(PARSER_RUNTIME,
1.18      paf       101:                                0,
                    102:                                "getting value of stat-ed file");
                    103: 
                    104:                return fvalue_ptr; 
                    105:        }
1.16      paf       106:        size_t value_size() const { return fvalue_size; }
1.53      paf       107:        HashStringValue& fields() { return ffields; }
1.16      paf       108: 
1.1       paf       109: private:
1.73    ! misha     110:        const char* text_cstr();
1.1       paf       111: };
                    112: 
                    113: #endif

E-mail: