Annotation of parser3/src/types/pa_vobject.h, revision 1.56
1.6 paf 1: /** @file
1.7 paf 2: Parser: @b object class decl.
3:
1.50 misha 4: Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com)
1.16 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
8: #ifndef PA_VOBJECT_H
9: #define PA_VOBJECT_H
10:
1.56 ! moko 11: static const char * const IDENT_VOBJECT_H="$Date: 2009-09-18 09:16:07 $";
1.39 paf 12:
13: // includes
1.19 paf 14:
1.1 paf 15: #include "pa_vjunction.h"
16: #include "pa_vclass.h"
1.4 paf 17: #include "pa_vstateless_object.h"
1.39 paf 18: #include "pa_vfile.h"
1.6 paf 19:
1.23 paf 20: // defines
21:
22: #define BASE_NAME "BASE"
23:
1.26 paf 24: /** parser class instance, stores
25: - class VObject::fclass;
26: - fields VObject::ffields (dynamic, not static, which are stored in class).
1.6 paf 27: */
1.53 misha 28: class VObject: public Value {
1.39 paf 29:
30: VStateless_class& fclass;
1.53 misha 31: HashStringValue ffields;
1.39 paf 32:
1.56 ! moko 33: enum State {
! 34: IS_GETTER_ACTIVE = 0x01,
! 35: IS_SETTER_ACTIVE = 0x02
! 36: };
! 37:
! 38: int state; // default setter & getter state
! 39:
1.1 paf 40: public: // Value
41:
1.39 paf 42: const char* type() const { return fclass.name_cstr(); }
1.53 misha 43: override Value* as(const char* atype);
1.12 parser 44:
1.25 paf 45: /// VObject: fclass
1.39 paf 46: override VStateless_class *get_class() { return &fclass; }
47:
48: override bool is_defined() const;
49: override Value& as_expr_result(bool);
50: override int as_int() const;
1.49 misha 51: override double as_double() const;
1.39 paf 52: override bool as_bool() const;
1.52 misha 53: override VFile* as_vfile(String::Language lang, const Request_charsets *charsets=0);
1.33 paf 54:
1.39 paf 55: override HashStringValue* get_hash();
56: override Table *get_table();
1.55 misha 57: override HashStringValue* get_fields() { return &ffields; }
1.33 paf 58:
1.53 misha 59: override Value* get_element(const String& aname);
60: override const VJunction* put_element(const String& name, Value* value, bool replace);
1.24 paf 61:
1.56 ! moko 62: /// VObject default getter & setter support
! 63: override void enable_default_getter(){ state |= IS_GETTER_ACTIVE; }
! 64: override void enable_default_setter(){ if(fclass.has_default_setter()) state |= IS_SETTER_ACTIVE; }
! 65: override void disable_default_getter(){ state &= ~IS_GETTER_ACTIVE; }
! 66: override void disable_default_setter(){ state &= ~IS_SETTER_ACTIVE; }
! 67: override bool is_enabled_default_getter(){ return (state & IS_GETTER_ACTIVE) > 0; }
! 68: bool is_enabled_default_setter(){ return (state & IS_SETTER_ACTIVE) > 0; }
! 69:
1.1 paf 70: public: // creation
71:
1.56 ! moko 72: VObject(VStateless_class& aclass): fclass(aclass), state(IS_GETTER_ACTIVE){}
1.1 paf 73:
74: private:
75:
1.54 misha 76: Value* get_scalar_value(char* as_something) const;
1.56 ! moko 77: };
! 78:
! 79: /// Auto-objects used for temporarily disabling setter/getter
! 80:
! 81: class Temp_disable_default_getter {
! 82: Value& fwhere;
! 83: public:
! 84: Temp_disable_default_getter(Value& awhere) : fwhere(awhere) {
! 85: fwhere.disable_default_getter();
! 86: }
! 87: ~Temp_disable_default_getter() {
! 88: fwhere.enable_default_getter();
! 89: }
! 90: };
1.49 misha 91:
1.56 ! moko 92: class Temp_disable_default_setter {
! 93: Value& fwhere;
! 94: public:
! 95: Temp_disable_default_setter(Value& awhere) : fwhere(awhere) {
! 96: fwhere.disable_default_setter();
! 97: }
! 98: ~Temp_disable_default_setter() {
! 99: fwhere.enable_default_setter();
! 100: }
1.1 paf 101: };
102:
103: #endif
E-mail: