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