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

1.2     ! paf         1: /*
        !             2:        Parser
        !             3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
        !             4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
        !             5: 
        !             6:        $Id: pa_vstateless_class.h,v 1.1.2.1 2001/03/13 13:40:02 paf Exp $
        !             7: */
        !             8: 
        !             9: #ifndef PA_VSTATELESS_CLASS_H
        !            10: #define PA_VSTATELESS_CLASS_H
        !            11: 
        !            12: #include "pa_valiased.h"
        !            13: #include "pa_vhash.h"
        !            14: #include "pa_vjunction.h"
        !            15: 
        !            16: #define CLASS_NAME "class"
        !            17: #define BASE_NAME "base"
        !            18: 
        !            19: class Temp_method;
        !            20: 
        !            21: class VStateless_class : public VAliased {
        !            22:        friend Temp_method;
        !            23: public: // Value
        !            24:        
        !            25:        // all: for error reporting after fail(), etc
        !            26:        const char *type() const { return "stateless_class"; }
        !            27: 
        !            28:        // stateless_class: $NAME,$CLASS,$BASE,$method
        !            29:        Value *get_element(const String& aname);
        !            30: 
        !            31:        // stateless_class: object_class
        !            32:        VStateless_class *get_class() { return this; }
        !            33: 
        !            34: public: // usage
        !            35: 
        !            36:        VStateless_class(Pool& apool) : VAliased(apool, *this), 
        !            37:                fbase(0),
        !            38:                read_only(false),
        !            39:                fmethods(apool) {
        !            40:        }
        !            41: 
        !            42:        Method *get_method(const String& name) { 
        !            43:                return static_cast<Method *>(fmethods.get(name)); 
        !            44:        }
        !            45: 
        !            46:        // make class read-only
        !            47:        //      this blocks put_method  // which could be done with ^process
        !            48:        void freeze() { read_only=true; }
        !            49: 
        !            50:        void add_method(const String& name, Method& method) {
        !            51:                put_method(name, &method);
        !            52:        }
        !            53:        void add_native_method(
        !            54:                const char *cstr_name,
        !            55:                Native_code_ptr native_code,
        !            56:                int min_numbered_params_count, int max_numbered_params_count);
        !            57:        
        !            58:        void set_base(VStateless_class& abase) {
        !            59:                // remember the guy
        !            60:                fbase=&abase;
        !            61:        }
        !            62:        VStateless_class *base() { return fbase; }
        !            63: 
        !            64:        bool is_or_derived_from(VStateless_class& vclass) {
        !            65:                return 
        !            66:                        this==&vclass || 
        !            67:                        fbase && fbase->is_or_derived_from(vclass);
        !            68:        }
        !            69: 
        !            70:        Junction *get_junction(VAliased& self, const String& name) {
        !            71:                if(Method *method=static_cast<Method *>(fmethods.get(name)))
        !            72:                        return NEW Junction(pool(), self, this, method, 0,0,0,0);
        !            73:                if(fbase)
        !            74:                        return fbase->get_junction(self, name);
        !            75:                return 0; 
        !            76:        }
        !            77: 
        !            78:        // just stubs, real onces defined below the hierarchy, in 
        !            79:        virtual Value *get_field(const String& name) { return 0; }
        !            80:        virtual bool replace_field(const String& name, Value *value) { return false; }
        !            81: 
        !            82: private: // Temp_method
        !            83: 
        !            84:        void put_method(const String& aname, Method *amethod);
        !            85:        
        !            86: private:
        !            87: 
        !            88:        Hash fmethods;
        !            89: 
        !            90: protected:
        !            91: 
        !            92:        VStateless_class *fbase;
        !            93:        bool read_only;
        !            94: 
        !            95: };
        !            96: 
        !            97: class Temp_method {
        !            98:        VStateless_class& fclass;
        !            99:        const String& fname;
        !           100:        Method *saved_method;
        !           101: public:
        !           102:        Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) : 
        !           103:                fclass(aclass),
        !           104:                fname(aname),
        !           105:                saved_method(aclass.get_method(aname)) {
        !           106:                fclass.put_method(aname, amethod);
        !           107:        }
        !           108:        ~Temp_method() { 
        !           109:                fclass.put_method(fname, saved_method);
        !           110:        }
        !           111: };
        !           112: 
        !           113: #endif

E-mail: