Annotation of parser3/src/types/pa_vobject.C, revision 1.31
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.31 ! moko 15: static const char * const IDENT_VOBJECT_C="$Date: 2009-09-17 23:31:42 $";
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){
1.31 ! moko 22: VMethodFrame frame(*method, 0 /*no caller*/, *unconst_this);
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.26 misha 36: return &pa_thread_request().execute_method(frame, *method).as_value();
37: }
38: return 0;
39: }
1.5 paf 40:
1.29 misha 41: Value* VObject::as(const char* atype) {
42: return fclass.as(atype) ? this:0;
1.5 paf 43: }
1.1 paf 44:
1.7 paf 45: bool VObject::is_defined() const {
1.30 misha 46: if(Value* value=get_scalar_value("def"))
1.26 misha 47: return value->is_defined();
1.29 misha 48: return Value::is_defined();
1.7 paf 49: }
1.29 misha 50:
1.26 misha 51: Value& VObject::as_expr_result(bool) {
1.30 misha 52: if(Value* value=get_scalar_value("expression"))
1.26 misha 53: return value->as_expr_result();
1.29 misha 54: return Value::as_expr_result();
1.7 paf 55: }
1.29 misha 56:
1.7 paf 57: int VObject::as_int() const {
1.30 misha 58: if(Value* value=get_scalar_value("int"))
1.26 misha 59: return value->as_int();
1.29 misha 60: return Value::as_int();
1.7 paf 61: }
1.29 misha 62:
1.26 misha 63: double VObject::as_double() const {
1.30 misha 64: if(Value* value=get_scalar_value("double"))
1.26 misha 65: return value->as_double();
1.29 misha 66: return Value::as_double();
1.7 paf 67: }
1.29 misha 68:
1.7 paf 69: bool VObject::as_bool() const {
1.30 misha 70: if(Value* value=get_scalar_value("bool"))
1.26 misha 71: return value->as_bool();
1.29 misha 72: return Value::as_bool();
1.7 paf 73: }
1.29 misha 74:
1.13 paf 75: VFile* VObject::as_vfile(String::Language lang, const Request_charsets *charsets) {
1.30 misha 76: if(Value* value=get_scalar_value("file"))
1.26 misha 77: return value->as_vfile(lang, charsets);
1.29 misha 78: return Value::as_vfile(lang, charsets);
1.7 paf 79: }
80:
1.13 paf 81: HashStringValue* VObject::get_hash() {
1.30 misha 82: if(Value* value=get_scalar_value("hash"))
1.29 misha 83: return value->get_hash();
84: return &ffields;
85: }
1.7 paf 86:
87: Table *VObject::get_table() {
1.30 misha 88: if(Value* value=get_scalar_value("table"))
1.29 misha 89: return value->get_table();
90: return Value::get_table();
1.7 paf 91: }
1.1 paf 92:
1.29 misha 93: Value* VObject::get_element(const String& aname) {
1.8 paf 94: // simple things first: $field=ffields.field
1.13 paf 95: if(Value* result=ffields.get(aname))
1.8 paf 96: return result;
97:
1.29 misha 98: // class $virtual_method $virtual_property
99: if(Value* result=fclass.get_element(*this, aname))
100: return result;
1.1 paf 101:
1.29 misha 102: if(Value* result=fclass.get_default_getter(*this, aname))
103: return result;
1.1 paf 104:
105: return 0;
106: }
1.19 paf 107:
108: /// VObject: (field/property)=value
1.29 misha 109: const VJunction* VObject::put_element(const String& aname, Value* avalue, bool /*areplace*/){
110: if(const VJunction* result=fclass.put_element(*this, aname, avalue, true /*try to replace! NEVER overwrite*/))
111: return result; // replaced in statics fields/properties
112: ffields.put(aname,avalue);
113: return 0;
1.1 paf 114: }
E-mail: