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

1.6       paf         1: /** @file
                      2:        Parser: stateless class decls.
                      3: 
1.2       paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
                      5:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
                      6: 
1.19    ! paf         7:        $Id: pa_vstateless_class.h,v 1.18 2001/10/19 12:43:30 parser Exp $
1.2       paf         8: */
                      9: 
                     10: #ifndef PA_VSTATELESS_CLASS_H
                     11: #define PA_VSTATELESS_CLASS_H
                     12: 
                     13: #include "pa_valiased.h"
1.13      paf        14: #include "pa_hash.h"
1.2       paf        15: #include "pa_vjunction.h"
                     16: 
                     17: class Temp_method;
                     18: 
1.6       paf        19: /**
                     20:        object' class. 
                     21:        
1.10      paf        22:        basically collection of methods [VStateless_class::fmethods, Method]
1.6       paf        23: 
                     24:        @see VStateless_object, Temp_method
                     25: */
1.2       paf        26: class VStateless_class : public VAliased {
1.19    ! paf        27:        friend class Temp_method;
1.2       paf        28: public: // Value
                     29:        
                     30:        const char *type() const { return "stateless_class"; }
                     31: 
1.5       paf        32:        /// VStateless_class: this
                     33:        VStateless_class *get_class() { return this; }
1.7       paf        34:        
                     35:        /// VStateless_class: +$method
                     36:        Value *get_element(const String& aname) {
1.16      parser     37:                // $CLASS
1.7       paf        38:                if(Value *result=VAliased::get_element(aname))
                     39:                        return result;
1.14      paf        40: 
1.7       paf        41:                // $method=junction(self+class+method)
                     42:                if(Junction *junction=get_junction(*this, aname))
1.15      parser     43:                        return new(junction->pool()) VJunction(*junction);
1.7       paf        44:                
                     45:                return 0;
                     46:        }
1.2       paf        47: 
                     48: public: // usage
                     49: 
1.3       paf        50:        VStateless_class(Pool& apool, VStateless_class *abase=0) : VAliased(apool, *this), 
                     51:                fbase(abase),
1.2       paf        52:                fmethods(apool) {
                     53:        }
                     54: 
                     55:        Method *get_method(const String& name) { 
                     56:                return static_cast<Method *>(fmethods.get(name)); 
                     57:        }
                     58: 
                     59:        void add_method(const String& name, Method& method) {
                     60:                put_method(name, &method);
                     61:        }
                     62:        void add_native_method(
                     63:                const char *cstr_name,
1.9       paf        64:                Method::Call_type call_type,
1.2       paf        65:                Native_code_ptr native_code,
                     66:                int min_numbered_params_count, int max_numbered_params_count);
                     67:        
                     68:        void set_base(VStateless_class& abase) {
                     69:                // remember the guy
                     70:                fbase=&abase;
                     71:        }
                     72:        VStateless_class *base() { return fbase; }
                     73: 
                     74:        bool is_or_derived_from(VStateless_class& vclass) {
                     75:                return 
                     76:                        this==&vclass || 
                     77:                        fbase && fbase->is_or_derived_from(vclass);
                     78:        }
                     79: 
                     80:        Junction *get_junction(VAliased& self, const String& name) {
                     81:                if(Method *method=static_cast<Method *>(fmethods.get(name)))
1.15      parser     82:                        return 
                     83:                                new(name.pool()) Junction(name.pool(), self, this, method, 0,0,0,0);
1.2       paf        84:                if(fbase)
                     85:                        return fbase->get_junction(self, name);
                     86:                return 0; 
                     87:        }
                     88: 
1.11      paf        89:        //@{
                     90:        /// @name just stubs, real onces defined below the hierarchy
1.18      parser     91:        virtual Value *get_field(const String& ) { return 0; }
                     92:        virtual bool replace_field(const String& , Value *) { return false; }
1.11      paf        93:        
1.18      parser     94:        virtual Value *create_new_value(Pool& ) { return 0; }
1.11      paf        95:        //@}
1.2       paf        96: 
                     97: private: // Temp_method
                     98: 
1.8       paf        99:        void put_method(const String& aname, Method *amethod) {
                    100:                fmethods.put(aname, amethod); 
                    101:        }
1.2       paf       102:        
                    103: private:
                    104: 
                    105:        Hash fmethods;
                    106: 
                    107: protected:
                    108: 
                    109:        VStateless_class *fbase;
                    110: 
                    111: };
                    112: 
1.6       paf       113: ///    Auto-object used for temporarily substituting/removing class method
1.2       paf       114: class Temp_method {
                    115:        VStateless_class& fclass;
                    116:        const String& fname;
                    117:        Method *saved_method;
                    118: public:
                    119:        Temp_method(VStateless_class& aclass, const String& aname, Method *amethod) : 
                    120:                fclass(aclass),
                    121:                fname(aname),
                    122:                saved_method(aclass.get_method(aname)) {
                    123:                fclass.put_method(aname, amethod);
                    124:        }
                    125:        ~Temp_method() { 
                    126:                fclass.put_method(fname, saved_method);
                    127:        }
                    128: };
                    129: 
                    130: #endif

E-mail: