Annotation of parser3/src/types/pa_vobject.C, revision 1.12.2.6
1.1 paf 1: /** @file
2: Parser: @b object class impl.
3:
1.12.2.4 paf 4: Copyright (c) 2001-2003 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.12.2.6! paf 12: static const char* IDENT_VOBJECT_C="$Date: 2003/02/03 11:46:48 $";
1.5 paf 13:
1.12.2.5 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.12.2.5 paf 37: ValuePtr 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.12.2.5 paf 53: VFilePtr VObject::as_vfile(Pool& pool, String::Untaint_lang lang, bool origins_mode) {
54: return fbase?fbase->as_vfile(pool, lang, origins_mode):
55: Value::as_vfile(pool, lang, origins_mode);
1.7 paf 56: }
57:
58: /// VObject: from possible parent, if any
1.12.2.3 paf 59: HashStringValue* VObject::get_hash(StringPtr source) {
1.12.2.5 paf 60: if(Value* vhash=get_last_derived().as(VHASH_TYPE, false))
1.7 paf 61: return vhash->get_hash(source);
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.12.2.5 paf 74: ValuePtr VObject::get_element(StringPtr aname, Value& aself, bool looking_up) {
1.8 paf 75: // simple things first: $field=ffields.field
1.12.2.5 paf 76: if(ValuePtr 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
1.12.2.5 paf 82: if(*aname==CLASS_NAME)
1.12.2.6! paf 83: return ValuePtr(get_class());
1.1 paf 84:
1.10 paf 85: // $virtual_method
86: VObject& last_derived=get_last_derived();
1.12.2.5 paf 87: if(ValuePtr 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.12.2.5 paf 93: if(ValuePtr result=fbase->get_element(aname, *fbase, true))
1.1 paf 94: return result;
95:
1.12.2.6! paf 96: return ValuePtr(0);
1.1 paf 97: }
1.12.2.5 paf 98: ValuePtr VObject::stateless_object__get_element(StringPtr 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.12.2.5 paf 103: bool VObject::put_element(StringPtr aname, ValuePtr 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: