Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.71
1.6 paf 1: /** @file
2: Parser: stateless class decls.
3:
1.62 misha 4: Copyright (c) 2001-2009 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.71 ! moko 11: static const char * const IDENT_VSTATELESS_CLASS_H="$Date: 2010-07-05 01:38:34 $";
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"
1.54 misha 23: #define CLASS_NAMETEXT "CLASS_NAME"
1.63 misha 24: extern const String class_name, class_nametext;
1.38 paf 25:
26: // forwards
27:
1.43 paf 28: class VStateless_class;
1.59 misha 29: typedef Array<VStateless_class*> ArrayClass;
1.66 misha 30: typedef HashString<Property *> HashStringProperty;
31: typedef HashString<Method *> HashStringMethod;
1.43 paf 32:
1.2 paf 33: class Temp_method;
34:
1.6 paf 35: /**
1.30 paf 36: object' class. stores
37: - base: VClass::base()
38: - methods: VStateless_class::fmethods
1.6 paf 39:
1.30 paf 40: @see Method, VStateless_object, Temp_method
1.6 paf 41: */
1.39 paf 42: class VStateless_class: public Value {
1.19 paf 43: friend class Temp_method;
1.43 paf 44:
45: const String* fname;
46: mutable const char* fname_cstr;
1.66 misha 47: HashStringMethod fmethods;
1.43 paf 48:
49: bool flocked;
1.57 misha 50: bool fall_vars_local;
1.61 misha 51: bool fpartial;
1.70 misha 52: Method::Call_type fcall_type;
1.43 paf 53:
54: protected:
55:
56: VStateless_class* fbase;
1.68 misha 57: /// all derived classes, recursively
1.66 misha 58: ArrayClass fderived;
59:
1.60 misha 60: Method* fscalar;
1.58 misha 61: Method* fdefault_getter;
1.71 ! moko 62: Method* fdefault_setter;
1.43 paf 63:
1.2 paf 64: public: // Value
65:
1.43 paf 66: const char* type() const { return "stateless_class"; }
1.2 paf 67:
1.5 paf 68: /// VStateless_class: this
1.69 misha 69: override VStateless_class* get_class() { return this; }
1.41 paf 70: /// VStateless_class: fbase
1.69 misha 71: override VStateless_class* base() { return fbase; }
1.66 misha 72:
73: override Value* get_element(const String& aname) { return get_element(*this, aname); }
74: /// get_element with aself for VObject junctions
75: virtual Value* get_element(Value& aself, const String& aname);
76:
77: override const VJunction* put_element(const String& aname, Value* avalue, bool areplace) { return put_element(*this, aname, avalue, areplace); }
78: /// put_element with aself for VObject junctions
79: virtual const VJunction* put_element(Value& /*aself*/, const String& aname, Value* avalue, bool areplace) { return Value::put_element(aname, avalue, areplace); }
80:
1.55 misha 81: override Value& as_expr_result(bool /*return_string_as_is=false*/);
1.60 misha 82:
1.66 misha 83: Value* get_scalar(Value& aself);
84: void set_scalar(Method* amethod);
1.2 paf 85:
1.66 misha 86: Value* get_default_getter(Value& aself, const String& aname);
87: void set_default_getter(Method* amethod);
1.71 ! moko 88: bool has_default_getter();
! 89:
! 90: VJunction* get_default_setter(Value& aself, const String& aname);
! 91: void set_default_setter(Method* amethod);
! 92: bool has_default_setter();
1.60 misha 93:
1.66 misha 94: void add_derived(VStateless_class &aclass);
1.61 misha 95:
1.2 paf 96: public: // usage
97:
1.43 paf 98: VStateless_class(
99: const String* aname=0,
100: VStateless_class* abase=0):
1.24 paf 101: fname(aname),
1.43 paf 102: flocked(false),
1.66 misha 103: fbase(0),
104: fderived(0),
1.58 misha 105: fall_vars_local(false),
1.61 misha 106: fpartial(false),
1.60 misha 107: fscalar(0),
1.70 misha 108: fdefault_getter(0),
1.71 ! moko 109: fdefault_setter(0),
1.70 misha 110: fcall_type(Method::CT_ANY)
1.61 misha 111: {
1.66 misha 112: set_base(abase);
1.2 paf 113: }
114:
1.43 paf 115: void lock() { flocked=true; }
116:
1.24 paf 117: const String& name() const {
118: if(!fname) {
119: if(fbase)
120: return fbase->name();
121:
1.56 misha 122: throw Exception(PARSER_RUNTIME,
1.24 paf 123: 0,
124: "getting name of nameless class");
125: }
126: return *fname;
127: }
1.66 misha 128:
1.43 paf 129: const char* name_cstr() const{
1.66 misha 130: if(!fname_cstr) // remembering last calculated, and can't reassign 'fname_cstr'!
131: fname_cstr=name().cstr();
132: return fname_cstr;
1.24 paf 133: }
1.61 misha 134:
1.24 paf 135: void set_name(const String& aname) {
136: fname=&aname;
1.66 misha 137: fname_cstr=0;
1.24 paf 138: }
139:
1.43 paf 140: Method* get_method(const String& aname) const {
141: return fmethods.get(aname);
1.2 paf 142: }
143:
1.66 misha 144: HashStringMethod get_methods(){
1.65 misha 145: return fmethods;
146: }
147:
1.61 misha 148: bool is_vars_local(){
149: return fall_vars_local;
150: }
151:
152: void set_all_vars_local(){
1.57 misha 153: fall_vars_local=true;
154: }
155:
1.61 misha 156: bool is_partial(){
157: return fpartial;
158: }
159:
160: void set_partial(){
161: fpartial=true;
1.57 misha 162: }
163:
1.70 misha 164: Method::Call_type get_methods_call_type(){
165: return fcall_type;
166: }
167:
168: void set_methods_call_type(Method::Call_type call_type){
169: if(fcall_type!=Method::CT_ANY)
170: throw Exception(PARSER_RUNTIME,
171: 0,
172: "You can specify call type option in a class only once"
173: );
174: fcall_type=call_type;
175: }
176:
1.2 paf 177: void add_native_method(
1.43 paf 178: const char* cstr_name,
1.9 paf 179: Method::Call_type call_type,
1.43 paf 180: NativeCodePtr native_code,
1.62 misha 181: int min_numbered_params_count,
182: int max_numbered_params_count,
183: Method::Call_optimization call_optimization=Method::CO_WITHOUT_WCONTEXT);
1.66 misha 184:
1.68 misha 185: void set_method(const String& aname, Method* amethod);
186:
1.66 misha 187: /// overrided in VClass
1.68 misha 188: virtual void real_set_method(const String& aname, Method* amethod);
1.66 misha 189: virtual HashStringProperty* get_properties(){ return 0; };
190: virtual void set_base(VStateless_class* abase);
1.2 paf 191:
1.43 paf 192: VStateless_class* base_class() { return fbase; }
1.2 paf 193:
1.66 misha 194: bool derived_from(VStateless_class& vclass){
195: return fbase==&vclass || fbase && fbase->derived_from(vclass);
1.31 paf 196: }
197:
1.21 paf 198: /// @returns new value for current class, used in classes/ & VClass
1.66 misha 199: virtual Value* create_new_value(Pool&) { return 0; }
1.2 paf 200: };
201:
1.6 paf 202: /// Auto-object used for temporarily substituting/removing class method
1.2 paf 203: class Temp_method {
204: VStateless_class& fclass;
205: const String& fname;
1.43 paf 206: Method* saved_method;
1.2 paf 207: public:
1.43 paf 208: Temp_method(VStateless_class& aclass, const String& aname, Method* amethod) :
1.2 paf 209: fclass(aclass),
210: fname(aname),
211: saved_method(aclass.get_method(aname)) {
1.67 misha 212: fclass.set_method(aname, amethod);
1.2 paf 213: }
214: ~Temp_method() {
1.67 misha 215: fclass.set_method(fname, saved_method);
1.2 paf 216: }
217: };
218:
219: #endif
E-mail: