Annotation of parser3/src/types/pa_wwrapper.h, revision 1.35

1.7       paf         1: /**    @file
1.8       paf         2:        Parser: @b write_wrapper write context
1.7       paf         3: 
1.31      paf         4:        Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
1.16      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_WWRAPPER_H
                      9: #define PA_WWRAPPER_H
1.19      paf        10: 
1.35    ! paf        11: static const char * const IDENT_WWRAPPER_H="$Date: 2005/07/28 11:23:03 $";
1.1       paf        12: 
                     13: #include "pa_wcontext.h"
                     14: #include "pa_exception.h"
                     15: 
1.7       paf        16: /// specialized write context, adds to WContext VHash autocreation ability
1.29      paf        17: class WWrapper: public WContext {
1.1       paf        18: public: // Value
                     19: 
1.29      paf        20:        override const char* type() const { return "wwrapper"; }
1.7       paf        21:        /// WWrapper: transparent
1.29      paf        22:        override Value* get_element(const String& aname, Value& aself, bool looking_up) { 
                     23:                return as_value().get_element(aname, aself, looking_up); 
1.22      paf        24:        }
1.7       paf        25:        /// WWrapper: transparent
1.35    ! paf        26:        override const VJunction* put_element(Value& aself, const String& aname, Value* avalue, bool areplace) { 
1.3       paf        27:                if(!fvalue) {
1.29      paf        28:                        fvalue=new VHash;
1.3       paf        29:                        // not constructing anymore [if were constructing]
                     30:                        // so to allow method calls after real constructor-method call
                     31:                        // sample:
                     32:                        //      $hash[
1.21      paf        33:                        //              $.key1[$i]
1.3       paf        34:                        //              ^i.inc[]  ^rem{allow such calls}
1.21      paf        35:                        //              $.key2[$1]
1.13      paf        36:                        set_constructing(false);
1.3       paf        37:                }
                     38: 
1.34      paf        39:                return fvalue->put_element(aself, aname, avalue, areplace); 
1.1       paf        40:        }
                     41: 
                     42: public: // usage
                     43: 
1.29      paf        44:        WWrapper(Value* avalue, WContext *aparent) : 
                     45:                WContext(avalue, aparent) {
1.1       paf        46:        }
                     47:        
                     48: private:
                     49:        // raises an exception on 0 value
1.29      paf        50:        Value& as_value() const {
1.1       paf        51:                if(!fvalue)
1.17      paf        52:                        throw Exception(0,
1.1       paf        53:                                0,
                     54:                                "accessing wrapper without value");
                     55: 
1.29      paf        56:                return *fvalue;
1.1       paf        57:        }
                     58: };
                     59: 
                     60: #endif

E-mail: