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

1.4       paf         1: /** @file
                      2:        Parser: file object decl.
                      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.13    ! paf         8:        $Id: pa_vfile.h,v 1.12 2001/03/28 09:38:09 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: 
                     35:        /// VFile: CLASS,BASE,method,field
1.1       paf        36:        Value *VFile::get_element(const String& aname) {
                     37:                // $CLASS,$BASE,$method
1.3       paf        38:                if(Value *result=VStateless_object::get_element(aname))
1.1       paf        39:                        return result;
                     40: 
1.12      paf        41:                // $name, $size, $text
1.1       paf        42:                return static_cast<Value *>(fields.get(aname));
                     43:        }
1.7       paf        44: 
                     45: protected: // VAliased
                     46: 
1.10      paf        47:        /// disable .CLASS element. @see VAliased::get_element
                     48:        bool are_static_calls_disabled() { return true; }
1.1       paf        49: 
                     50: public: // usage
                     51: 
1.13    ! paf        52:        VFile::VFile(Pool& apool) : VStateless_object(apool, *file_class),
        !            53:                fvalue_ptr(0),
        !            54:                fvalue_size(0),
        !            55:                fields(apool) {
        !            56:        }
1.1       paf        57: 
1.13    ! paf        58:        void set(const void *avalue_ptr, size_t avalue_size, const char *afile_name);
        !            59:        
1.6       paf        60:        void save(const String& file_spec) {
1.13    ! paf        61:                if(fvalue_ptr)
        !            62:                        file_write(pool(), file_spec, fvalue_ptr, fvalue_size, false);
        !            63:                else
        !            64:                        THROW(0, 0,
        !            65:                                &file_spec,
        !            66:                                "saving unassigned file"); //never
1.1       paf        67:        }
                     68: 
                     69: private:
                     70: 
1.12      paf        71:        const void *fvalue_ptr;
1.1       paf        72:        size_t fvalue_size;
                     73:        Hash fields;
                     74: 
                     75: };
                     76: 
                     77: #endif

E-mail: