Annotation of parser3/src/types/pa_vobject.C, revision 1.30
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.30 ! misha 15: static const char * const IDENT_VOBJECT_C="$Date: 2009-08-08 13:30:21 $";
1.26 misha 16:
1.30 ! misha 17: Value* VObject::get_scalar_value(char* as_something) const {
1.26 misha 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.30 ! misha 23:
! 24: Value *param;
! 25:
! 26: if(size_t param_count=frame.method_params_count()){
! 27: if(param_count==1){
! 28: param=new VString(*new String(as_something));
! 29: frame.store_params(¶m, 1);
! 30: } else
! 31: throw Exception(PARSER_RUNTIME,
! 32: 0,
! 33: "scalar getter method can't have more then 1 parameter (has %d parameters)", param_count);
! 34: } // no need for else frame.empty_params()
! 35:
1.29 misha 36: frame.set_self(*unconst_this);
1.26 misha 37: return &pa_thread_request().execute_method(frame, *method).as_value();
38: }
39: return 0;
40: }
1.5 paf 41:
1.29 misha 42: Value* VObject::as(const char* atype) {
43: return fclass.as(atype) ? this:0;
1.5 paf 44: }
1.1 paf 45:
1.7 paf 46: bool VObject::is_defined() const {
1.30 ! misha 47: if(Value* value=get_scalar_value("def"))
1.26 misha 48: return value->is_defined();
1.29 misha 49: return Value::is_defined();
1.7 paf 50: }
1.29 misha 51:
1.26 misha 52: Value& VObject::as_expr_result(bool) {
1.30 ! misha 53: if(Value* value=get_scalar_value("expression"))
1.26 misha 54: return value->as_expr_result();
1.29 misha 55: return Value::as_expr_result();
1.7 paf 56: }
1.29 misha 57:
1.7 paf 58: int VObject::as_int() const {
1.30 ! misha 59: if(Value* value=get_scalar_value("int"))
1.26 misha 60: return value->as_int();
1.29 misha 61: return Value::as_int();
1.7 paf 62: }
1.29 misha 63:
1.26 misha 64: double VObject::as_double() const {
1.30 ! misha 65: if(Value* value=get_scalar_value("double"))
1.26 misha 66: return value->as_double();
1.29 misha 67: return Value::as_double();
1.7 paf 68: }
1.29 misha 69:
1.7 paf 70: bool VObject::as_bool() const {
1.30 ! misha 71: if(Value* value=get_scalar_value("bool"))
1.26 misha 72: return value->as_bool();
1.29 misha 73: return Value::as_bool();
1.7 paf 74: }
1.29 misha 75:
1.13 paf 76: VFile* VObject::as_vfile(String::Language lang, const Request_charsets *charsets) {
1.30 ! misha 77: if(Value* value=get_scalar_value("file"))
1.26 misha 78: return value->as_vfile(lang, charsets);
1.29 misha 79: return Value::as_vfile(lang, charsets);
1.7 paf 80: }
81:
1.13 paf 82: HashStringValue* VObject::get_hash() {
1.30 ! misha 83: if(Value* value=get_scalar_value("hash"))
1.29 misha 84: return value->get_hash();
85: return &ffields;
86: }
1.7 paf 87:
88: Table *VObject::get_table() {
1.30 ! misha 89: if(Value* value=get_scalar_value("table"))
1.29 misha 90: return value->get_table();
91: return Value::get_table();
1.7 paf 92: }
1.1 paf 93:
1.29 misha 94: Value* VObject::get_element(const String& aname) {
1.8 paf 95: // simple things first: $field=ffields.field
1.13 paf 96: if(Value* result=ffields.get(aname))
1.8 paf 97: return result;
98:
1.29 misha 99: // class $virtual_method $virtual_property
100: if(Value* result=fclass.get_element(*this, aname))
101: return result;
1.1 paf 102:
1.29 misha 103: if(Value* result=fclass.get_default_getter(*this, aname))
104: return result;
1.1 paf 105:
106: return 0;
107: }
1.19 paf 108:
109: /// VObject: (field/property)=value
1.29 misha 110: const VJunction* VObject::put_element(const String& aname, Value* avalue, bool /*areplace*/){
111: if(const VJunction* result=fclass.put_element(*this, aname, avalue, true /*try to replace! NEVER overwrite*/))
112: return result; // replaced in statics fields/properties
113: ffields.put(aname,avalue);
114: return 0;
1.1 paf 115: }
E-mail: