Annotation of parser3/src/types/pa_vclass.h, revision 1.77

1.13      paf         1: /**    @file
1.14      paf         2:        Parser: @b class parser class decl.
1.13      paf         3: 
1.77    ! moko        4:        Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
1.75      moko        5:        Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_VCLASS_H
                      9: #define PA_VCLASS_H
1.26      paf        10: 
1.77    ! moko       11: #define IDENT_PA_VCLASS_H "$Id: pa_vclass.h,v 1.76 2024/09/13 04:01:23 moko Exp $"
1.67      moko       12: 
                     13: #define OBJECT_PROTOTYPE
1.74      moko       14: #define CLASS_GETTER_UNPROTECTED
1.40      paf        15: 
                     16: // includes
1.1       paf        17: 
1.8       paf        18: #include "pa_vstateless_class.h"
1.1       paf        19: #include "pa_vjunction.h"
                     20: 
1.13      paf        21: /**    stores 
1.55      misha      22: - static fields, getters & setters: VClass::ffields
1.13      paf        23: */
1.40      paf        24: class VClass: public VStateless_class {
1.1       paf        25: public: // Value
                     26:        
1.66      moko       27:        override const char* type() const {
                     28:                if(!ftype)
                     29:                        throw Exception(PARSER_RUNTIME, 0, "getting type of nameless class");
                     30:                return ftype;
                     31:        }
                     32: 
1.20      parser     33:        /// VClass: true
1.40      paf        34:        override bool as_bool() const { return true; }
1.76      moko       35:        override bool is(const char* atype);
1.1       paf        36: 
1.55      misha      37:        override Value* get_element(Value& aself, const String& aname);
1.61      moko       38:        override const VJunction* put_element(Value& self, const String& name, Value* value);
1.72      moko       39: 
                     40:        /// indicator value meaning that put_element_replace_only overwritten static field in non-prototype mode
                     41:        #define PUT_ELEMENT_REPLACED_FIELD reinterpret_cast<const VJunction*>(1)
                     42: 
1.61      moko       43:        // for VObject::put_element
                     44:        const VJunction* put_element_replace_only(Value& self, const String& name, Value* value);
                     45: 
1.63      misha      46:        override const String* get_json_string(Json_options& options);
                     47: 
1.55      misha      48:        override Value* create_new_value(Pool&);
1.8       paf        49: 
1.60      misha      50:        override HashStringValue *get_hash();
                     51:        override HashStringValue* get_fields() { return get_hash(); };
1.58      misha      52: 
1.67      moko       53: public:
                     54: 
                     55: #ifdef OBJECT_PROTOTYPE
                     56:        static bool prototype;
                     57: #endif
1.74      moko       58: #ifdef CLASS_GETTER_UNPROTECTED
                     59:        static bool getter_protected;
                     60: #endif
1.67      moko       61: 
1.55      misha      62:        // VStateless_class
1.57      misha      63:        override void real_set_method(const String& aname, Method* amethod);
1.55      misha      64:        override HashStringProperty* get_properties(){ return &ffields; };
                     65:        override void set_base(VStateless_class* abase);
1.47      paf        66: 
1.62      moko       67:        /// VClass default getter & setter support
                     68:        override void enable_default_getter(){ state |= IS_GETTER_ACTIVE; }
                     69:        override void enable_default_setter(){ if(has_default_setter()) state |= IS_SETTER_ACTIVE; }
                     70:        override void disable_default_getter(){ state &= ~IS_GETTER_ACTIVE; }
                     71:        override void disable_default_setter(){ state &= ~IS_SETTER_ACTIVE; }
                     72:        override bool is_enabled_default_getter(){ return (state & IS_GETTER_ACTIVE) > 0; }
                     73:        override bool is_enabled_default_setter(){ return (state & IS_SETTER_ACTIVE) > 0; }
                     74: 
1.47      paf        75: private:
                     76: 
1.66      moko       77:        const char* ftype;
1.69      moko       78:        const String& ffilespec;
1.66      moko       79: 
1.62      moko       80:        enum State {
                     81:                IS_GETTER_ACTIVE = 0x01,
                     82:                IS_SETTER_ACTIVE = 0x02
                     83:        };
                     84: 
                     85:        int state; // default setter & getter state
                     86: 
                     87:        HashStringProperty ffields;
                     88: 
1.55      misha      89:        Property& get_property(const String& aname);
1.4       paf        90: 
1.62      moko       91: public:
1.1       paf        92: 
1.69      moko       93:        VClass(const char* atype, const String* afilespec=0) : ftype(atype), ffilespec(afilespec ? *afilespec : String::Empty), state(IS_GETTER_ACTIVE){}
1.68      moko       94: 
1.69      moko       95:        const String& get_filespec(){ return ffilespec; }
1.25      paf        96: 
1.1       paf        97: };
                     98: 
                     99: #endif

E-mail: