Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.16
1.6 paf 1: /** @file
2: Parser: stateless class decls.
3:
1.2 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.6 paf 5:
1.2 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
7:
1.16 ! parser 8: $Id: pa_vstateless_class.h,v 1.15 2001/07/11 15:02:09 parser Exp $
1.2 paf 9: */
10:
11: #ifndef PA_VSTATELESS_CLASS_H
12: #define PA_VSTATELESS_CLASS_H
13:
14: #include "pa_valiased.h"
1.13 paf 15: #include "pa_hash.h"
1.2 paf 16: #include "pa_vjunction.h"
17:
18: class Temp_method;
19:
1.6 paf 20: /**
21: object' class.
22:
1.10 paf 23: basically collection of methods [VStateless_class::fmethods, Method]
1.6 paf 24:
25: @see VStateless_object, Temp_method
26: */
1.2 paf 27: class VStateless_class : public VAliased {
28: friend Temp_method;
29: public: // Value
30:
31: const char *type() const { return "stateless_class"; }
32:
1.5 paf 33: /// VStateless_class: this
34: VStateless_class *get_class() { return this; }
1.7 paf 35:
36: /// VStateless_class: +$method
37: Value *get_element(const String& aname) {
1.16 ! parser 38: // $CLASS
1.7 paf 39: if(Value *result=VAliased::get_element(aname))
40: return result;
1.14 paf 41:
1.7 paf 42: // $method=junction(self+class+method)
43: if(Junction *junction=get_junction(*this, aname))
1.15 parser 44: return new(junction->pool()) VJunction(*junction);
1.7 paf 45:
46: return 0;
47: }
1.2 paf 48:
49: public: // usage
50:
1.3 paf 51: VStateless_class(Pool& apool, VStateless_class *abase=0) : VAliased(apool, *this),
52: fbase(abase),
1.2 paf 53: fmethods(apool) {
54: }
55:
56: Method *get_method(const String& name) {
57: return static_cast<Method *>(fmethods.get(name));
58: }
59:
60: void add_method(const String& name, Method& method) {
61: put_method(name, &method);
62: }
63: void add_native_method(
64: const char *cstr_name,
1.9 paf 65: Method::Call_type call_type,
1.2 paf 66: Native_code_ptr native_code,
67: int min_numbered_params_count, int max_numbered_params_count);
68:
69: void set_base(VStateless_class& abase) {
70: // remember the guy
71: fbase=&abase;
72: }
73: VStateless_class *base() { return fbase; }
74:
75: bool is_or_derived_from(VStateless_class& vclass) {
76: return
77: this==&vclass ||
78: fbase && fbase->is_or_derived_from(vclass);
79: }
80:
81: Junction *get_junction(VAliased& self, const String& name) {
82: if(Method *method=static_cast<Method *>(fmethods.get(name)))
1.15 parser 83: return
84: new(name.pool()) Junction(name.pool(), self, this, method, 0,0,0,0);
1.2 paf 85: if(fbase)
86: return fbase->get_junction(self, name);
87: return 0;
88: }
89:
1.11 paf 90: //@{
91: /// @name just stubs, real onces defined below the hierarchy
1.2 paf 92: virtual Value *get_field(const String& name) { return 0; }
93: virtual bool replace_field(const String& name, Value *value) { return false; }
1.11 paf 94:
95: virtual Value *create_new_value(Pool& pool) { return 0; }
96: //@}
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: