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

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.33    ! paf        11: static const char* IDENT_VCLASS_H="$Date: 2002/08/12 14:21:52 $";
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.33    ! paf        38:        /// VClass: (field)=STATIC value;(method)=method_ref with self=object_class
        !            39:        Value *get_element(const String& aname, Value *aself) {
        !            40:                // $method or other base element
        !            41:                if(Value *result=VStateless_class::get_element(aname, aself))
        !            42:                        return result;
        !            43: 
1.16      paf        44:                // $field=static field
1.33    ! paf        45:                if(Value *result=static_cast<Value *>(ffields.get(aname)))
1.8       paf        46:                        return result;
1.33    ! paf        47: 
        !            48:                return 0;
1.8       paf        49:        }
1.1       paf        50: 
1.33    ! paf        51:        /// VClass: (field)=value - static values only
        !            52:        /*override*/ bool put_element(const String& aname, Value *avalue, bool replace) {
        !            53:                try {
        !            54:                        if(fbase && fbase->put_element(aname, avalue, true))
        !            55:                                return true; // replaced in base
        !            56:                } catch(Exception) { /* ignore "can not store to stateless_class errors */ }
        !            57: 
        !            58:                if(replace)
        !            59:                        return ffields.put_replace(aname, avalue);
        !            60:                else {
        !            61:                        ffields.put(aname, avalue);
        !            62:                        return false;
        !            63:                }
1.22      paf        64:        }
                     65: 
                     66:        /// @returns object of this class
1.31      paf        67:        /*override*/ Value *create_new_value(Pool& ) { 
1.22      paf        68:                return NEW VObject(pool(), *this);
1.11      paf        69:        }
1.1       paf        70: 
                     71: public: // usage
                     72: 
1.8       paf        73:        VClass(Pool& apool) : VStateless_class(apool), 
                     74:                ffields(apool) {
1.1       paf        75:        }
                     76: 
1.12      paf        77: private:
                     78: 
1.1       paf        79:        void set_field(const String& name, Value *value) {
                     80:                if(fbase && fbase->replace_field(name, value))
                     81:                        return;
                     82: 
                     83:                ffields.put(name, value);
                     84:        }
                     85: 
                     86:        Value *get_field(const String& name) {
                     87:                Value *result=static_cast<Value *>(ffields.get(name));
                     88:                if(!result && fbase)
                     89:                        result=fbase->get_field(name);
                     90:                return result;
                     91:        }
1.8       paf        92: 
                     93: protected:
1.1       paf        94:                
                     95:        bool replace_field(const String& name, Value *value) {
                     96:                return 
                     97:                        (fbase && fbase->replace_field(name, value)) ||
                     98:                        ffields.put_replace(name, value);
                     99:        }
1.4       paf       100: 
1.25      paf       101: private: // self
1.1       paf       102: 
                    103:        Hash ffields;
1.25      paf       104: 
1.1       paf       105: };
                    106: 
                    107: #endif

E-mail: