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

1.7       paf         1: /**    @file
1.8       paf         2:        Parser: @b write_wrapper write context
1.7       paf         3: 
1.15      paf         4:        Copyright (c) 2001, 2002 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.26    ! paf        11: static const char* IDENT_WWRAPPER_H="$Date: 2002/09/10 12:02:24 $";
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.1       paf        17: class WWrapper : public WContext {
                     18: public: // Value
                     19: 
                     20:        const char *type() const { return "wwrapper"; }
1.7       paf        21:        /// WWrapper: transparent
1.24      paf        22:        Value *get_element(const String& aname, Value *aself, bool looking_up) { 
                     23:                return check_value()->get_element(aname, aself, looking_up); 
1.22      paf        24:        }
1.7       paf        25:        /// WWrapper: transparent
1.22      paf        26:        /*override*/ bool put_element(const String& aname, Value *avalue, bool replace) { 
1.3       paf        27:                if(!fvalue) {
1.1       paf        28:                        fvalue=NEW VHash(pool());
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.22      paf        39:                return fvalue->put_element(aname, avalue, replace); 
1.1       paf        40:        }
                     41: 
                     42: public: // usage
                     43: 
1.26    ! paf        44:        WWrapper(Pool& apool, Value *avalue, WContext *aparent) : 
        !            45:                WContext(apool, avalue, aparent) {
1.1       paf        46:        }
                     47:        
                     48: private:
                     49:        // raises an exception on 0 value
                     50:        Value *check_value() const {
                     51:                if(!fvalue)
1.17      paf        52:                        throw Exception(0,
1.1       paf        53:                                0,
                     54:                                "accessing wrapper without value");
                     55: 
                     56:                return fvalue;
                     57:        }
                     58: };
                     59: 
                     60: #endif

E-mail: