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

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.33    ! parser      8:        $Id: pa_vfile.h,v 1.32 2001/09/17 14:46:49 parser Exp $
1.1       paf         9: */
                     10: 
                     11: #ifndef PA_VFILE_H
                     12: #define PA_VFILE_H
                     13: 
1.25      paf        14: #include "classes.h"
1.1       paf        15: #include "pa_common.h"
                     16: #include "pa_globals.h"
1.3       paf        17: #include "pa_vstateless_object.h"
1.23      paf        18: 
                     19: extern Methoded *file_class;
1.1       paf        20: 
1.22      paf        21: /** holds received from user or read from disk file.
1.1       paf        22: 
1.4       paf        23:        @see VForm
                     24: */
1.3       paf        25: class VFile : public VStateless_object {
1.1       paf        26: public: // Value
                     27:        
                     28:        const char *type() const { return "file"; }
1.11      paf        29: 
1.2       paf        30:        /// VFile: true
1.33    ! parser     31:        bool as_bool() const { return true; }
1.2       paf        32: 
1.16      paf        33:        /// VFile: this
1.27      parser     34:        VFile *as_vfile(String::Untaint_lang lang=String::UL_UNSPECIFIED,
                     35:                bool origins_mode=false) { 
1.19      paf        36:                return this; 
                     37:        }
1.16      paf        38: 
1.28      parser     39:        /// VFile: CLASS,method,field
1.1       paf        40:        Value *VFile::get_element(const String& aname) {
1.28      parser     41:                // $CLASS,$method
1.3       paf        42:                if(Value *result=VStateless_object::get_element(aname))
1.1       paf        43:                        return result;
                     44: 
1.12      paf        45:                // $name, $size, $text
1.16      paf        46:                return static_cast<Value *>(ffields.get(aname));
1.1       paf        47:        }
1.7       paf        48: 
                     49: protected: // VAliased
                     50: 
1.10      paf        51:        /// disable .CLASS element. @see VAliased::get_element
1.15      paf        52:        bool hide_class() { return true; }
1.1       paf        53: 
                     54: public: // usage
                     55: 
1.13      paf        56:        VFile::VFile(Pool& apool) : VStateless_object(apool, *file_class),
                     57:                fvalue_ptr(0),
                     58:                fvalue_size(0),
1.16      paf        59:                ffields(apool) {
1.13      paf        60:        }
1.1       paf        61: 
1.17      paf        62:        void set(bool tainted, 
                     63:                const void *avalue_ptr, size_t avalue_size, const char *afile_name=0,
1.31      parser     64:                Value *amime_type=0);
1.13      paf        65:        
1.29      parser     66:        void save(const String& file_spec, bool is_text) {
1.13      paf        67:                if(fvalue_ptr)
1.29      parser     68:                        file_write(pool(), file_spec, fvalue_ptr, fvalue_size, is_text);
1.13      paf        69:                else
                     70:                        THROW(0, 0,
                     71:                                &file_spec,
1.18      paf        72:                                "saving stat-ed file");
1.1       paf        73:        }
                     74: 
1.18      paf        75:        const void *value_ptr() const { 
                     76:                if(!fvalue_ptr)
                     77:                        THROW(0, 0,
                     78:                                0,
                     79:                                "getting value of stat-ed file");
                     80: 
                     81:                return fvalue_ptr; 
                     82:        }
1.16      paf        83:        size_t value_size() const { return fvalue_size; }
1.21      paf        84:        Hash& fields() { return ffields; }
                     85:        const Hash& fields() const { return ffields; }
1.30      parser     86: 
                     87: private:
                     88: 
                     89:        Value *fields_element();
1.16      paf        90: 
1.1       paf        91: private:
                     92: 
1.12      paf        93:        const void *fvalue_ptr;
1.1       paf        94:        size_t fvalue_size;
1.16      paf        95:        Hash ffields;
1.1       paf        96: 
                     97: };
                     98: 
                     99: #endif

E-mail: