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

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"
                      9: 
1.6     ! paf        10: static const char* IDENT_VOBJECT_C="$Date: 2002/08/14 14:18:30 $";
1.5       paf        11: 
1.6     ! paf        12: Value *VObject::as(const char *atype, bool looking_up) { 
1.5       paf        13:        if(!looking_up)
1.6     ! paf        14:                return get_last_derived()->as(atype, true/*the only user*/); // figure out from last_derivate upwards
1.5       paf        15: 
                     16:        // is it me?
1.6     ! paf        17:        if(Value *result=Value::as(atype, false))
        !            18:                return result;
1.5       paf        19: 
                     20:        // is it my base?
                     21:        if(fbase) {
1.6     ! paf        22:                if(Value *result=fbase->as(atype, true))
        !            23:                        return result;
1.5       paf        24:        }
                     25: 
                     26:        // neither
1.6     ! paf        27:        return 0;
1.5       paf        28: }
1.1       paf        29: 
                     30: /// VObject: true, todo: z base table can be 33
                     31: Value *VObject::as_expr_result(bool) { return NEW VBool(pool(), as_bool()); }
                     32: /// VObject: true, todo: z base table can be false     
                     33: bool VObject::as_bool() const { return true; }
                     34: 
                     35: /// VObject: (field)=value;(CLASS)=vclass;(method)=method_ref
1.5       paf        36: Value *VObject::get_element(const String& aname, Value * /*aself*/, bool looking_up) {
1.1       paf        37:        // gets element from last_derivate upwards
1.5       paf        38:        if(!looking_up) {
1.1       paf        39:                // $CLASS
                     40:                if(aname==CLASS_NAME)
                     41:                        return get_class();
                     42: 
                     43:                // for first call, pass call to last derived VObject
1.3       paf        44:                return get_last_derived()->get_element(aname, 
                     45:                        0, true/*the only user*/);
1.1       paf        46:        }
                     47: 
                     48:        // $method, $CLASS_field
                     49:        {
                     50:                Temp_base temp_base(*get_class(), 0);
1.3       paf        51:                if(Value *result=VStateless_object::get_element(aname, this, true))
1.1       paf        52:                        return result;
                     53:        }
                     54: 
                     55:        // $field=ffields.field
                     56:        if(Value *result=static_cast<Value *>(ffields.get(aname)))
                     57:                return result;
                     58: 
                     59:        // up the tree...
                     60:        if(fbase)
1.3       paf        61:                if(Value *result=fbase->get_element(aname, fbase, true))
1.1       paf        62:                        return result;
                     63: 
                     64:        return 0;
                     65: }
                     66: 
                     67: /// VObject: (field)=value
                     68: bool VObject::put_element(const String& aname, Value *avalue, bool replace) {
                     69:        // replaces element to last_derivate upwards or stores it in self
                     70:        // speed1:
                     71:        //   will not check for '$CLASS(subst)' trick
                     72:        //   will hope that user ain't THAT self-hating person
                     73:        // speed2:
                     74:        //   will not check for '$method_name(subst)' trick
                     75:        //   -same-
                     76: 
1.2       paf        77:        if(!replace) { 
                     78:                // for first call, pass call to last derived VObject
                     79:                if(get_last_derived()->put_element(aname, avalue, true))
                     80:                        return true;
1.1       paf        81: 
1.2       paf        82:                ffields.put(aname, avalue);
                     83:                return false;
                     84:        }
1.1       paf        85: 
1.2       paf        86:        // replace
1.1       paf        87:        // upwards: copied from VClass::put_element...
                     88: 
                     89:        try {
                     90:                if(fbase && fbase->put_element(aname, avalue, true))
                     91:                        return true; // replaced in base
1.2       paf        92: 
                     93:                return ffields.put_replace(aname, avalue);
1.4       paf        94:        } catch(Exception) { /* allow override parent variables, useful for form descendants */ }
1.1       paf        95: 
1.2       paf        96:        // could not put to any base of last child
                     97:        return false;
1.1       paf        98: }
                     99: 

E-mail: