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

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.41    ! paf        11: static const char* IDENT_VSTATELESS_CLASS_H="$Date: 2002/10/31 13:49:58 $";
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.39      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
1.41    ! paf        38:        /*override*/ VStateless_class *get_class() { return this; }
        !            39:        /// VStateless_class: fbase
        !            40:        /*override*/ Value *base() { return fbase; }
        !            41:        /*override*/ Value *get_element(const String& aname, Value& aself, bool looking_up);
1.2       paf        42: 
                     43: public: // usage
                     44: 
1.24      paf        45:        VStateless_class(Pool& apool, 
                     46:                const String *aname=0, 
1.29      paf        47:                VStateless_class *abase=0) : Value(apool), 
1.24      paf        48:                fname(aname),
1.41    ! paf        49:         fbase(abase),
1.2       paf        50:                fmethods(apool) {
                     51:        }
                     52: 
1.24      paf        53:        const String& name() const { 
                     54:                if(!fname) {
                     55:                        if(fbase)
                     56:                                return fbase->name();
                     57: 
                     58:                        throw Exception("parser.runtime",
                     59:                                0,
                     60:                                "getting name of nameless class");
                     61:                }
                     62: 
                     63:                return *fname; 
                     64:        }
                     65:        const char *name_cstr() const {
                     66:                return this?name().cstr():"<unknown>";
                     67:        }
                     68:        void set_name(const String& aname) {
                     69:                fname=&aname; 
                     70:        }
                     71: 
1.26      paf        72:        Method *get_method(const String& name) const { 
1.2       paf        73:                return static_cast<Method *>(fmethods.get(name)); 
                     74:        }
                     75: 
1.40      paf        76:        void add_method(const String& name, Method& method);
                     77:        
1.2       paf        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:        }
                    139: };
                    140: 
                    141: #endif

E-mail: