Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.38

1.6       paf         1: /** @file
                      2:        Parser: stateless class decls.
                      3: 
1.22      paf         4:        Copyright (c) 2001, 2002 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.38    ! paf        11: static const char* IDENT_VSTATELESS_CLASS_H="$Date: 2002/09/17 16:46:26 $";
1.2       paf        12: 
1.13      paf        13: #include "pa_hash.h"
1.2       paf        14: #include "pa_vjunction.h"
                     15: 
1.38    ! paf        16: // defines
        !            17: 
        !            18: #define CLASS_NAME "CLASS"
        !            19: 
        !            20: // forwards
        !            21: 
1.2       paf        22: class Temp_method;
                     23: 
1.6       paf        24: /**
1.30      paf        25:        object' class. stores
                     26:        - base: VClass::base()
                     27:        - methods: VStateless_class::fmethods
1.6       paf        28: 
1.30      paf        29:        @see Method, VStateless_object, Temp_method
1.6       paf        30: */
1.29      paf        31: class VStateless_class : public Value {
1.19      paf        32:        friend class Temp_method;
1.2       paf        33: public: // Value
                     34:        
                     35:        const char *type() const { return "stateless_class"; }
                     36: 
1.5       paf        37:        /// VStateless_class: this
                     38:        VStateless_class *get_class() { return this; }
1.7       paf        39:        
1.38    ! paf        40:        /*overridef*/ Value *get_element(const String& aname, Value *aself, bool looking_up);
1.2       paf        41: 
                     42: public: // usage
                     43: 
1.24      paf        44:        VStateless_class(Pool& apool, 
                     45:                const String *aname=0, 
1.29      paf        46:                VStateless_class *abase=0) : Value(apool), 
1.24      paf        47:                fname(aname),
1.3       paf        48:                fbase(abase),
1.2       paf        49:                fmethods(apool) {
                     50:        }
                     51: 
1.24      paf        52:        const String& name() const { 
                     53:                if(!fname) {
                     54:                        if(fbase)
                     55:                                return fbase->name();
                     56: 
                     57:                        throw Exception("parser.runtime",
                     58:                                0,
                     59:                                "getting name of nameless class");
                     60:                }
                     61: 
                     62:                return *fname; 
                     63:        }
                     64:        const char *name_cstr() const {
                     65:                return this?name().cstr():"<unknown>";
                     66:        }
                     67:        void set_name(const String& aname) {
                     68:                fname=&aname; 
                     69:        }
                     70: 
1.26      paf        71:        Method *get_method(const String& name) const { 
1.2       paf        72:                return static_cast<Method *>(fmethods.get(name)); 
                     73:        }
                     74: 
                     75:        void add_method(const String& name, Method& method) {
                     76:                put_method(name, &method);
                     77:        }
                     78:        void add_native_method(
                     79:                const char *cstr_name,
1.9       paf        80:                Method::Call_type call_type,
1.2       paf        81:                Native_code_ptr native_code,
                     82:                int min_numbered_params_count, int max_numbered_params_count);
                     83:        
1.32      paf        84:        VStateless_class *set_base(VStateless_class *abase) {
                     85:                VStateless_class *result=fbase;
1.2       paf        86:                // remember the guy
1.32      paf        87:                fbase=abase;
                     88:                return result;
1.2       paf        89:        }
1.30      paf        90:        VStateless_class *base_class() { return fbase; }
1.2       paf        91: 
1.30      paf        92:        bool derived_from(VStateless_class& vclass) {
1.2       paf        93:                return 
1.30      paf        94:                        fbase==&vclass || 
                     95:                        fbase && fbase->derived_from(vclass);
1.31      paf        96:        }
                     97: 
1.11      paf        98:        //@{
                     99:        /// @name just stubs, real onces defined below the hierarchy
1.18      parser    100:        virtual Value *get_field(const String& ) { return 0; }
                    101:        virtual bool replace_field(const String& , Value *) { return false; }
1.21      paf       102:        //@}
                    103: 
                    104:        /// @returns new value for current class, used in classes/ & VClass
1.18      parser    105:        virtual Value *create_new_value(Pool& ) { return 0; }
1.2       paf       106: 
                    107: private: // Temp_method
                    108: 
1.8       paf       109:        void put_method(const String& aname, Method *amethod) {
                    110:                fmethods.put(aname, amethod); 
                    111:        }
1.2       paf       112:        
                    113: private:
                    114: 
1.24      paf       115:        const String *fname;
1.2       paf       116:        Hash fmethods;
                    117: 
                    118: protected:
                    119: 
                    120:        VStateless_class *fbase;
                    121: 
                    122: };
                    123: 
1.6       paf       124: ///    Auto-object used for temporarily substituting/removing class method
1.2       paf       125: class Temp_method {
                    126:        VStateless_class& fclass;
                    127:        const String& fname;
                    128:        Method *saved_method;
                    129: public:
                    130:        Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) : 
                    131:                fclass(aclass),
                    132:                fname(aname),
                    133:                saved_method(aclass.get_method(aname)) {
                    134:                fclass.put_method(aname, amethod);
                    135:        }
                    136:        ~Temp_method() { 
                    137:                fclass.put_method(fname, saved_method);
                    138:        }
1.32      paf       139: };
                    140: 
                    141: ///    Auto-object used for temporarily substituting/removing class base
                    142: class Temp_base {
                    143:        VStateless_class& fclass;
                    144:        VStateless_class *fbase;
                    145: public:
                    146:        Temp_base(VStateless_class& aclass, VStateless_class *abase) : fclass(aclass), fbase(aclass.set_base(abase)) {}
                    147:        ~Temp_base() { fclass.set_base(fbase); }
                    148: 
1.2       paf       149: };
                    150: 
                    151: #endif

E-mail: