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

1.1       paf         1: /**    @file
                      2:        Parser: @b object class impl.
                      3: 
1.24      paf         4:        Copyright (c) 2001-2005 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.25    ! misha      11: #include "pa_vstring.h"
1.1       paf        12: 
1.25    ! misha      13: static const char * const IDENT_VOBJECT_C="$Date: 2005/08/09 08:14:55 $";
1.5       paf        14: 
1.13      paf        15: Value* VObject::as(const char* atype, bool looking_up) { 
1.5       paf        16:        if(!looking_up)
1.10      paf        17:                return get_last_derived().as(atype, true/*the only user*/); // figure out from last_derivate upwards
1.5       paf        18: 
                     19:        // is it me?
1.6       paf        20:        if(Value *result=Value::as(atype, false))
                     21:                return result;
1.5       paf        22: 
                     23:        // is it my base?
                     24:        if(fbase) {
1.6       paf        25:                if(Value *result=fbase->as(atype, true))
                     26:                        return result;
1.5       paf        27:        }
                     28: 
                     29:        // neither
1.6       paf        30:        return 0;
1.5       paf        31: }
1.1       paf        32: 
1.7       paf        33: /// VObject: from possible parent, if any
                     34: bool VObject::is_defined() const {
                     35:        return fbase?fbase->is_defined():Value::is_defined();
                     36: }
                     37: /// VObject: from possible parent, if any
1.13      paf        38: Value& VObject::as_expr_result(bool) { 
1.7       paf        39:        return fbase?fbase->as_expr_result():Value::as_expr_result();
                     40: }
                     41: /// VObject: from possible parent, if any
                     42: int VObject::as_int() const {
                     43:        return fbase?fbase->as_int():Value::as_int();
                     44: }
                     45: /// VObject: from possible parent, if any
                     46: double VObject::as_double() {
                     47:        return fbase?fbase->as_double():Value::as_double();
                     48: }
                     49: /// VObject: from possible parent, if any
                     50: bool VObject::as_bool() const { 
                     51:        return fbase?fbase->as_bool():Value::as_bool();
                     52: }
                     53: /// VObject: from possible parent, if any
1.13      paf        54: VFile* VObject::as_vfile(String::Language lang, const Request_charsets *charsets) {
                     55:        return fbase?fbase->as_vfile(lang, charsets):
                     56:                Value::as_vfile(lang, charsets);
1.7       paf        57: }
                     58: 
                     59: /// VObject: from possible parent, if any
1.13      paf        60: HashStringValue* VObject::get_hash() {
                     61:        if(Value* vhash=get_last_derived().as(VHASH_TYPE, false))
                     62:                return vhash->get_hash();
1.7       paf        63: 
                     64:        return 0;
                     65: }
                     66: /// VObject: from possible 'table' parent
                     67: Table *VObject::get_table() {
1.10      paf        68:        if(Value *vtable=get_last_derived().as(VTABLE_TYPE, false))
1.7       paf        69:                return vtable->get_table();
                     70: 
                     71:        return 0;
                     72: }
1.1       paf        73: 
                     74: /// VObject: (field)=value;(CLASS)=vclass;(method)=method_ref
1.25    ! misha      75: Value* VObject::get_element(const String& aname, Value&, bool alooking_up) {
1.8       paf        76:        // simple things first: $field=ffields.field
1.13      paf        77:        if(Value* result=ffields.get(aname))
1.8       paf        78:                return result;
                     79: 
1.1       paf        80:        // gets element from last_derivate upwards
1.25    ! misha      81:        if(alooking_up) {
1.1       paf        82:                // $CLASS
                     83:                if(aname==CLASS_NAME)
                     84:                        return get_class();
1.25    ! misha      85:                // $CLASS_NAME
        !            86:                if(aname==CLASS_NAMETEXT)
        !            87:                        return new VString(get_class()->name());
1.22      paf        88:                // $virtual_method $virtual_property
1.10      paf        89:                VObject& last_derived=get_last_derived();
1.13      paf        90:                if(Value* result=last_derived.stateless_object__get_element(aname, last_derived))
1.1       paf        91:                        return result;
1.25    ! misha      92: 
        !            93:                if(Value* result=last_derived.get_default_getter(last_derived, aname))
        !            94:                        return result;
1.1       paf        95:        }
                     96: 
1.21      paf        97:        return 0;
                     98: }
                     99: 
1.23      paf       100: const VJunction* VObject::prevent_append_if_exists_in_static_or_base(Value* value, Prevent_append_if_exists_in_static_or_base_info* info)  {
1.21      paf       101:        // $virtual_property, any this/bases $static_property 
                    102:        VObject& last_derived=info->_this->get_last_derived();
1.23      paf       103:        if(const VJunction* result=last_derived.stateless_object__put_element(last_derived, *info->name, value))
1.21      paf       104:                return result; // replaced in any(derivate or base) statics fields/properties
1.1       paf       105: 
                    106:        return 0;
                    107: }
1.19      paf       108: 
                    109: /// VObject: (field/property)=value
1.25    ! misha     110: const VJunction* VObject::put_element(Value& /*aself*/, const String& aname, Value* avalue, bool /*areplace*/){
1.21      paf       111:        Prevent_append_if_exists_in_static_or_base_info info={this, &aname};
1.23      paf       112:        return ffields.replace_maybe_append<const VJunction*>(aname, avalue, 
1.21      paf       113:                prevent_append_if_exists_in_static_or_base, 
                    114:                &info);
1.1       paf       115: }

E-mail: