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