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