Annotation of parser3/src/types/pa_vobject.h, revision 1.59

1.6       paf         1: /**    @file
1.7       paf         2:        Parser: @b object class decl.
                      3: 
1.57      moko        4:        Copyright (c) 2001-2012 Art. Lebedev Studio (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.59    ! moko       11: #define IDENT_PA_VOBJECT_H "$Id: pa_vobject.h,v 1.58 2012-05-23 16:26:41 moko Exp $"
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;
1.58      moko       49:        override Value& as_expr_result();
1.39      paf        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.59    ! moko       62:        override const String* get_json_string(Json_options& options);
        !            63: 
1.56      moko       64:        /// VObject default getter & setter support
                     65:        override void enable_default_getter(){ state |= IS_GETTER_ACTIVE; }
                     66:        override void enable_default_setter(){ if(fclass.has_default_setter()) state |= IS_SETTER_ACTIVE; }
                     67:        override void disable_default_getter(){ state &= ~IS_GETTER_ACTIVE; }
                     68:        override void disable_default_setter(){ state &= ~IS_SETTER_ACTIVE; }
                     69:        override bool is_enabled_default_getter(){ return (state & IS_GETTER_ACTIVE) > 0; }
                     70:                         bool is_enabled_default_setter(){ return (state & IS_SETTER_ACTIVE) > 0; }
                     71: 
1.1       paf        72: public: // creation
                     73: 
1.56      moko       74:        VObject(VStateless_class& aclass): fclass(aclass), state(IS_GETTER_ACTIVE){}
1.1       paf        75: 
                     76: private:
                     77: 
1.54      misha      78:        Value* get_scalar_value(char* as_something) const;
1.56      moko       79: };
                     80: 
                     81: ///    Auto-objects used for temporarily disabling setter/getter
                     82: 
                     83: class Temp_disable_default_getter {
                     84:        Value& fwhere;
                     85: public:
                     86:        Temp_disable_default_getter(Value& awhere) : fwhere(awhere) {
                     87:                fwhere.disable_default_getter();
                     88:        }
                     89:        ~Temp_disable_default_getter() { 
                     90:                fwhere.enable_default_getter();
                     91:        }
                     92: };
1.49      misha      93: 
1.56      moko       94: class Temp_disable_default_setter {
                     95:        Value& fwhere;
                     96: public:
                     97:        Temp_disable_default_setter(Value& awhere) : fwhere(awhere) {
                     98:                fwhere.disable_default_setter();
                     99:        }
                    100:        ~Temp_disable_default_setter() { 
                    101:                fwhere.enable_default_setter();
                    102:        }
1.1       paf       103: };
                    104: 
                    105: #endif

E-mail: