Annotation of parser3/src/types/pa_vobject.C, revision 1.7

1.1       paf         1: /**    @file
                      2:        Parser: @b object class impl.
                      3: 
                      4:        Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
                      5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
                      6: */
                      7: 
                      8: #include "pa_vobject.h"
1.7     ! paf         9: #include "pa_vhash.h"
        !            10: #include "pa_vtable.h"
1.1       paf        11: 
1.7     ! paf        12: static const char* IDENT_VOBJECT_C="$Date: 2002/08/15 07:53:07 $";
1.5       paf        13: 
1.6       paf        14: Value *VObject::as(const char *atype, bool looking_up) { 
1.5       paf        15:        if(!looking_up)
1.6       paf        16:                return get_last_derived()->as(atype, true/*the only user*/); // figure out from last_derivate upwards
1.5       paf        17: 
                     18:        // is it me?
1.6       paf        19:        if(Value *result=Value::as(atype, false))
                     20:                return result;
1.5       paf        21: 
                     22:        // is it my base?
                     23:        if(fbase) {
1.6       paf        24:                if(Value *result=fbase->as(atype, true))
                     25:                        return result;
1.5       paf        26:        }
                     27: 
                     28:        // neither
1.6       paf        29:        return 0;
1.5       paf        30: }
1.1       paf        31: 
1.7     ! paf        32: /// VObject: from possible parent, if any
        !            33: bool VObject::is_defined() const {
        !            34:        return fbase?fbase->is_defined():Value::is_defined();
        !            35: }
        !            36: /// VObject: from possible parent, if any
        !            37: Value *VObject::as_expr_result(bool) { 
        !            38:        return fbase?fbase->as_expr_result():Value::as_expr_result();
        !            39: }
        !            40: /// VObject: from possible parent, if any
        !            41: int VObject::as_int() const {
        !            42:        return fbase?fbase->as_int():Value::as_int();
        !            43: }
        !            44: /// VObject: from possible parent, if any
        !            45: double VObject::as_double() {
        !            46:        return fbase?fbase->as_double():Value::as_double();
        !            47: }
        !            48: /// VObject: from possible parent, if any
        !            49: bool VObject::as_bool() const { 
        !            50:        return fbase?fbase->as_bool():Value::as_bool();
        !            51: }
        !            52: /// VObject: from possible parent, if any
        !            53: VFile *VObject::as_vfile(String::Untaint_lang lang, bool origins_mode) {
        !            54:        return fbase?fbase->as_vfile(lang, origins_mode):Value::as_vfile(lang, origins_mode);
        !            55: }
        !            56: 
        !            57: /// VObject: from possible parent, if any
        !            58: Hash *VObject::get_hash(const String *source) {
        !            59:        if(Value *vhash=get_last_derived()->as(VHASH_TYPE, false))
        !            60:                return vhash->get_hash(source);
        !            61: 
        !            62:        return 0;
        !            63: }
        !            64: /// VObject: from possible 'table' parent
        !            65: Table *VObject::get_table() {
        !            66:        if(Value *vtable=get_last_derived()->as(VTABLE_TYPE, false))
        !            67:                return vtable->get_table();
        !            68: 
        !            69:        return 0;
        !            70: }
1.1       paf        71: 
                     72: /// VObject: (field)=value;(CLASS)=vclass;(method)=method_ref
1.5       paf        73: Value *VObject::get_element(const String& aname, Value * /*aself*/, bool looking_up) {
1.1       paf        74:        // gets element from last_derivate upwards
1.5       paf        75:        if(!looking_up) {
1.1       paf        76:                // $CLASS
                     77:                if(aname==CLASS_NAME)
                     78:                        return get_class();
                     79: 
                     80:                // for first call, pass call to last derived VObject
1.3       paf        81:                return get_last_derived()->get_element(aname, 
                     82:                        0, true/*the only user*/);
1.1       paf        83:        }
                     84: 
                     85:        // $method, $CLASS_field
                     86:        {
                     87:                Temp_base temp_base(*get_class(), 0);
1.3       paf        88:                if(Value *result=VStateless_object::get_element(aname, this, true))
1.1       paf        89:                        return result;
                     90:        }
                     91: 
                     92:        // $field=ffields.field
                     93:        if(Value *result=static_cast<Value *>(ffields.get(aname)))
                     94:                return result;
                     95: 
                     96:        // up the tree...
                     97:        if(fbase)
1.3       paf        98:                if(Value *result=fbase->get_element(aname, fbase, true))
1.1       paf        99:                        return result;
                    100: 
                    101:        return 0;
                    102: }
                    103: 
                    104: /// VObject: (field)=value
                    105: bool VObject::put_element(const String& aname, Value *avalue, bool replace) {
                    106:        // replaces element to last_derivate upwards or stores it in self
                    107:        // speed1:
                    108:        //   will not check for '$CLASS(subst)' trick
                    109:        //   will hope that user ain't THAT self-hating person
                    110:        // speed2:
                    111:        //   will not check for '$method_name(subst)' trick
                    112:        //   -same-
                    113: 
1.2       paf       114:        if(!replace) { 
                    115:                // for first call, pass call to last derived VObject
                    116:                if(get_last_derived()->put_element(aname, avalue, true))
                    117:                        return true;
1.1       paf       118: 
1.2       paf       119:                ffields.put(aname, avalue);
                    120:                return false;
                    121:        }
1.1       paf       122: 
1.2       paf       123:        // replace
1.1       paf       124:        // upwards: copied from VClass::put_element...
                    125: 
                    126:        try {
                    127:                if(fbase && fbase->put_element(aname, avalue, true))
                    128:                        return true; // replaced in base
1.2       paf       129: 
                    130:                return ffields.put_replace(aname, avalue);
1.4       paf       131:        } catch(Exception) { /* allow override parent variables, useful for form descendants */ }
1.1       paf       132: 
1.2       paf       133:        // could not put to any base of last child
                    134:        return false;
1.1       paf       135: }
                    136: 

E-mail: