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

1.1     ! paf         1: /*
        !             2:        Parser
        !             3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
        !             4:        Author: Alexander Petrosyan <paf@design.ru>
        !             5: 
        !             6:        $Id: pa_vclass.h,v 1.29 2001/03/10 16:34:36 paf Exp $
        !             7: */
        !             8: 
        !             9: #ifndef PA_VCLASS_H
        !            10: #define PA_VCLASS_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 VClass : public VAliased {
        !            20: public: // Value
        !            21:        
        !            22:        // all: for error reporting after fail(), etc
        !            23:        const char *type() const { return "class"; }
        !            24: 
        !            25:        // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
        !            26:        Value *get_element(const String& aname);
        !            27: 
        !            28:        // object_class, operator_class: (field)=value - static values only
        !            29:        void put_element(const String& name, Value *value);
        !            30: 
        !            31:        // object_class, object_instance: object_class
        !            32:        VClass *get_class() { return this; }
        !            33: 
        !            34: public: // usage
        !            35: 
        !            36:        VClass(Pool& apool) : VAliased(apool, *this), 
        !            37:                fbase(0),
        !            38:                ffields(apool),
        !            39:                fmethods(apool) {
        !            40:        }
        !            41: 
        !            42:        void add_method(const String& name, Method& method) {
        !            43:                fmethods.put(name, &method);
        !            44:        }
        !            45: //     Hash& methods() { return fmethods; }
        !            46:        
        !            47:        void set_base(VClass& abase) {
        !            48:                // remember the guy
        !            49:                fbase=&abase;
        !            50:        }
        !            51:        VClass *base() { return fbase; }
        !            52: 
        !            53:        bool is_or_derived_from(VClass& vclass) {
        !            54:                return 
        !            55:                        this==&vclass || 
        !            56:                        fbase && fbase->is_or_derived_from(vclass);
        !            57:        }
        !            58: 
        !            59:        Junction *get_junction(VAliased& self, const String& name) {
        !            60:                if(Method *method=static_cast<Method *>(fmethods.get(name)))
        !            61:                        return NEW Junction(pool(), self, this, method, 0,0,0,0);
        !            62:                if(fbase)
        !            63:                        return fbase->get_junction(self, name);
        !            64:                return 0; 
        !            65:        }
        !            66: 
        !            67:        void set_field(const String& name, Value *value) {
        !            68:                value->set_name(name);
        !            69:                if(fbase && fbase->replace_field(name, value))
        !            70:                        return;
        !            71: 
        !            72:                ffields.put(name, value);
        !            73:        }
        !            74: 
        !            75: private:
        !            76: 
        !            77:        Value *get_field(const String& name) {
        !            78:                Value *result=static_cast<Value *>(ffields.get(name));
        !            79:                if(!result && fbase)
        !            80:                        result=fbase->get_field(name);
        !            81:                return result;
        !            82:        }
        !            83:                
        !            84:        bool replace_field(const String& name, Value *value) {
        !            85:                return 
        !            86:                        (fbase && fbase->replace_field(name, value)) ||
        !            87:                        ffields.put_replace(name, value);
        !            88:        }
        !            89:        
        !            90: private:
        !            91: 
        !            92:        VClass *fbase;
        !            93:        Hash ffields;
        !            94:        Hash fmethods;
        !            95: };
        !            96: 
        !            97: #endif

E-mail: