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

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: 
        !            11: static const char* IDENT_WWRAPPER_H="$Id: zzz $";
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.1       paf        22:        Value *get_element(const String& name) { return check_value()->get_element(name); }
1.7       paf        23:        /// WWrapper: transparent
1.3       paf        24:        void put_element(const String& aname, Value *avalue){ 
                     25:                if(!fvalue) {
1.1       paf        26:                        fvalue=NEW VHash(pool());
1.3       paf        27:                        // not constructing anymore [if were constructing]
                     28:                        // so to allow method calls after real constructor-method call
                     29:                        // sample:
                     30:                        //      $hash[
                     31:                        //              $key1[$i]
                     32:                        //              ^i.inc[]  ^rem{allow such calls}
                     33:                        //              $key2[$1]
1.13      paf        34:                        set_constructing(false);
1.3       paf        35:                }
                     36: 
                     37:                fvalue->put_element(aname, avalue); 
1.1       paf        38:        }
                     39: 
                     40: public: // usage
                     41: 
1.10      parser     42:        WWrapper(Pool& apool, Value *avalue) : 
                     43:                WContext(apool, avalue) {
1.1       paf        44:        }
                     45:        
                     46: private:
                     47:        // raises an exception on 0 value
                     48:        Value *check_value() const {
                     49:                if(!fvalue)
1.17      paf        50:                        throw Exception(0,
1.1       paf        51:                                0,
                     52:                                "accessing wrapper without value");
                     53: 
                     54:                return fvalue;
                     55:        }
                     56: };
                     57: 
                     58: #endif

E-mail: