Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.44
1.6 paf 1: /** @file
2: Parser: stateless class decls.
3:
1.43 paf 4: Copyright (c) 2001-2003 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.44 ! paf 11: static const char* IDENT_VSTATELESS_CLASS_H="$Date: 2003/09/24 14:32:06 $";
1.43 paf 12:
13: // include
1.2 paf 14:
1.13 paf 15: #include "pa_hash.h"
1.2 paf 16: #include "pa_vjunction.h"
1.43 paf 17: #include "pa_method.h"
1.2 paf 18:
1.38 paf 19: // defines
20:
21: #define CLASS_NAME "CLASS"
22:
23: // forwards
24:
1.43 paf 25: class VStateless_class;
26:
1.2 paf 27: class Temp_method;
28:
1.6 paf 29: /**
1.30 paf 30: object' class. stores
31: - base: VClass::base()
32: - methods: VStateless_class::fmethods
1.6 paf 33:
1.30 paf 34: @see Method, VStateless_object, Temp_method
1.6 paf 35: */
1.39 paf 36: class VStateless_class: public Value {
1.19 paf 37: friend class Temp_method;
1.43 paf 38:
39: const String* fname;
40: mutable const char* fname_cstr;
1.44 ! paf 41: Hash<const String::Body, Method*> fmethods;
1.43 paf 42:
43: bool flocked;
44:
45: protected:
46:
47: VStateless_class* fbase;
48:
1.2 paf 49: public: // Value
50:
1.43 paf 51: const char* type() const { return "stateless_class"; }
1.2 paf 52:
1.5 paf 53: /// VStateless_class: this
1.43 paf 54: override VStateless_class *get_class() { return this; }
1.41 paf 55: /// VStateless_class: fbase
1.43 paf 56: override Value* base() { return fbase; }
57: override Value* get_element(const String& aname, Value& aself, bool looking_up);
1.2 paf 58:
59: public: // usage
60:
1.43 paf 61: VStateless_class(
62: const String* aname=0,
63: VStateless_class* abase=0):
1.24 paf 64: fname(aname),
1.43 paf 65: flocked(false),
66: fbase(abase) {
1.2 paf 67: }
68:
1.43 paf 69: void lock() { flocked=true; }
70:
1.24 paf 71: const String& name() const {
72: if(!fname) {
73: if(fbase)
74: return fbase->name();
75:
76: throw Exception("parser.runtime",
77: 0,
78: "getting name of nameless class");
79: }
80:
81: return *fname;
82: }
1.43 paf 83: const char* name_cstr() const{
84: if(this) {
85: if(!fname_cstr) // remembering last calculated, and can't reassign 'fname_cstr'!
86: fname_cstr=name().cstr();
87: return fname_cstr;
88: } else
89: return "<unknown>";
1.24 paf 90: }
91: void set_name(const String& aname) {
92: fname=&aname;
93: }
94:
1.43 paf 95: Method* get_method(const String& aname) const {
96: return fmethods.get(aname);
1.2 paf 97: }
98:
1.40 paf 99: void add_method(const String& name, Method& method);
100:
1.2 paf 101: void add_native_method(
1.43 paf 102: const char* cstr_name,
1.9 paf 103: Method::Call_type call_type,
1.43 paf 104: NativeCodePtr native_code,
1.2 paf 105: int min_numbered_params_count, int max_numbered_params_count);
106:
1.43 paf 107: void set_base(VStateless_class* abase) {
1.2 paf 108: // remember the guy
1.32 paf 109: fbase=abase;
1.2 paf 110: }
1.43 paf 111: VStateless_class* base_class() { return fbase; }
1.2 paf 112:
1.30 paf 113: bool derived_from(VStateless_class& vclass) {
1.2 paf 114: return
1.30 paf 115: fbase==&vclass ||
116: fbase && fbase->derived_from(vclass);
1.31 paf 117: }
118:
1.11 paf 119: //@{
120: /// @name just stubs, real onces defined below the hierarchy
1.43 paf 121: virtual Value* get_field(const String&) { return 0; }
122: virtual bool replace_field(const String&, Value*) { return false; }
1.21 paf 123: //@}
124:
125: /// @returns new value for current class, used in classes/ & VClass
1.43 paf 126: virtual Value* create_new_value() { return 0; }
1.2 paf 127:
128: private: // Temp_method
129:
1.43 paf 130: void put_method(const String& aname, Method* amethod) {
1.8 paf 131: fmethods.put(aname, amethod);
132: }
1.2 paf 133:
134: };
135:
1.6 paf 136: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 137: class Temp_method {
138: VStateless_class& fclass;
139: const String& fname;
1.43 paf 140: Method* saved_method;
1.2 paf 141: public:
1.43 paf 142: Temp_method(VStateless_class& aclass, const String& aname, Method* amethod) :
1.2 paf 143: fclass(aclass),
144: fname(aname),
145: saved_method(aclass.get_method(aname)) {
146: fclass.put_method(aname, amethod);
147: }
148: ~Temp_method() {
149: fclass.put_method(fname, saved_method);
150: }
151: };
152:
153: #endif
E-mail: