Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.30
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.30 ! paf 11: static const char* IDENT_VSTATELESS_CLASS_H="$Date: 2002/08/12 10:32:53 $";
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: /**
1.30 ! paf 19: object' class. stores
! 20: - base: VClass::base()
! 21: - methods: VStateless_class::fmethods
1.6 paf 22:
1.30 ! paf 23: @see Method, VStateless_object, Temp_method
1.6 paf 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:
1.30 ! paf 34: /// VStateless_class: self or parent method junction
! 35: /*override*/ Junction *get_junction(const String& name, bool looking_down) {
! 36: if(Method *method=static_cast<Method *>(fmethods.get(name)))
! 37: return
! 38: new(name.pool()) Junction(name.pool(), *this, this, method, 0,0,0,0);
! 39: if(!looking_down && fbase)
! 40: return fbase->get_junction(name, looking_down);
! 41: return 0;
! 42: }
! 43:
1.7 paf 44: /// VStateless_class: +$method
45: Value *get_element(const String& aname) {
46: // $method=junction(self+class+method)
1.30 ! paf 47: if(Junction *junction=get_junction(aname, false))
1.15 parser 48: return new(junction->pool()) VJunction(*junction);
1.7 paf 49:
50: return 0;
51: }
1.2 paf 52:
53: public: // usage
54:
1.24 paf 55: VStateless_class(Pool& apool,
56: const String *aname=0,
1.29 paf 57: VStateless_class *abase=0) : Value(apool),
1.24 paf 58: fname(aname),
1.3 paf 59: fbase(abase),
1.2 paf 60: fmethods(apool) {
61: }
62:
1.24 paf 63: const String& name() const {
64: if(!fname) {
65: if(fbase)
66: return fbase->name();
67:
68: throw Exception("parser.runtime",
69: 0,
70: "getting name of nameless class");
71: }
72:
73: return *fname;
74: }
75: const char *name_cstr() const {
76: return this?name().cstr():"<unknown>";
77: }
78: void set_name(const String& aname) {
79: fname=&aname;
80: }
81:
1.26 paf 82: Method *get_method(const String& name) const {
1.2 paf 83: return static_cast<Method *>(fmethods.get(name));
84: }
85:
86: void add_method(const String& name, Method& method) {
87: put_method(name, &method);
88: }
89: void add_native_method(
90: const char *cstr_name,
1.9 paf 91: Method::Call_type call_type,
1.2 paf 92: Native_code_ptr native_code,
93: int min_numbered_params_count, int max_numbered_params_count);
94:
95: void set_base(VStateless_class& abase) {
96: // remember the guy
97: fbase=&abase;
98: }
1.30 ! paf 99: VStateless_class *base_class() { return fbase; }
1.2 paf 100:
1.30 ! paf 101: bool derived_from(VStateless_class& vclass) {
1.2 paf 102: return
1.30 ! paf 103: fbase==&vclass ||
! 104: fbase && fbase->derived_from(vclass);
1.2 paf 105: }
106:
1.11 paf 107: //@{
108: /// @name just stubs, real onces defined below the hierarchy
1.18 parser 109: virtual Value *get_field(const String& ) { return 0; }
110: virtual bool replace_field(const String& , Value *) { return false; }
1.21 paf 111: //@}
112:
113: /// @returns new value for current class, used in classes/ & VClass
1.18 parser 114: virtual Value *create_new_value(Pool& ) { return 0; }
1.2 paf 115:
116: private: // Temp_method
117:
1.8 paf 118: void put_method(const String& aname, Method *amethod) {
119: fmethods.put(aname, amethod);
120: }
1.2 paf 121:
122: private:
123:
1.24 paf 124: const String *fname;
1.2 paf 125: Hash fmethods;
126:
127: protected:
128:
129: VStateless_class *fbase;
130:
131: };
132:
1.6 paf 133: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 134: class Temp_method {
135: VStateless_class& fclass;
136: const String& fname;
137: Method *saved_method;
138: public:
139: Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) :
140: fclass(aclass),
141: fname(aname),
142: saved_method(aclass.get_method(aname)) {
143: fclass.put_method(aname, amethod);
144: }
145: ~Temp_method() {
146: fclass.put_method(fname, saved_method);
147: }
148: };
149:
150: #endif
E-mail: