Annotation of parser3/src/types/pa_vclass.C, revision 1.21

1.7       paf         1: /**    @file
                      2:        Parser: @b class parser class impl.
1.1       paf         3: 
1.20      paf         4:        Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
1.7       paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
1.21    ! paf         8: static const char * const IDENT_VCLASS_C="$Date: 2004/02/11 15:33:17 $";
1.7       paf         9: 
1.1       paf        10: #include "pa_vclass.h"
                     11: 
1.17      paf        12: Value* VClass::as(const char* atype, bool looking_up) {
                     13:        if(Value* result=Value::as(atype, looking_up))
1.12      paf        14:                return result;
1.11      paf        15:        else
1.12      paf        16:                return fbase?fbase->as(atype, looking_up):0;
1.11      paf        17: }
                     18: 
1.14      paf        19: /// VClass: $CLASS, (field)=STATIC value;(method)=method_ref with self=object_class
1.17      paf        20: Value* VClass::get_element(const String& aname, Value& aself, bool looking_up) {
1.13      paf        21:        // simple things first: $field=static field
1.17      paf        22:        if(Value* result=ffields.get(aname))
1.13      paf        23:                return result;
                     24: 
1.21    ! paf        25:        // $property
        !            26:        if(Property* prop=get_property(aname))
        !            27:        {
        !            28:                Method* method=prop->getter;
        !            29:                if(!method)
        !            30:                        throw Exception("parser.runtime",
        !            31:                                &aname,
        !            32:                                "this property has no getter method (get_%s)", aname.cstr());
        !            33: 
        !            34:                Value* result=new VJunction(new Junction(aself, method, true /*is_getter*/));
        !            35:                // cache for future use
        !            36:                if(ffields.put_dont_replace(aname, result))
        !            37:                        throw Exception("parser.runtime",
        !            38:                                &aname,
        !            39:                                "variable exists, can not create property with this name");
        !            40: 
        !            41:                return result;
        !            42:        }
        !            43: 
1.14      paf        44:        // $CLASS, $method, or other base element
1.17      paf        45:        if(Value* result=VStateless_class::get_element(aname, aself, looking_up))
1.7       paf        46:                return result;
                     47: 
                     48:        return 0;
                     49: }
                     50: 
                     51: /// VClass: (field)=value - static values only
1.21    ! paf        52: const Method* VClass::put_element(const String& aname, Value* avalue, bool replace) {
1.7       paf        53:        try {
                     54:                if(fbase && fbase->put_element(aname, avalue, true))
1.21    ! paf        55:                        return PUT_ELEMENT_REPLACED_ELEMENT; // replaced in base
1.10      paf        56:        } catch(Exception) {  /* allow override parent variables, useful for form descendants */ }
1.7       paf        57: 
                     58:        if(replace)
1.21    ! paf        59:                return ffields.put_replace(aname, avalue)? PUT_ELEMENT_REPLACED_ELEMENT: 0;
1.7       paf        60:        else {
                     61:                ffields.put(aname, avalue);
1.21    ! paf        62:                return 0;
1.7       paf        63:        }
                     64: }
                     65: 
                     66: /// @returns object of this class
1.18      paf        67: Value* VClass::create_new_value(Pool& apool) { 
                     68:        return new VObject(apool, *this);
1.1       paf        69: }

E-mail: