Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.10
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.10 ! paf 8: $Id: pa_vstateless_class.h,v 1.9 2001/03/30 05:53:04 paf Exp $
1.2 paf 9: */
10:
11: #ifndef PA_VSTATELESS_CLASS_H
12: #define PA_VSTATELESS_CLASS_H
13:
14: #include "pa_valiased.h"
15: #include "pa_vhash.h"
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:
1.5 paf 31: /// all: for error reporting after fail(), etc
1.2 paf 32: const char *type() const { return "stateless_class"; }
33:
1.5 paf 34: /// VStateless_class: this
35: VStateless_class *get_class() { return this; }
1.7 paf 36:
37: /// VStateless_class: +$method
38: Value *get_element(const String& aname) {
39: // $CLASS, $BASE
40: if(Value *result=VAliased::get_element(aname))
41: return result;
42: // $method=junction(self+class+method)
43: if(Junction *junction=get_junction(*this, aname))
44: return NEW VJunction(*junction);
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)))
83: return NEW Junction(pool(), self, this, method, 0,0,0,0);
84: if(fbase)
85: return fbase->get_junction(self, name);
86: return 0;
87: }
88:
89: // just stubs, real onces defined below the hierarchy, in
90: virtual Value *get_field(const String& name) { return 0; }
91: virtual bool replace_field(const String& name, Value *value) { return false; }
92:
93: private: // Temp_method
94:
1.8 paf 95: void put_method(const String& aname, Method *amethod) {
96: fmethods.put(aname, amethod);
97: }
1.2 paf 98:
99: private:
100:
101: Hash fmethods;
102:
103: protected:
104:
105: VStateless_class *fbase;
106:
107: };
108:
1.6 paf 109: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 110: class Temp_method {
111: VStateless_class& fclass;
112: const String& fname;
113: Method *saved_method;
114: public:
115: Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) :
116: fclass(aclass),
117: fname(aname),
118: saved_method(aclass.get_method(aname)) {
119: fclass.put_method(aname, amethod);
120: }
121: ~Temp_method() {
122: fclass.put_method(fname, saved_method);
123: }
124: };
125:
126: #endif
E-mail: