Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.29
1.6 paf 1: /** @file
2: Parser: stateless class decls.
3:
1.22 paf 4: Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.23 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.2 paf 6: */
7:
8: #ifndef PA_VSTATELESS_CLASS_H
9: #define PA_VSTATELESS_CLASS_H
1.27 paf 10:
1.29 ! paf 11: static const char* IDENT_VSTATELESS_CLASS_H="$Date: 2002/08/01 11:41:24 $";
1.2 paf 12:
1.13 paf 13: #include "pa_hash.h"
1.2 paf 14: #include "pa_vjunction.h"
15:
16: class Temp_method;
17:
1.6 paf 18: /**
19: object' class.
20:
1.10 paf 21: basically collection of methods [VStateless_class::fmethods, Method]
1.6 paf 22:
23: @see VStateless_object, Temp_method
24: */
1.29 ! paf 25: class VStateless_class : public Value {
1.19 paf 26: friend class Temp_method;
1.2 paf 27: public: // Value
28:
29: const char *type() const { return "stateless_class"; }
30:
1.5 paf 31: /// VStateless_class: this
32: VStateless_class *get_class() { return this; }
1.7 paf 33:
34: /// VStateless_class: +$method
35: Value *get_element(const String& aname) {
36: // $method=junction(self+class+method)
37: if(Junction *junction=get_junction(*this, aname))
1.15 parser 38: return new(junction->pool()) VJunction(*junction);
1.7 paf 39:
40: return 0;
41: }
1.2 paf 42:
43: public: // usage
44:
1.24 paf 45: VStateless_class(Pool& apool,
46: const String *aname=0,
1.29 ! paf 47: VStateless_class *abase=0) : Value(apool),
1.24 paf 48: fname(aname),
1.3 paf 49: fbase(abase),
1.2 paf 50: fmethods(apool) {
51: }
52:
1.24 paf 53: const String& name() const {
54: if(!fname) {
55: if(fbase)
56: return fbase->name();
57:
58: throw Exception("parser.runtime",
59: 0,
60: "getting name of nameless class");
61: }
62:
63: return *fname;
64: }
65: const char *name_cstr() const {
66: return this?name().cstr():"<unknown>";
67: }
68: void set_name(const String& aname) {
69: fname=&aname;
70: }
71:
1.26 paf 72: Method *get_method(const String& name) const {
1.2 paf 73: return static_cast<Method *>(fmethods.get(name));
74: }
75:
76: void add_method(const String& name, Method& method) {
77: put_method(name, &method);
78: }
79: void add_native_method(
80: const char *cstr_name,
1.9 paf 81: Method::Call_type call_type,
1.2 paf 82: Native_code_ptr native_code,
83: int min_numbered_params_count, int max_numbered_params_count);
84:
85: void set_base(VStateless_class& abase) {
86: // remember the guy
87: fbase=&abase;
88: }
89: VStateless_class *base() { return fbase; }
90:
91: bool is_or_derived_from(VStateless_class& vclass) {
92: return
93: this==&vclass ||
94: fbase && fbase->is_or_derived_from(vclass);
95: }
96:
1.29 ! paf 97: Junction *get_junction(Value& self, const String& name) {
1.2 paf 98: if(Method *method=static_cast<Method *>(fmethods.get(name)))
1.15 parser 99: return
100: new(name.pool()) Junction(name.pool(), self, this, method, 0,0,0,0);
1.2 paf 101: if(fbase)
102: return fbase->get_junction(self, name);
103: return 0;
104: }
105:
1.11 paf 106: //@{
107: /// @name just stubs, real onces defined below the hierarchy
1.18 parser 108: virtual Value *get_field(const String& ) { return 0; }
109: virtual bool replace_field(const String& , Value *) { return false; }
1.21 paf 110: //@}
111:
112: /// @returns new value for current class, used in classes/ & VClass
1.18 parser 113: virtual Value *create_new_value(Pool& ) { return 0; }
1.2 paf 114:
115: private: // Temp_method
116:
1.8 paf 117: void put_method(const String& aname, Method *amethod) {
118: fmethods.put(aname, amethod);
119: }
1.2 paf 120:
121: private:
122:
1.24 paf 123: const String *fname;
1.2 paf 124: Hash fmethods;
125:
126: protected:
127:
128: VStateless_class *fbase;
129:
130: };
131:
1.6 paf 132: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 133: class Temp_method {
134: VStateless_class& fclass;
135: const String& fname;
136: Method *saved_method;
137: public:
138: Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) :
139: fclass(aclass),
140: fname(aname),
141: saved_method(aclass.get_method(aname)) {
142: fclass.put_method(aname, amethod);
143: }
144: ~Temp_method() {
145: fclass.put_method(fname, saved_method);
146: }
147: };
148:
149: #endif
E-mail: