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