Annotation of parser3/src/types/pa_vclass.h, revision 1.32

1.13      paf         1: /**    @file
1.14      paf         2:        Parser: @b class parser class decl.
1.13      paf         3: 
1.23      paf         4:        Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.24      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_VCLASS_H
                      9: #define PA_VCLASS_H
1.26      paf        10: 
1.32    ! paf        11: static const char* IDENT_VCLASS_H="$Date: 2002/08/12 11:22:55 $";
1.1       paf        12: 
1.8       paf        13: #include "pa_vstateless_class.h"
1.18      parser     14: //#include "pa_vhash.h"
1.1       paf        15: #include "pa_vjunction.h"
1.22      paf        16: #include "pa_vobject.h"
1.1       paf        17: 
1.13      paf        18: /**    stores 
1.25      paf        19: - static fields: VClass::ffields
1.13      paf        20: */
1.8       paf        21: class VClass : public VStateless_class {
1.1       paf        22: public: // Value
                     23:        
1.28      paf        24:        const char *type() const { return name_cstr(); }
1.29      paf        25: 
                     26:        Value *as(const char *atype) {
                     27:                if(Value *result=Value::as(atype))
                     28:                        return result;
                     29:                else
                     30:                        return fbase?fbase->as(atype):0;
                     31:        }
1.20      parser     32: 
                     33:        /// VClass: true
                     34:        Value *as_expr_result(bool) { return NEW VBool(pool(), as_bool()); }
                     35:        /// VClass: true
                     36:        bool as_bool() const { return true; }
1.9       paf        37: 
1.16      paf        38:        // VClass: (field)=STATIC value;(method)=method_ref with self=object_class
1.8       paf        39:        Value *get_element(const String& aname) {
1.16      paf        40:                // $field=static field
                     41:                if(Value *result=get_field(aname))
1.8       paf        42:                        return result;
1.16      paf        43:                
1.31      paf        44:                // $method
1.16      paf        45:                return VStateless_class::get_element(aname);
1.8       paf        46:        }
1.1       paf        47: 
1.16      paf        48:        // VClass: (field)=value - static values only
1.11      paf        49:        void put_element(const String& name, Value *value) {
                     50:                set_field(name, value);
1.22      paf        51:        }
                     52: 
                     53:        /// @returns object of this class
1.31      paf        54:        /*override*/ Value *create_new_value(Pool& ) { 
1.22      paf        55:                return NEW VObject(pool(), *this);
1.11      paf        56:        }
1.1       paf        57: 
                     58: public: // usage
                     59: 
1.8       paf        60:        VClass(Pool& apool) : VStateless_class(apool), 
                     61:                ffields(apool) {
1.1       paf        62:        }
                     63: 
1.12      paf        64: private:
                     65: 
1.1       paf        66:        void set_field(const String& name, Value *value) {
                     67:                if(fbase && fbase->replace_field(name, value))
                     68:                        return;
                     69: 
                     70:                ffields.put(name, value);
                     71:        }
                     72: 
                     73:        Value *get_field(const String& name) {
                     74:                Value *result=static_cast<Value *>(ffields.get(name));
                     75:                if(!result && fbase)
                     76:                        result=fbase->get_field(name);
                     77:                return result;
                     78:        }
1.8       paf        79: 
                     80: protected:
1.1       paf        81:                
                     82:        bool replace_field(const String& name, Value *value) {
                     83:                return 
                     84:                        (fbase && fbase->replace_field(name, value)) ||
                     85:                        ffields.put_replace(name, value);
                     86:        }
1.4       paf        87: 
1.25      paf        88: private: // self
1.1       paf        89: 
                     90:        Hash ffields;
1.25      paf        91: 
1.1       paf        92: };
                     93: 
                     94: #endif

E-mail: