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

1.4       paf         1: /** @file
1.18      paf         2:        Parser: @b file parser type decl.
1.4       paf         3: 
1.39      paf         4:        Copyright (c) 2001, 2002 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.50    ! paf        11: static const char* IDENT_VFILE_H="$Date: 2002/10/31 12:22:14 $";
1.1       paf        12: 
1.25      paf        13: #include "classes.h"
1.1       paf        14: #include "pa_common.h"
                     15: #include "pa_globals.h"
1.3       paf        16: #include "pa_vstateless_object.h"
1.23      paf        17: 
                     18: extern Methoded *file_class;
1.1       paf        19: 
1.22      paf        20: /** holds received from user or read from disk file.
1.1       paf        21: 
1.4       paf        22:        @see VForm
                     23: */
1.3       paf        24: class VFile : public VStateless_object {
1.1       paf        25: public: // Value
                     26:        
                     27:        const char *type() const { return "file"; }
1.42      paf        28:        VStateless_class *get_class() { return file_class; }
1.11      paf        29: 
1.2       paf        30:        /// VFile: true
1.33      parser     31:        bool as_bool() const { return true; }
1.35      parser     32: 
                     33:        /// VFile: true
                     34:        Value *as_expr_result(bool return_string_as_is=false) { return NEW VBool(pool(), as_bool()); }
1.2       paf        35: 
1.16      paf        36:        /// VFile: this
1.27      parser     37:        VFile *as_vfile(String::Untaint_lang lang=String::UL_UNSPECIFIED,
                     38:                bool origins_mode=false) { 
1.19      paf        39:                return this; 
                     40:        }
1.16      paf        41: 
1.47      paf        42:        /// VFile: method,field
1.50    ! paf        43:        Value *get_element(const String& aname, Value& aself, bool looking_up) {
1.47      paf        44:                // $method
1.49      paf        45:                if(Value *result=VStateless_object::get_element(aname, aself, looking_up))
1.1       paf        46:                        return result;
                     47: 
1.12      paf        48:                // $name, $size, $text
1.16      paf        49:                return static_cast<Value *>(ffields.get(aname));
1.1       paf        50:        }
                     51: 
                     52: public: // usage
                     53: 
1.42      paf        54:        VFile::VFile(Pool& apool) : VStateless_object(apool),
1.13      paf        55:                fvalue_ptr(0),
                     56:                fvalue_size(0),
1.16      paf        57:                ffields(apool) {
1.13      paf        58:        }
1.1       paf        59: 
1.17      paf        60:        void set(bool tainted, 
                     61:                const void *avalue_ptr, size_t avalue_size, const char *afile_name=0,
1.45      paf        62:                Value *acontent_type=0);
1.13      paf        63:        
1.29      parser     64:        void save(const String& file_spec, bool is_text) {
1.13      paf        65:                if(fvalue_ptr)
1.38      paf        66:                        file_write(file_spec, fvalue_ptr, fvalue_size, is_text);
1.13      paf        67:                else
1.41      paf        68:                        throw Exception("parser.runtime",
1.13      paf        69:                                &file_spec,
1.18      paf        70:                                "saving stat-ed file");
1.1       paf        71:        }
                     72: 
1.18      paf        73:        const void *value_ptr() const { 
                     74:                if(!fvalue_ptr)
1.41      paf        75:                        throw Exception("parser.runtime",
1.18      paf        76:                                0,
                     77:                                "getting value of stat-ed file");
                     78: 
                     79:                return fvalue_ptr; 
                     80:        }
1.16      paf        81:        size_t value_size() const { return fvalue_size; }
1.21      paf        82:        Hash& fields() { return ffields; }
                     83:        const Hash& fields() const { return ffields; }
1.30      parser     84: 
                     85: private:
                     86: 
                     87:        Value *fields_element();
1.16      paf        88: 
1.1       paf        89: private:
                     90: 
1.12      paf        91:        const void *fvalue_ptr;
1.1       paf        92:        size_t fvalue_size;
1.16      paf        93:        Hash ffields;
1.1       paf        94: 
                     95: };
                     96: 
                     97: #endif

E-mail: