Annotation of parser3/src/include/pa_vclass.h, revision 1.29

1.1       paf         1: /*
1.29    ! paf         2:        Parser
        !             3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
        !             4:        Author: Alexander Petrosyan <paf@design.ru>
        !             5: 
        !             6:        $Id: pa_string.C,v 1.35 2001/03/10 12:12:51 paf Exp $
1.1       paf         7: */
                      8: 
                      9: #ifndef PA_VCLASS_H
                     10: #define PA_VCLASS_H
                     11: 
1.19      paf        12: #include "pa_valiased.h"
1.6       paf        13: #include "pa_vhash.h"
1.8       paf        14: #include "pa_vjunction.h"
1.1       paf        15: 
1.17      paf        16: #define CLASS_NAME "CLASS"
                     17: #define BASE_NAME "BASE"
                     18: 
1.19      paf        19: class VClass : public VAliased {
1.1       paf        20: public: // Value
                     21:        
                     22:        // all: for error reporting after fail(), etc
1.20      paf        23:        const char *type() const { return "class"; }
1.23      paf        24: 
1.1       paf        25:        // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.26      paf        26:        Value *get_element(const String& aname);
1.1       paf        27: 
                     28:        // object_class, operator_class: (field)=value - static values only
1.26      paf        29:        void put_element(const String& name, Value *value);
1.1       paf        30: 
                     31:        // object_class, object_instance: object_class
1.17      paf        32:        VClass *get_class() { return this; }
1.1       paf        33: 
                     34: public: // usage
                     35: 
1.19      paf        36:        VClass(Pool& apool) : VAliased(apool, *this), 
1.23      paf        37:                fbase(0),
1.25      paf        38:                ffields(apool),
                     39:                fmethods(apool) {
1.1       paf        40:        }
                     41: 
                     42:        void add_method(const String& name, Method& method) {
1.15      paf        43:                fmethods.put(name, &method);
1.1       paf        44:        }
1.19      paf        45: //     Hash& methods() { return fmethods; }
1.15      paf        46:        
1.17      paf        47:        void set_base(VClass& abase) {
                     48:                // remember the guy
                     49:                fbase=&abase;
1.15      paf        50:        }
1.17      paf        51:        VClass *base() { return fbase; }
1.18      paf        52: 
                     53:        bool is_or_derived_from(VClass& vclass) {
                     54:                return 
                     55:                        this==&vclass || 
                     56:                        fbase && fbase->is_or_derived_from(vclass);
1.19      paf        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; 
1.18      paf        65:        }
1.11      paf        66: 
1.27      paf        67:        void set_field(const String& name, Value *value) {
1.28      paf        68:                value->set_name(name);
1.27      paf        69:                if(fbase && fbase->replace_field(name, value))
                     70:                        return;
                     71: 
                     72:                ffields.put(name, value);
                     73:        }
                     74: 
1.17      paf        75: private:
1.11      paf        76: 
1.17      paf        77:        Value *get_field(const String& name) {
1.23      paf        78:                Value *result=static_cast<Value *>(ffields.get(name));
1.17      paf        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)) ||
1.23      paf        87:                        ffields.put_replace(name, value);
1.17      paf        88:        }
                     89:        
1.1       paf        90: private:
                     91: 
1.17      paf        92:        VClass *fbase;
1.25      paf        93:        Hash ffields;
                     94:        Hash fmethods;
1.1       paf        95: };
                     96: 
                     97: #endif

E-mail: