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