Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.13
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.13 ! paf 8: $Id: pa_vstateless_class.h,v 1.12 2001/05/07 14:00:54 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"
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) {
38: // $CLASS, $BASE
39: if(Value *result=VAliased::get_element(aname))
40: return result;
41: // $method=junction(self+class+method)
42: if(Junction *junction=get_junction(*this, aname))
43: return NEW VJunction(*junction);
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)))
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:
1.11 paf 88: //@{
89: /// @name just stubs, real onces defined below the hierarchy
1.2 paf 90: virtual Value *get_field(const String& name) { return 0; }
91: virtual bool replace_field(const String& name, Value *value) { return false; }
1.11 paf 92:
93: virtual Value *create_new_value(Pool& pool) { return 0; }
94: //@}
1.2 paf 95:
96: private: // Temp_method
97:
1.8 paf 98: void put_method(const String& aname, Method *amethod) {
99: fmethods.put(aname, amethod);
100: }
1.2 paf 101:
102: private:
103:
104: Hash fmethods;
105:
106: protected:
107:
108: VStateless_class *fbase;
109:
110: };
111:
1.6 paf 112: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 113: class Temp_method {
114: VStateless_class& fclass;
115: const String& fname;
116: Method *saved_method;
117: public:
118: Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) :
119: fclass(aclass),
120: fname(aname),
121: saved_method(aclass.get_method(aname)) {
122: fclass.put_method(aname, amethod);
123: }
124: ~Temp_method() {
125: fclass.put_method(fname, saved_method);
126: }
127: };
128:
129: #endif
E-mail: