Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.8
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.8 ! paf 8: $Id: pa_vstateless_class.h,v 1.7 2001/03/19 22:38:11 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:
23: basically collection of methods.
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,
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)))
82: return NEW Junction(pool(), self, this, method, 0,0,0,0);
83: if(fbase)
84: return fbase->get_junction(self, name);
85: return 0;
86: }
87:
88: // just stubs, real onces defined below the hierarchy, in
89: virtual Value *get_field(const String& name) { return 0; }
90: virtual bool replace_field(const String& name, Value *value) { return false; }
91:
92: private: // Temp_method
93:
1.8 ! paf 94: void put_method(const String& aname, Method *amethod) {
! 95: fmethods.put(aname, amethod);
! 96: }
1.2 paf 97:
98: private:
99:
100: Hash fmethods;
101:
102: protected:
103:
104: VStateless_class *fbase;
105:
106: };
107:
1.6 paf 108: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 109: class Temp_method {
110: VStateless_class& fclass;
111: const String& fname;
112: Method *saved_method;
113: public:
114: Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) :
115: fclass(aclass),
116: fname(aname),
117: saved_method(aclass.get_method(aname)) {
118: fclass.put_method(aname, amethod);
119: }
120: ~Temp_method() {
121: fclass.put_method(fname, saved_method);
122: }
123: };
124:
125: #endif
E-mail: