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

1.4       paf         1: /** @file
1.18      paf         2:        Parser: @b file parser type decl.
1.4       paf         3: 
1.1       paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.4       paf         5: 
1.1       paf         6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
                      7: 
1.20    ! paf         8:        $Id: pa_vfile.h,v 1.19 2001/04/11 08:13:43 paf Exp $
1.1       paf         9: */
                     10: 
                     11: #ifndef PA_VFILE_H
                     12: #define PA_VFILE_H
                     13: 
                     14: #include "pa_common.h"
                     15: #include "pa_globals.h"
1.3       paf        16: #include "pa_vstateless_object.h"
1.1       paf        17: #include "_file.h"
                     18: 
1.4       paf        19: /** holds received file.
1.1       paf        20: 
1.4       paf        21:        @see VForm
                     22: */
1.3       paf        23: class VFile : public VStateless_object {
1.1       paf        24: public: // Value
                     25:        
1.2       paf        26:        /// all: for error reporting after fail(), etc
1.1       paf        27:        const char *type() const { return "file"; }
                     28: 
1.2       paf        29:        /// VFile: this
1.11      paf        30:        Value *as_expr_result(bool return_string_as_is=false) { return this; }
                     31: 
1.2       paf        32:        /// VFile: true
1.11      paf        33:        bool as_bool() { return true; }
1.2       paf        34: 
1.16      paf        35:        /// VFile: this
1.19      paf        36:        const VFile *as_vfile(String::Untaint_lang lang=String::UL_UNSPECIFIED) const { 
                     37:                return this; 
                     38:        }
1.16      paf        39: 
1.2       paf        40:        /// VFile: CLASS,BASE,method,field
1.1       paf        41:        Value *VFile::get_element(const String& aname) {
                     42:                // $CLASS,$BASE,$method
1.3       paf        43:                if(Value *result=VStateless_object::get_element(aname))
1.1       paf        44:                        return result;
                     45: 
1.12      paf        46:                // $name, $size, $text
1.16      paf        47:                return static_cast<Value *>(ffields.get(aname));
1.1       paf        48:        }
1.7       paf        49: 
                     50: protected: // VAliased
                     51: 
1.10      paf        52:        /// disable .CLASS element. @see VAliased::get_element
1.15      paf        53:        bool hide_class() { return true; }
1.1       paf        54: 
                     55: public: // usage
                     56: 
1.13      paf        57:        VFile::VFile(Pool& apool) : VStateless_object(apool, *file_class),
                     58:                fvalue_ptr(0),
                     59:                fvalue_size(0),
1.16      paf        60:                ffields(apool) {
1.13      paf        61:        }
1.1       paf        62: 
1.17      paf        63:        void set(bool tainted, 
                     64:                const void *avalue_ptr, size_t avalue_size, const char *afile_name=0,
1.14      paf        65:                const String *amime_type=0);
1.13      paf        66:        
1.6       paf        67:        void save(const String& file_spec) {
1.13      paf        68:                if(fvalue_ptr)
                     69:                        file_write(pool(), file_spec, fvalue_ptr, fvalue_size, false);
                     70:                else
                     71:                        THROW(0, 0,
                     72:                                &file_spec,
1.18      paf        73:                                "saving stat-ed file");
1.1       paf        74:        }
                     75: 
1.18      paf        76:        const void *value_ptr() const { 
                     77:                if(!fvalue_ptr)
                     78:                        THROW(0, 0,
                     79:                                0,
                     80:                                "getting value of stat-ed file");
                     81: 
                     82:                return fvalue_ptr; 
                     83:        }
1.16      paf        84:        size_t value_size() const { return fvalue_size; }
1.20    ! paf        85:        Hash& fields() const { return ffields; }
1.16      paf        86: 
1.1       paf        87: private:
                     88: 
1.12      paf        89:        const void *fvalue_ptr;
1.1       paf        90:        size_t fvalue_size;
1.16      paf        91:        Hash ffields;
1.1       paf        92: 
                     93: };
                     94: 
                     95: #endif

E-mail: