Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.22
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.20 paf 5: Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.2 paf 6:
1.22 ! paf 7: $Id: pa_vstateless_class.h,v 1.21 2001/11/14 07:46:42 paf Exp $
1.2 paf 8: */
9:
10: #ifndef PA_VSTATELESS_CLASS_H
11: #define PA_VSTATELESS_CLASS_H
12:
13: #include "pa_valiased.h"
1.13 paf 14: #include "pa_hash.h"
1.2 paf 15: #include "pa_vjunction.h"
16:
17: class Temp_method;
18:
1.6 paf 19: /**
20: object' class.
21:
1.10 paf 22: basically collection of methods [VStateless_class::fmethods, Method]
1.6 paf 23:
24: @see VStateless_object, Temp_method
25: */
1.2 paf 26: class VStateless_class : public VAliased {
1.19 paf 27: friend class Temp_method;
1.2 paf 28: public: // Value
29:
30: const char *type() const { return "stateless_class"; }
31:
1.5 paf 32: /// VStateless_class: this
33: VStateless_class *get_class() { return this; }
1.7 paf 34:
35: /// VStateless_class: +$method
36: Value *get_element(const String& aname) {
1.16 parser 37: // $CLASS
1.7 paf 38: if(Value *result=VAliased::get_element(aname))
39: return result;
1.14 paf 40:
1.7 paf 41: // $method=junction(self+class+method)
42: if(Junction *junction=get_junction(*this, aname))
1.15 parser 43: return new(junction->pool()) VJunction(*junction);
1.7 paf 44:
45: return 0;
46: }
1.2 paf 47:
48: public: // usage
49:
1.3 paf 50: VStateless_class(Pool& apool, VStateless_class *abase=0) : VAliased(apool, *this),
51: fbase(abase),
1.2 paf 52: fmethods(apool) {
53: }
54:
55: Method *get_method(const String& name) {
56: return static_cast<Method *>(fmethods.get(name));
57: }
58:
59: void add_method(const String& name, Method& method) {
60: put_method(name, &method);
61: }
62: void add_native_method(
63: const char *cstr_name,
1.9 paf 64: Method::Call_type call_type,
1.2 paf 65: Native_code_ptr native_code,
66: int min_numbered_params_count, int max_numbered_params_count);
67:
68: void set_base(VStateless_class& abase) {
69: // remember the guy
70: fbase=&abase;
71: }
72: VStateless_class *base() { return fbase; }
73:
74: bool is_or_derived_from(VStateless_class& vclass) {
75: return
76: this==&vclass ||
77: fbase && fbase->is_or_derived_from(vclass);
78: }
79:
80: Junction *get_junction(VAliased& self, const String& name) {
81: if(Method *method=static_cast<Method *>(fmethods.get(name)))
1.15 parser 82: return
83: new(name.pool()) Junction(name.pool(), self, this, method, 0,0,0,0);
1.2 paf 84: if(fbase)
85: return fbase->get_junction(self, name);
86: return 0;
87: }
88:
1.11 paf 89: //@{
90: /// @name just stubs, real onces defined below the hierarchy
1.18 parser 91: virtual Value *get_field(const String& ) { return 0; }
92: virtual bool replace_field(const String& , Value *) { return false; }
1.21 paf 93: //@}
94:
95: /// @returns new value for current class, used in classes/ & VClass
1.18 parser 96: virtual Value *create_new_value(Pool& ) { return 0; }
1.2 paf 97:
98: private: // Temp_method
99:
1.8 paf 100: void put_method(const String& aname, Method *amethod) {
101: fmethods.put(aname, amethod);
102: }
1.2 paf 103:
104: private:
105:
106: Hash fmethods;
107:
108: protected:
109:
110: VStateless_class *fbase;
111:
112: };
113:
1.6 paf 114: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 115: class Temp_method {
116: VStateless_class& fclass;
117: const String& fname;
118: Method *saved_method;
119: public:
120: Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) :
121: fclass(aclass),
122: fname(aname),
123: saved_method(aclass.get_method(aname)) {
124: fclass.put_method(aname, amethod);
125: }
126: ~Temp_method() {
127: fclass.put_method(fname, saved_method);
128: }
129: };
130:
131: #endif
E-mail: