Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.40.4.1
1.6 paf 1: /** @file
2: Parser: stateless class decls.
3:
1.22 paf 4: Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.23 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.2 paf 6: */
7:
8: #ifndef PA_VSTATELESS_CLASS_H
9: #define PA_VSTATELESS_CLASS_H
1.27 paf 10:
1.40.4.1! paf 11: static const char* IDENT_VSTATELESS_CLASS_H="$Date: 2002/10/15 10:05:01 $";
1.2 paf 12:
1.13 paf 13: #include "pa_hash.h"
1.2 paf 14: #include "pa_vjunction.h"
15:
1.38 paf 16: // defines
17:
18: #define CLASS_NAME "CLASS"
19:
20: // forwards
21:
1.2 paf 22: class Temp_method;
23:
1.6 paf 24: /**
1.30 paf 25: object' class. stores
26: - base: VClass::base()
27: - methods: VStateless_class::fmethods
1.6 paf 28:
1.30 paf 29: @see Method, VStateless_object, Temp_method
1.6 paf 30: */
1.39 paf 31: class VStateless_class: public Value {
1.19 paf 32: friend class Temp_method;
1.2 paf 33: public: // Value
34:
35: const char *type() const { return "stateless_class"; }
36:
1.5 paf 37: /// VStateless_class: this
1.40.4.1! paf 38: /*override*/ VStateless_class *get_class() { return this; }
! 39: /*override*/ Value& get_last_derived() {
! 40: return fderived?fderived->get_last_derived():*static_cast<Value *>(this);
! 41: }
! 42: /*override*/ Value *base() { return fbase; }
1.7 paf 43:
1.40.4.1! paf 44: /*overridef*/ Value *get_element(const String& aname, Value& aself, bool looking_up);
! 45:
! 46: /// VObject: remember derived [one of two client] */
! 47: /*override*/ Value *set_derived(Value *aderived) {
! 48: Value *result=fderived;
! 49: fderived=aderived;
! 50: return result;
! 51: }
1.2 paf 52:
53: public: // usage
54:
1.24 paf 55: VStateless_class(Pool& apool,
56: const String *aname=0,
1.29 paf 57: VStateless_class *abase=0) : Value(apool),
1.24 paf 58: fname(aname),
1.40.4.1! paf 59: fmethods(apool),
! 60: fderived(0) {
! 61: set_base(abase);
1.2 paf 62: }
63:
1.24 paf 64: const String& name() const {
65: if(!fname) {
66: if(fbase)
67: return fbase->name();
68:
69: throw Exception("parser.runtime",
70: 0,
71: "getting name of nameless class");
72: }
73:
74: return *fname;
75: }
76: const char *name_cstr() const {
77: return this?name().cstr():"<unknown>";
78: }
79: void set_name(const String& aname) {
80: fname=&aname;
81: }
82:
1.26 paf 83: Method *get_method(const String& name) const {
1.2 paf 84: return static_cast<Method *>(fmethods.get(name));
85: }
86:
1.40 paf 87: void add_method(const String& name, Method& method);
88:
1.2 paf 89: void add_native_method(
90: const char *cstr_name,
1.9 paf 91: Method::Call_type call_type,
1.2 paf 92: Native_code_ptr native_code,
93: int min_numbered_params_count, int max_numbered_params_count);
94:
1.32 paf 95: VStateless_class *set_base(VStateless_class *abase) {
96: VStateless_class *result=fbase;
1.2 paf 97: // remember the guy
1.32 paf 98: fbase=abase;
1.40.4.1! paf 99: if(fbase)
! 100: fbase->set_derived(this);
1.32 paf 101: return result;
1.2 paf 102: }
1.30 paf 103: VStateless_class *base_class() { return fbase; }
1.2 paf 104:
1.30 paf 105: bool derived_from(VStateless_class& vclass) {
1.2 paf 106: return
1.30 paf 107: fbase==&vclass ||
108: fbase && fbase->derived_from(vclass);
1.31 paf 109: }
110:
1.11 paf 111: //@{
112: /// @name just stubs, real onces defined below the hierarchy
1.18 parser 113: virtual Value *get_field(const String& ) { return 0; }
114: virtual bool replace_field(const String& , Value *) { return false; }
1.21 paf 115: //@}
116:
117: /// @returns new value for current class, used in classes/ & VClass
1.18 parser 118: virtual Value *create_new_value(Pool& ) { return 0; }
1.2 paf 119:
120: private: // Temp_method
121:
1.8 paf 122: void put_method(const String& aname, Method *amethod) {
123: fmethods.put(aname, amethod);
124: }
1.2 paf 125:
126: private:
127:
1.24 paf 128: const String *fname;
1.2 paf 129: Hash fmethods;
1.40.4.1! paf 130: Value *fderived;
1.2 paf 131:
132: protected:
133:
134: VStateless_class *fbase;
135:
136: };
137:
1.6 paf 138: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 139: class Temp_method {
140: VStateless_class& fclass;
141: const String& fname;
142: Method *saved_method;
143: public:
144: Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) :
145: fclass(aclass),
146: fname(aname),
147: saved_method(aclass.get_method(aname)) {
148: fclass.put_method(aname, amethod);
149: }
150: ~Temp_method() {
151: fclass.put_method(fname, saved_method);
152: }
153: };
154:
155: #endif
E-mail: