Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.50
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.50 ! paf 11: static const char * const IDENT_VSTATELESS_CLASS_H="$Date: 2005/07/15 06:16:42 $";
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.49 paf 44: Hash<const String::Body, Property*> fprops;
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.50 ! paf 102: /* Property* get_property(const String& aname) const {
1.49 paf 103: return fprops.get(aname);
104: }
1.50 ! paf 105: */
1.40 paf 106: void add_method(const String& name, Method& method);
107:
1.2 paf 108: void add_native_method(
1.43 paf 109: const char* cstr_name,
1.9 paf 110: Method::Call_type call_type,
1.43 paf 111: NativeCodePtr native_code,
1.2 paf 112: int min_numbered_params_count, int max_numbered_params_count);
113:
1.43 paf 114: void set_base(VStateless_class* abase) {
1.2 paf 115: // remember the guy
1.32 paf 116: fbase=abase;
1.2 paf 117: }
1.43 paf 118: VStateless_class* base_class() { return fbase; }
1.2 paf 119:
1.30 paf 120: bool derived_from(VStateless_class& vclass) {
1.2 paf 121: return
1.30 paf 122: fbase==&vclass ||
123: fbase && fbase->derived_from(vclass);
1.31 paf 124: }
125:
1.11 paf 126: //@{
127: /// @name just stubs, real onces defined below the hierarchy
1.43 paf 128: virtual Value* get_field(const String&) { return 0; }
129: virtual bool replace_field(const String&, Value*) { return false; }
1.21 paf 130: //@}
131:
132: /// @returns new value for current class, used in classes/ & VClass
1.46 paf 133: virtual Value* create_new_value(Pool&) { return 0; }
1.50 ! paf 134:
! 135: protected:
! 136:
! 137: void fill_properties(HashStringValue& acache);
1.2 paf 138:
1.49 paf 139: private:
1.2 paf 140:
1.49 paf 141: void put_method(const String& aname, Method* amethod);
1.2 paf 142: };
143:
1.6 paf 144: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 145: class Temp_method {
146: VStateless_class& fclass;
147: const String& fname;
1.43 paf 148: Method* saved_method;
1.2 paf 149: public:
1.43 paf 150: Temp_method(VStateless_class& aclass, const String& aname, Method* amethod) :
1.2 paf 151: fclass(aclass),
152: fname(aname),
153: saved_method(aclass.get_method(aname)) {
154: fclass.put_method(aname, amethod);
155: }
156: ~Temp_method() {
157: fclass.put_method(fname, saved_method);
158: }
159: };
160:
161: #endif
E-mail: