Annotation of parser3/src/types/pa_vobject.C, revision 1.9.4.1
1.1 paf 1: /** @file
2: Parser: @b object class impl.
3:
4: Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
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.9.4.1 ! paf 12: static const char* IDENT_VOBJECT_C="$Date: 2002/10/14 11:28:45 $";
1.5 paf 13:
1.6 paf 14: Value *VObject::as(const char *atype, bool looking_up) {
1.5 paf 15: if(!looking_up)
1.9.4.1 ! 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
37: Value *VObject::as_expr_result(bool) {
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
53: VFile *VObject::as_vfile(String::Untaint_lang lang, bool origins_mode) {
54: return fbase?fbase->as_vfile(lang, origins_mode):Value::as_vfile(lang, origins_mode);
55: }
56:
57: /// VObject: from possible parent, if any
58: Hash *VObject::get_hash(const String *source) {
1.9.4.1 ! paf 59: if(Value *vhash=get_last_derived().as(VHASH_TYPE, false))
1.7 paf 60: return vhash->get_hash(source);
61:
62: return 0;
63: }
64: /// VObject: from possible 'table' parent
65: Table *VObject::get_table() {
1.9.4.1 ! paf 66: if(Value *vtable=get_last_derived().as(VTABLE_TYPE, false))
1.7 paf 67: return vtable->get_table();
68:
69: return 0;
70: }
1.1 paf 71:
72: /// VObject: (field)=value;(CLASS)=vclass;(method)=method_ref
1.9.4.1 ! paf 73: Value *VObject::get_element(const String& aname, Value& aself, bool looking_up) {
1.8 paf 74: // simple things first: $field=ffields.field
75: if(Value *result=static_cast<Value *>(ffields.get(aname)))
76: return result;
77:
1.9.4.1 ! paf 78: // $method [virtual down,up lookup]
1.5 paf 79: if(!looking_up) {
1.9.4.1 ! paf 80: if(Value *result=VStateless_object::get_element(aname, aself, false))
1.1 paf 81: return result;
82: }
83:
84: // up the tree...
85: if(fbase)
1.9.4.1 ! paf 86: if(Value *result=fbase->get_element(aname, * /*must have base too*/aself.base(), true))
1.1 paf 87: return result;
88:
89: return 0;
90: }
91:
92: /// VObject: (field)=value
93: bool VObject::put_element(const String& aname, Value *avalue, bool replace) {
94: // replaces element to last_derivate upwards or stores it in self
95: // speed1:
96: // will not check for '$CLASS(subst)' trick
97: // will hope that user ain't THAT self-hating person
98: // speed2:
99: // will not check for '$method_name(subst)' trick
100: // -same-
101:
1.2 paf 102: if(!replace) {
103: // for first call, pass call to last derived VObject
1.9.4.1 ! paf 104: if(get_last_derived().put_element(aname, avalue, true))
1.2 paf 105: return true;
1.1 paf 106:
1.2 paf 107: ffields.put(aname, avalue);
108: return false;
109: }
1.1 paf 110:
1.2 paf 111: // replace
1.1 paf 112: // upwards: copied from VClass::put_element...
113:
114: try {
115: if(fbase && fbase->put_element(aname, avalue, true))
116: return true; // replaced in base
1.2 paf 117:
118: return ffields.put_replace(aname, avalue);
1.4 paf 119: } catch(Exception) { /* allow override parent variables, useful for form descendants */ }
1.1 paf 120:
1.2 paf 121: // could not put to any base of last child
122: return false;
1.1 paf 123: }
124:
E-mail: