Annotation of parser3/src/types/pa_vobject.C, revision 1.12.2.7.2.4
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.7.2.4! paf 12: static const char* IDENT_VOBJECT_C="$Date: 2003/03/21 13:42:34 $";
1.12.2.7 paf 13:
14: VObject::~VObject() {
15: }
1.5 paf 16:
1.12.2.5 paf 17: Value* VObject::as(const char* atype, bool looking_up) {
1.5 paf 18: if(!looking_up)
1.10 paf 19: return get_last_derived().as(atype, true/*the only user*/); // figure out from last_derivate upwards
1.5 paf 20:
21: // is it me?
1.6 paf 22: if(Value *result=Value::as(atype, false))
23: return result;
1.5 paf 24:
25: // is it my base?
26: if(fbase) {
1.6 paf 27: if(Value *result=fbase->as(atype, true))
28: return result;
1.5 paf 29: }
30:
31: // neither
1.6 paf 32: return 0;
1.5 paf 33: }
1.1 paf 34:
1.7 paf 35: /// VObject: from possible parent, if any
36: bool VObject::is_defined() const {
37: return fbase?fbase->is_defined():Value::is_defined();
38: }
39: /// VObject: from possible parent, if any
1.12.2.7.2.3 paf 40: Value* VObject::as_expr_result(bool) {
1.7 paf 41: return fbase?fbase->as_expr_result():Value::as_expr_result();
42: }
43: /// VObject: from possible parent, if any
44: int VObject::as_int() const {
45: return fbase?fbase->as_int():Value::as_int();
46: }
47: /// VObject: from possible parent, if any
48: double VObject::as_double() {
49: return fbase?fbase->as_double():Value::as_double();
50: }
51: /// VObject: from possible parent, if any
52: bool VObject::as_bool() const {
53: return fbase?fbase->as_bool():Value::as_bool();
54: }
55: /// VObject: from possible parent, if any
1.12.2.7.2.3 paf 56: VFile* VObject::as_vfile(String::Language lang) {
57: return fbase?fbase->as_vfile(lang):
1.12.2.7.2.2 paf 58: Value::as_vfile(lang, origins_mode);
1.7 paf 59: }
60:
61: /// VObject: from possible parent, if any
1.12.2.7.2.4! paf 62: HashStringValue* VObject::get_hash() {
1.12.2.5 paf 63: if(Value* vhash=get_last_derived().as(VHASH_TYPE, false))
1.12.2.7.2.4! paf 64: return vhash->get_hash();
1.7 paf 65:
66: return 0;
67: }
68: /// VObject: from possible 'table' parent
69: Table *VObject::get_table() {
1.10 paf 70: if(Value *vtable=get_last_derived().as(VTABLE_TYPE, false))
1.7 paf 71: return vtable->get_table();
72:
73: return 0;
74: }
1.1 paf 75:
76: /// VObject: (field)=value;(CLASS)=vclass;(method)=method_ref
1.12.2.7.2.3 paf 77: Value* VObject::get_element(const String& aname, Value& aself, bool looking_up) {
1.8 paf 78: // simple things first: $field=ffields.field
1.12.2.7.2.3 paf 79: if(Value* result=ffields.get(aname))
1.8 paf 80: return result;
81:
1.1 paf 82: // gets element from last_derivate upwards
1.5 paf 83: if(!looking_up) {
1.1 paf 84: // $CLASS
1.12.2.7.2.3 paf 85: if(aname==CLASS_NAME)
86: return Value*(get_class());
1.1 paf 87:
1.10 paf 88: // $virtual_method
89: VObject& last_derived=get_last_derived();
1.12.2.7.2.3 paf 90: if(Value* result=last_derived.stateless_object__get_element(aname, last_derived))
1.1 paf 91: return result;
92: }
93:
1.10 paf 94: // up the tree for other $virtual_field try...
1.1 paf 95: if(fbase)
1.12.2.7.2.3 paf 96: if(Value* result=fbase->get_element(aname, *fbase, true))
1.1 paf 97: return result;
98:
1.12.2.7.2.3 paf 99: return 0;
1.1 paf 100: }
1.12.2.7.2.3 paf 101: Value* VObject::stateless_object__get_element(const String& aname, Value& aself) {
1.10 paf 102: return VStateless_object::get_element(aname, aself, false);
103: }
1.1 paf 104:
105: /// VObject: (field)=value
1.12.2.7.2.3 paf 106: bool VObject::put_element(const String& aname, Value* avalue, bool replace) {
1.11 paf 107: if(fbase && fbase->put_element(aname, avalue, true))
108: return true; // replaced in base dynamic fields
1.1 paf 109:
1.10 paf 110: if(replace)
111: return ffields.put_replace(aname, avalue);
112: else {
1.11 paf 113: if(VStateless_object::put_element(aname, avalue, true))
114: return true; // replaced in base statics fields
115:
1.2 paf 116: ffields.put(aname, avalue);
117: return false;
118: }
1.1 paf 119: }
120:
E-mail: