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

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.40    ! paf        11: static const char* IDENT_VSTATELESS_CLASS_H="$Date: 2002/10/14 15:22:42 $";
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
                     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: 
1.40    ! paf        75:        void add_method(const String& name, Method& method);
        !            76:        
1.2       paf        77:        void add_native_method(
                     78:                const char *cstr_name,
1.9       paf        79:                Method::Call_type call_type,
1.2       paf        80:                Native_code_ptr native_code,
                     81:                int min_numbered_params_count, int max_numbered_params_count);
                     82:        
1.32      paf        83:        VStateless_class *set_base(VStateless_class *abase) {
                     84:                VStateless_class *result=fbase;
1.2       paf        85:                // remember the guy
1.32      paf        86:                fbase=abase;
                     87:                return result;
1.2       paf        88:        }
1.30      paf        89:        VStateless_class *base_class() { return fbase; }
1.2       paf        90: 
1.30      paf        91:        bool derived_from(VStateless_class& vclass) {
1.2       paf        92:                return 
1.30      paf        93:                        fbase==&vclass || 
                     94:                        fbase && fbase->derived_from(vclass);
1.31      paf        95:        }
                     96: 
1.11      paf        97:        //@{
                     98:        /// @name just stubs, real onces defined below the hierarchy
1.18      parser     99:        virtual Value *get_field(const String& ) { return 0; }
                    100:        virtual bool replace_field(const String& , Value *) { return false; }
1.21      paf       101:        //@}
                    102: 
                    103:        /// @returns new value for current class, used in classes/ & VClass
1.18      parser    104:        virtual Value *create_new_value(Pool& ) { return 0; }
1.2       paf       105: 
                    106: private: // Temp_method
                    107: 
1.8       paf       108:        void put_method(const String& aname, Method *amethod) {
                    109:                fmethods.put(aname, amethod); 
                    110:        }
1.2       paf       111:        
                    112: private:
                    113: 
1.24      paf       114:        const String *fname;
1.2       paf       115:        Hash fmethods;
                    116: 
                    117: protected:
                    118: 
                    119:        VStateless_class *fbase;
                    120: 
                    121: };
                    122: 
1.6       paf       123: ///    Auto-object used for temporarily substituting/removing class method
1.2       paf       124: class Temp_method {
                    125:        VStateless_class& fclass;
                    126:        const String& fname;
                    127:        Method *saved_method;
                    128: public:
                    129:        Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) : 
                    130:                fclass(aclass),
                    131:                fname(aname),
                    132:                saved_method(aclass.get_method(aname)) {
                    133:                fclass.put_method(aname, amethod);
                    134:        }
                    135:        ~Temp_method() { 
                    136:                fclass.put_method(fname, saved_method);
                    137:        }
1.32      paf       138: };
                    139: 
                    140: ///    Auto-object used for temporarily substituting/removing class base
                    141: class Temp_base {
                    142:        VStateless_class& fclass;
                    143:        VStateless_class *fbase;
                    144: public:
                    145:        Temp_base(VStateless_class& aclass, VStateless_class *abase) : fclass(aclass), fbase(aclass.set_base(abase)) {}
                    146:        ~Temp_base() { fclass.set_base(fbase); }
                    147: 
1.2       paf       148: };
                    149: 
                    150: #endif

E-mail: