Annotation of parser3/src/types/pa_vobject.C, revision 1.21
1.1 paf 1: /** @file
2: Parser: @b object class impl.
3:
1.16 paf 4: Copyright (c) 2001-2004 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.21 ! paf 12: static const char * const IDENT_VOBJECT_C="$Date: 2005/07/28 10:02:27 $";
1.5 paf 13:
1.13 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
1.13 paf 37: Value& VObject::as_expr_result(bool) {
1.7 paf 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
1.13 paf 53: VFile* VObject::as_vfile(String::Language lang, const Request_charsets *charsets) {
54: return fbase?fbase->as_vfile(lang, charsets):
55: Value::as_vfile(lang, charsets);
1.7 paf 56: }
57:
58: /// VObject: from possible parent, if any
1.13 paf 59: HashStringValue* VObject::get_hash() {
60: if(Value* vhash=get_last_derived().as(VHASH_TYPE, false))
61: return vhash->get_hash();
1.7 paf 62:
63: return 0;
64: }
65: /// VObject: from possible 'table' parent
66: Table *VObject::get_table() {
1.10 paf 67: if(Value *vtable=get_last_derived().as(VTABLE_TYPE, false))
1.7 paf 68: return vtable->get_table();
69:
70: return 0;
71: }
1.1 paf 72:
73: /// VObject: (field)=value;(CLASS)=vclass;(method)=method_ref
1.14 paf 74: Value* VObject::get_element(const String& aname, Value&, bool looking_up) {
1.8 paf 75: // simple things first: $field=ffields.field
1.13 paf 76: if(Value* result=ffields.get(aname))
1.8 paf 77: return result;
78:
1.1 paf 79: // gets element from last_derivate upwards
1.5 paf 80: if(!looking_up) {
1.1 paf 81: // $CLASS
82: if(aname==CLASS_NAME)
83: return get_class();
84:
1.10 paf 85: // $virtual_method
86: VObject& last_derived=get_last_derived();
1.13 paf 87: if(Value* result=last_derived.stateless_object__get_element(aname, last_derived))
1.1 paf 88: return result;
89: }
90:
1.21 ! paf 91: return 0;
! 92: }
! 93:
! 94: const Junction* VObject::prevent_append_if_exists_in_static_or_base(Value* value, Prevent_append_if_exists_in_static_or_base_info* info) {
! 95: // $virtual_property, any this/bases $static_property
! 96: VObject& last_derived=info->_this->get_last_derived();
! 97: if(const Junction* result=last_derived.stateless_object__put_element(last_derived, *info->name, value))
! 98: return result; // replaced in any(derivate or base) statics fields/properties
1.1 paf 99:
100: return 0;
101: }
1.19 paf 102:
103: /// VObject: (field/property)=value
1.21 ! paf 104: const Junction* VObject::put_element(Value& /*aself*/, const String& aname, Value* avalue, bool /*areplace*/) {
! 105: Prevent_append_if_exists_in_static_or_base_info info={this, &aname};
! 106: return ffields.replace_maybe_append<const Junction*>(aname, avalue,
! 107: prevent_append_if_exists_in_static_or_base,
! 108: &info);
1.1 paf 109: }
E-mail: