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

1.1       paf         1: /*
                      2:        Parser
                      3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.2       paf         4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1       paf         5: 
1.3     ! paf         6:        $Id: pa_vclass.h,v 1.2 2001/03/11 08:16:38 paf Exp $
1.1       paf         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:        }
1.3     ! paf        45:        void add_native_method(
        !            46:                const char *cstr_name,
        !            47:                Native_code_ptr native_code,
        !            48:                int min_numbered_params_count, int max_numbered_params_count);
1.1       paf        49: //     Hash& methods() { return fmethods; }
                     50:        
                     51:        void set_base(VClass& abase) {
                     52:                // remember the guy
                     53:                fbase=&abase;
                     54:        }
                     55:        VClass *base() { return fbase; }
                     56: 
                     57:        bool is_or_derived_from(VClass& vclass) {
                     58:                return 
                     59:                        this==&vclass || 
                     60:                        fbase && fbase->is_or_derived_from(vclass);
                     61:        }
                     62: 
                     63:        Junction *get_junction(VAliased& self, const String& name) {
                     64:                if(Method *method=static_cast<Method *>(fmethods.get(name)))
                     65:                        return NEW Junction(pool(), self, this, method, 0,0,0,0);
                     66:                if(fbase)
                     67:                        return fbase->get_junction(self, name);
                     68:                return 0; 
                     69:        }
                     70: 
                     71:        void set_field(const String& name, Value *value) {
                     72:                value->set_name(name);
                     73:                if(fbase && fbase->replace_field(name, value))
                     74:                        return;
                     75: 
                     76:                ffields.put(name, value);
                     77:        }
                     78: 
                     79: private:
                     80: 
                     81:        Value *get_field(const String& name) {
                     82:                Value *result=static_cast<Value *>(ffields.get(name));
                     83:                if(!result && fbase)
                     84:                        result=fbase->get_field(name);
                     85:                return result;
                     86:        }
                     87:                
                     88:        bool replace_field(const String& name, Value *value) {
                     89:                return 
                     90:                        (fbase && fbase->replace_field(name, value)) ||
                     91:                        ffields.put_replace(name, value);
                     92:        }
                     93:        
                     94: private:
                     95: 
                     96:        VClass *fbase;
                     97:        Hash ffields;
                     98:        Hash fmethods;
                     99: };
                    100: 
                    101: #endif

E-mail: