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

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: 
        !            10: static const char* IDENT_VOBJECT_C="$Date: 2002/08/13 14:52:17 $";
        !            11: 
        !            12: /// VObject: true, todo: z base table can be 33
        !            13: Value *VObject::as_expr_result(bool) { return NEW VBool(pool(), as_bool()); }
        !            14: /// VObject: true, todo: z base table can be false     
        !            15: bool VObject::as_bool() const { return true; }
        !            16: 
        !            17: /// VObject: (field)=value;(CLASS)=vclass;(method)=method_ref
        !            18: Value *VObject::get_element(const String& aname, Value *aself) {
        !            19:        // gets element from last_derivate upwards
        !            20:        if(aself) {
        !            21:                // $CLASS
        !            22:                if(aname==CLASS_NAME)
        !            23:                        return get_class();
        !            24: 
        !            25:                // for first call, pass call to last derived VObject
        !            26:                return get_last_derived()->get_element(aname, 0/*mark this call as 'not first'*/);
        !            27:        }
        !            28: 
        !            29:        // $method, $CLASS_field
        !            30:        {
        !            31:                Temp_base temp_base(*get_class(), 0);
        !            32:                if(Value *result=VStateless_object::get_element(aname, this))
        !            33:                        return result;
        !            34:        }
        !            35: 
        !            36:        // $field=ffields.field
        !            37:        if(Value *result=static_cast<Value *>(ffields.get(aname)))
        !            38:                return result;
        !            39: 
        !            40:        // up the tree...
        !            41:        if(fbase)
        !            42:                if(Value *result=fbase->get_element(aname, fbase))
        !            43:                        return result;
        !            44: 
        !            45:        return 0;
        !            46: }
        !            47: 
        !            48: /// VObject: (field)=value
        !            49: bool VObject::put_element(const String& aname, Value *avalue, bool replace) {
        !            50:        // replaces element to last_derivate upwards or stores it in self
        !            51:        // speed1:
        !            52:        //   will not check for '$CLASS(subst)' trick
        !            53:        //   will hope that user ain't THAT self-hating person
        !            54:        // speed2:
        !            55:        //   will not check for '$method_name(subst)' trick
        !            56:        //   -same-
        !            57: 
        !            58:        // downwards: same as upwards
        !            59: 
        !            60:        if(fderived && fderived->put_element(aname, avalue, true))
        !            61:                return true; // replaced in derived
        !            62: 
        !            63:        // upwards: copied from VClass::put_element...
        !            64: 
        !            65:        try {
        !            66:                if(fbase && fbase->put_element(aname, avalue, true))
        !            67:                        return true; // replaced in base
        !            68:        } catch(Exception) { 
        !            69:                /* ignore "can not store to table&co errors for nonexistent elements */ 
        !            70:                bool error;
        !            71:                try {
        !            72:                        error=get_element(aname, this)!=0;
        !            73:                } catch(Exception) { 
        !            74:                        error=false;
        !            75:                }
        !            76:                if(error)
        !            77:                        /*re*/throw;
        !            78:        }
        !            79: 
        !            80:        if(replace)
        !            81:                return ffields.put_replace(aname, avalue);
        !            82:        else {
        !            83:                ffields.put(aname, avalue);
        !            84:                return false;
        !            85:        }
        !            86: }
        !            87: 

E-mail: