Annotation of parser3/src/types/pa_vobject.C, revision 1.4
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"
9:
1.4 ! paf 10: static const char* IDENT_VOBJECT_C="$Date: 2002/08/13 15:55:44 $";
1.1 paf 11:
12: /// VObject: true, todo: z base table can be 33
13: Value *VObject::as_expr_result(bool) { return NEW VBool(pool(), as_bool()); }
14: /// VObject: true, todo: z base table can be false
15: bool VObject::as_bool() const { return true; }
16:
17: /// VObject: (field)=value;(CLASS)=vclass;(method)=method_ref
1.3 paf 18: Value *VObject::get_element(const String& aname, Value * /*aself*/, bool looking_down) {
1.1 paf 19: // gets element from last_derivate upwards
1.3 paf 20: if(!looking_down) {
1.1 paf 21: // $CLASS
22: if(aname==CLASS_NAME)
23: return get_class();
24:
25: // for first call, pass call to last derived VObject
1.3 paf 26: return get_last_derived()->get_element(aname,
27: 0, true/*the only user*/);
1.1 paf 28: }
29:
30: // $method, $CLASS_field
31: {
32: Temp_base temp_base(*get_class(), 0);
1.3 paf 33: if(Value *result=VStateless_object::get_element(aname, this, true))
1.1 paf 34: return result;
35: }
36:
37: // $field=ffields.field
38: if(Value *result=static_cast<Value *>(ffields.get(aname)))
39: return result;
40:
41: // up the tree...
42: if(fbase)
1.3 paf 43: if(Value *result=fbase->get_element(aname, fbase, true))
1.1 paf 44: return result;
45:
46: return 0;
47: }
48:
49: /// VObject: (field)=value
50: bool VObject::put_element(const String& aname, Value *avalue, bool replace) {
51: // replaces element to last_derivate upwards or stores it in self
52: // speed1:
53: // will not check for '$CLASS(subst)' trick
54: // will hope that user ain't THAT self-hating person
55: // speed2:
56: // will not check for '$method_name(subst)' trick
57: // -same-
58:
1.2 paf 59: if(!replace) {
60: // for first call, pass call to last derived VObject
61: if(get_last_derived()->put_element(aname, avalue, true))
62: return true;
1.1 paf 63:
1.2 paf 64: ffields.put(aname, avalue);
65: return false;
66: }
1.1 paf 67:
1.2 paf 68: // replace
1.1 paf 69: // upwards: copied from VClass::put_element...
70:
71: try {
72: if(fbase && fbase->put_element(aname, avalue, true))
73: return true; // replaced in base
1.2 paf 74:
75: return ffields.put_replace(aname, avalue);
1.4 ! paf 76: } catch(Exception) { /* allow override parent variables, useful for form descendants */ }
1.1 paf 77:
1.2 paf 78: // could not put to any base of last child
79: return false;
1.1 paf 80: }
81:
E-mail: