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

1.1       paf         1: /**    @file
                      2:        Parser: @b object class impl.
                      3: 
1.28      misha       4:        Copyright (c) 2001-2009 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.26      misha      12: #include "pa_vmethod_frame.h"
                     13: #include "pa_request.h"
1.1       paf        14: 
1.29    ! misha      15: static const char * const IDENT_VOBJECT_C="$Date: 2009-05-14 11:27:23 $";
1.26      misha      16: 
                     17: Value* VObject::get_scalar_value() const {
                     18:        VObject* unconst_this=const_cast<VObject*>(this);
1.29    ! misha      19:        if(Value* scalar=fclass.get_scalar(*unconst_this))
1.26      misha      20:                if(Junction* junction=scalar->get_junction())
                     21:                        if(const Method *method=junction->method){
                     22:                                VMethodFrame frame(*junction, 0/*no caller*/);
1.29    ! misha      23:                                frame.set_self(*unconst_this);
1.26      misha      24:                                return &pa_thread_request().execute_method(frame, *method).as_value();
                     25:                        }
                     26:        return 0;
                     27: }
1.5       paf        28: 
1.29    ! misha      29: Value* VObject::as(const char* atype) {
        !            30:        return fclass.as(atype) ? this:0;
1.5       paf        31: }
1.1       paf        32: 
1.7       paf        33: bool VObject::is_defined() const {
1.26      misha      34:        if(Value* value=get_scalar_value())
                     35:                return value->is_defined();
1.29    ! misha      36:        return Value::is_defined();
1.7       paf        37: }
1.29    ! misha      38: 
1.26      misha      39: Value& VObject::as_expr_result(bool) {
                     40:        if(Value* value=get_scalar_value())
                     41:                return value->as_expr_result();
1.29    ! misha      42:        return Value::as_expr_result();
1.7       paf        43: }
1.29    ! misha      44: 
1.7       paf        45: int VObject::as_int() const {
1.26      misha      46:        if(Value* value=get_scalar_value())
                     47:                return value->as_int();
1.29    ! misha      48:        return Value::as_int();
1.7       paf        49: }
1.29    ! misha      50: 
1.26      misha      51: double VObject::as_double() const {
                     52:        if(Value* value=get_scalar_value())
                     53:                return value->as_double();
1.29    ! misha      54:        return Value::as_double();
1.7       paf        55: }
1.29    ! misha      56: 
1.7       paf        57: bool VObject::as_bool() const { 
1.26      misha      58:        if(Value* value=get_scalar_value())
                     59:                return value->as_bool();
1.29    ! misha      60:        return Value::as_bool();
1.7       paf        61: }
1.29    ! misha      62: 
1.13      paf        63: VFile* VObject::as_vfile(String::Language lang, const Request_charsets *charsets) {
1.26      misha      64:        if(Value* value=get_scalar_value())
                     65:                return value->as_vfile(lang, charsets);
1.29    ! misha      66:        return Value::as_vfile(lang, charsets);
1.7       paf        67: }
                     68: 
1.13      paf        69: HashStringValue* VObject::get_hash() {
1.29    ! misha      70:        if(Value* value=get_scalar_value())
        !            71:                return value->get_hash();
        !            72:        return &ffields;
        !            73: }
1.7       paf        74: 
                     75: Table *VObject::get_table() {
1.29    ! misha      76:        if(Value* value=get_scalar_value())
        !            77:                return value->get_table();
        !            78:        return Value::get_table();
1.7       paf        79: }
1.1       paf        80: 
1.29    ! misha      81: Value* VObject::get_element(const String& aname) {
1.8       paf        82:        // simple things first: $field=ffields.field
1.13      paf        83:        if(Value* result=ffields.get(aname))
1.8       paf        84:                return result;
                     85: 
1.29    ! misha      86:        // class $virtual_method $virtual_property
        !            87:        if(Value* result=fclass.get_element(*this, aname))
        !            88:                return result;
1.1       paf        89: 
1.29    ! misha      90:        if(Value* result=fclass.get_default_getter(*this, aname))
        !            91:                return result;
1.1       paf        92: 
                     93:        return 0;
                     94: }
1.19      paf        95: 
                     96: /// VObject: (field/property)=value
1.29    ! misha      97: const VJunction* VObject::put_element(const String& aname, Value* avalue, bool /*areplace*/){
        !            98:        if(const VJunction* result=fclass.put_element(*this, aname, avalue, true /*try to replace! NEVER overwrite*/))
        !            99:                return result; // replaced in statics fields/properties
        !           100:        ffields.put(aname,avalue);
        !           101:        return 0;
1.1       paf       102: }

E-mail: