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

1.1       paf         1: /**    @file
                      2:        Parser: @b object class impl.
                      3: 
1.16    ! paf         4:        Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
1.1       paf         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.16    ! paf        12: static const char * const IDENT_VOBJECT_C="$Date: 2003/11/20 16:34:30 $";
1.5       paf        13: 
1.13      paf        14: Value* VObject::as(const char* atype, bool looking_up) { 
1.5       paf        15:        if(!looking_up)
1.10      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
1.13      paf        37: Value& VObject::as_expr_result(bool) { 
1.7       paf        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
1.13      paf        53: VFile* VObject::as_vfile(String::Language lang, const Request_charsets *charsets) {
                     54:        return fbase?fbase->as_vfile(lang, charsets):
                     55:                Value::as_vfile(lang, charsets);
1.7       paf        56: }
                     57: 
                     58: /// VObject: from possible parent, if any
1.13      paf        59: HashStringValue* VObject::get_hash() {
                     60:        if(Value* vhash=get_last_derived().as(VHASH_TYPE, false))
                     61:                return vhash->get_hash();
1.7       paf        62: 
                     63:        return 0;
                     64: }
                     65: /// VObject: from possible 'table' parent
                     66: Table *VObject::get_table() {
1.10      paf        67:        if(Value *vtable=get_last_derived().as(VTABLE_TYPE, false))
1.7       paf        68:                return vtable->get_table();
                     69: 
                     70:        return 0;
                     71: }
1.1       paf        72: 
                     73: /// VObject: (field)=value;(CLASS)=vclass;(method)=method_ref
1.14      paf        74: Value* VObject::get_element(const String& aname, Value&, bool looking_up) {
1.8       paf        75:        // simple things first: $field=ffields.field
1.13      paf        76:        if(Value* result=ffields.get(aname))
1.8       paf        77:                return result;
                     78: 
1.1       paf        79:        // gets element from last_derivate upwards
1.5       paf        80:        if(!looking_up) {
1.1       paf        81:                // $CLASS
                     82:                if(aname==CLASS_NAME)
                     83:                        return get_class();
                     84: 
1.10      paf        85:                // $virtual_method
                     86:                VObject& last_derived=get_last_derived();
1.13      paf        87:                if(Value* result=last_derived.stateless_object__get_element(aname, last_derived))
1.1       paf        88:                        return result;
                     89:        }
                     90: 
1.10      paf        91:        // up the tree for other $virtual_field try...
1.1       paf        92:        if(fbase)
1.13      paf        93:                if(Value* result=fbase->get_element(aname, *fbase, true))
1.1       paf        94:                        return result;
                     95: 
                     96:        return 0;
                     97: }
1.13      paf        98: Value* VObject::stateless_object__get_element(const String& aname, Value& aself) {
1.10      paf        99:        return VStateless_object::get_element(aname, aself, false);
                    100: }
1.1       paf       101: 
                    102: /// VObject: (field)=value
1.13      paf       103: bool VObject::put_element(const String& aname, Value* avalue, bool replace) {
1.11      paf       104:        if(fbase && fbase->put_element(aname, avalue, true))
                    105:                return true; // replaced in base dynamic fields
1.1       paf       106: 
1.10      paf       107:        if(replace)
                    108:                return ffields.put_replace(aname, avalue);
                    109:        else {
1.11      paf       110:                if(VStateless_object::put_element(aname, avalue, true))
                    111:                        return true; // replaced in base statics fields
                    112: 
1.2       paf       113:                ffields.put(aname, avalue);
                    114:                return false;
                    115:        }
1.1       paf       116: }
                    117: 

E-mail: