Annotation of parser3/src/types/pa_vobject.h, revision 1.31
1.6 paf 1: /** @file
1.7 paf 2: Parser: @b object class decl.
3:
1.15 paf 4: Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.16 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
8: #ifndef PA_VOBJECT_H
9: #define PA_VOBJECT_H
10:
1.31 ! paf 11: static const char* IDENT_VOBJECT_H="$Date: 2002/08/13 15:55:44 $";
1.19 paf 12:
1.1 paf 13: #include "pa_vjunction.h"
14: #include "pa_vclass.h"
1.4 paf 15: #include "pa_vstateless_object.h"
1.6 paf 16:
1.23 paf 17: // defines
18:
19: #define CLASS_NAME "CLASS"
20: #define BASE_NAME "BASE"
21:
1.26 paf 22: /** parser class instance, stores
23: - class VObject::fclass;
24: - fields VObject::ffields (dynamic, not static, which are stored in class).
25: - links to base/derived instances [VObject::fbase, VObject::fderived]
1.6 paf 26: */
1.24 paf 27: class VObject: public VStateless_object {
1.1 paf 28: public: // Value
29:
1.24 paf 30: const char *type() const { return fclass.name_cstr(); }
1.31 ! paf 31: /*override*/ bool is(const char *atype, bool looking_up) const;
1.12 parser 32:
1.25 paf 33: /// VObject: fclass
34: VStateless_class *get_class() { return &fclass; }
35: /// VObject: fbase
36: /*override*/ Value *base_object() { return fbase; }
1.29 paf 37: Value *as_expr_result(bool);
38: bool as_bool() const;
1.31 ! paf 39: /*override*/ Value *get_element(const String& aname, Value *aself, bool /*looking_up*/);
1.29 paf 40: /*override*/ bool put_element(const String& aname, Value *avalue, bool replace);
1.1 paf 41:
1.24 paf 42: /// VObject: remember derived [the only client] */
1.26 paf 43: /*override*/ VObject *set_derived(VObject *aderived) {
44: VObject *result=fderived;
1.25 paf 45: fderived=aderived;
46: return fderived;
1.24 paf 47: }
48:
1.1 paf 49: public: // creation
50:
1.24 paf 51: VObject(Pool& apool, VStateless_class& aclass) : VStateless_object(apool),
52: fclass(aclass),
53: ffields(apool),
54: fderived(0),
1.25 paf 55: fbase(fclass.base_class()?fclass.base_class()->create_new_value(apool):0) {
1.24 paf 56: if(fbase)
1.25 paf 57: fbase->set_derived(this);
1.1 paf 58: }
59:
60: private:
61:
1.26 paf 62: Value *get_last_derived() {
63: return fderived?fderived->get_last_derived():this;
1.31 ! paf 64: }
! 65:
! 66: const Value *get_last_derived_const() const {
! 67: return fderived?fderived->get_last_derived_const():this;
1.26 paf 68: }
69:
70: private:
71:
1.24 paf 72: VStateless_class& fclass;
1.1 paf 73: Hash ffields;
1.26 paf 74: VObject *fderived;
1.24 paf 75: Value *fbase;
1.25 paf 76: };
77:
78: class Temp_derived {
79: Value& fvalue;
1.26 paf 80: VObject *fsaved_derived;
1.25 paf 81: public:
1.26 paf 82: Temp_derived(Value& avalue, VObject *aderived) :
1.25 paf 83: fvalue(avalue),
84: fsaved_derived(avalue.set_derived(aderived)) {}
85: ~Temp_derived() { fvalue.set_derived(fsaved_derived); }
1.1 paf 86: };
87:
88: #endif
E-mail: