Annotation of parser3/src/types/pa_vobject.C, revision 1.11
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.11 ! paf 12: static const char* IDENT_VOBJECT_C="$Date: 2002/10/31 15:01:56 $";
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.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
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.10 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.10 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.10 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.1 paf 78: // gets element from last_derivate upwards
1.5 paf 79: if(!looking_up) {
1.1 paf 80: // $CLASS
81: if(aname==CLASS_NAME)
82: return get_class();
83:
1.10 paf 84: // $virtual_method
85: VObject& last_derived=get_last_derived();
86: if(Value *result=last_derived.stateless_object__get_element(aname, last_derived))
1.1 paf 87: return result;
88: }
89:
1.10 paf 90: // up the tree for other $virtual_field try...
1.1 paf 91: if(fbase)
1.10 paf 92: if(Value *result=fbase->get_element(aname, *fbase, true))
1.1 paf 93: return result;
94:
95: return 0;
96: }
1.10 paf 97: Value *VObject::stateless_object__get_element(const String& aname, Value& aself) {
98: return VStateless_object::get_element(aname, aself, false);
99: }
1.1 paf 100:
101: /// VObject: (field)=value
102: bool VObject::put_element(const String& aname, Value *avalue, bool replace) {
1.11 ! paf 103: if(fbase && fbase->put_element(aname, avalue, true))
! 104: return true; // replaced in base dynamic fields
1.1 paf 105:
1.10 paf 106: if(replace)
107: return ffields.put_replace(aname, avalue);
108: else {
1.11 ! paf 109: if(VStateless_object::put_element(aname, avalue, true))
! 110: return true; // replaced in base statics fields
! 111:
1.2 paf 112: ffields.put(aname, avalue);
113: return false;
114: }
1.1 paf 115: }
116:
E-mail: