Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.4
1.2 paf 1: /*
2: Parser
3: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
4: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
5:
1.4 ! paf 6: $Id: pa_vstateless_class.h,v 1.3 2001/03/13 16:38:27 paf Exp $
1.2 paf 7: */
8:
9: #ifndef PA_VSTATELESS_CLASS_H
10: #define PA_VSTATELESS_CLASS_H
11:
12: #include "pa_valiased.h"
13: #include "pa_vhash.h"
14: #include "pa_vjunction.h"
15:
1.4 ! paf 16: #define CLASS_NAME "CLASS"
! 17: #define BASE_NAME "BASE"
1.2 paf 18:
19: class Temp_method;
20:
21: class VStateless_class : public VAliased {
22: friend Temp_method;
23: public: // Value
24:
25: // all: for error reporting after fail(), etc
26: const char *type() const { return "stateless_class"; }
27:
1.4 ! paf 28: // stateless_class: $CLASS,$BASE,$method
1.2 paf 29: Value *get_element(const String& aname);
30:
31: public: // usage
32:
1.3 paf 33: VStateless_class(Pool& apool, VStateless_class *abase=0) : VAliased(apool, *this),
34: fbase(abase),
1.2 paf 35: read_only(false),
36: fmethods(apool) {
37: }
38:
39: Method *get_method(const String& name) {
40: return static_cast<Method *>(fmethods.get(name));
41: }
42:
43: // make class read-only
44: // this blocks put_method // which could be done with ^process
45: void freeze() { read_only=true; }
46:
47: void add_method(const String& name, Method& method) {
48: put_method(name, &method);
49: }
50: void add_native_method(
51: const char *cstr_name,
52: Native_code_ptr native_code,
53: int min_numbered_params_count, int max_numbered_params_count);
54:
55: void set_base(VStateless_class& abase) {
56: // remember the guy
57: fbase=&abase;
58: }
59: VStateless_class *base() { return fbase; }
60:
61: bool is_or_derived_from(VStateless_class& vclass) {
62: return
63: this==&vclass ||
64: fbase && fbase->is_or_derived_from(vclass);
65: }
66:
67: Junction *get_junction(VAliased& self, const String& name) {
68: if(Method *method=static_cast<Method *>(fmethods.get(name)))
69: return NEW Junction(pool(), self, this, method, 0,0,0,0);
70: if(fbase)
71: return fbase->get_junction(self, name);
72: return 0;
73: }
74:
75: // just stubs, real onces defined below the hierarchy, in
76: virtual Value *get_field(const String& name) { return 0; }
77: virtual bool replace_field(const String& name, Value *value) { return false; }
78:
79: private: // Temp_method
80:
81: void put_method(const String& aname, Method *amethod);
82:
83: private:
84:
85: Hash fmethods;
86:
87: protected:
88:
89: VStateless_class *fbase;
90: bool read_only;
91:
92: };
93:
94: class Temp_method {
95: VStateless_class& fclass;
96: const String& fname;
97: Method *saved_method;
98: public:
99: Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) :
100: fclass(aclass),
101: fname(aname),
102: saved_method(aclass.get_method(aname)) {
103: fclass.put_method(aname, amethod);
104: }
105: ~Temp_method() {
106: fclass.put_method(fname, saved_method);
107: }
108: };
109:
110: #endif
E-mail: