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

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.9.4.2 ! paf        12: static const char* IDENT_VOBJECT_C="$Date: 2002/10/31 12:22:14 $";
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.9.4.1   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) {
1.9.4.1   paf        59:        if(Value *vhash=get_last_derived().as(VHASH_TYPE, false))
1.7       paf        60:                return vhash->get_hash(source);
                     61: 
                     62:        return 0;
                     63: }
                     64: /// VObject: from possible 'table' parent
                     65: Table *VObject::get_table() {
1.9.4.1   paf        66:        if(Value *vtable=get_last_derived().as(VTABLE_TYPE, false))
1.7       paf        67:                return vtable->get_table();
                     68: 
                     69:        return 0;
                     70: }
1.1       paf        71: 
                     72: /// VObject: (field)=value;(CLASS)=vclass;(method)=method_ref
1.9.4.1   paf        73: Value *VObject::get_element(const String& aname, Value& aself, bool looking_up) {
1.8       paf        74:        // simple things first: $field=ffields.field
                     75:        if(Value *result=static_cast<Value *>(ffields.get(aname)))
                     76:                return result;
                     77: 
1.9.4.1   paf        78:        // $method [virtual down,up lookup]
1.5       paf        79:        if(!looking_up) {
1.9.4.1   paf        80:                if(Value *result=VStateless_object::get_element(aname, aself, false))
1.1       paf        81:                        return result;
                     82:        }
                     83: 
                     84:        // up the tree...
1.9.4.2 ! paf        85:        if(fbase) {
        !            86:                if(!aself.base())
        !            87:                        throw Exception("paf.debug",
        !            88:                                &aname,
        !            89:                                "no aself.base() here in vobject");
1.9.4.1   paf        90:                if(Value *result=fbase->get_element(aname, * /*must have base too*/aself.base(), true))
1.1       paf        91:                        return result;
1.9.4.2 ! paf        92:        }
1.1       paf        93: 
                     94:        return 0;
                     95: }
                     96: 
                     97: /// VObject: (field)=value
                     98: bool VObject::put_element(const String& aname, Value *avalue, bool replace) {
                     99:        // replaces element to last_derivate upwards or stores it in self
                    100:        // speed1:
                    101:        //   will not check for '$CLASS(subst)' trick
                    102:        //   will hope that user ain't THAT self-hating person
                    103:        // speed2:
                    104:        //   will not check for '$method_name(subst)' trick
                    105:        //   -same-
                    106: 
1.2       paf       107:        if(!replace) { 
                    108:                // for first call, pass call to last derived VObject
1.9.4.1   paf       109:                if(get_last_derived().put_element(aname, avalue, true))
1.2       paf       110:                        return true;
1.1       paf       111: 
1.2       paf       112:                ffields.put(aname, avalue);
                    113:                return false;
                    114:        }
1.1       paf       115: 
1.2       paf       116:        // replace
1.1       paf       117:        // upwards: copied from VClass::put_element...
                    118: 
                    119:        try {
                    120:                if(fbase && fbase->put_element(aname, avalue, true))
                    121:                        return true; // replaced in base
1.2       paf       122: 
                    123:                return ffields.put_replace(aname, avalue);
1.4       paf       124:        } catch(Exception) { /* allow override parent variables, useful for form descendants */ }
1.1       paf       125: 
1.2       paf       126:        // could not put to any base of last child
                    127:        return false;
1.1       paf       128: }
                    129: 

E-mail: