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

1.1       paf         1: /*
                      2:        Parser
                      3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.2       paf         4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1       paf         5: 
1.6     ! paf         6:        $Id: pa_wwrapper.h,v 1.5 2001/03/21 14:06:54 paf Exp $
1.1       paf         7: */
                      8: 
                      9: #ifndef PA_WWRAPPER_H
                     10: #define PA_WWRAPPER_H
                     11: 
                     12: #include "pa_wcontext.h"
                     13: #include "pa_exception.h"
                     14: 
                     15: class WWrapper : public WContext {
                     16: public: // Value
                     17: 
                     18:        // all: for error reporting after fail(), etc
                     19:        const char *type() const { return "wwrapper"; }
                     20:        // wwrapper: transparent
                     21:        Value *get_element(const String& name) { return check_value()->get_element(name); }
                     22:        // wwrapper: transparent
1.3       paf        23:        void put_element(const String& aname, Value *avalue){ 
                     24:                if(!fvalue) {
1.1       paf        25:                        fvalue=NEW VHash(pool());
1.3       paf        26:                        // not constructing anymore [if were constructing]
                     27:                        // so to allow method calls after real constructor-method call
                     28:                        // sample:
                     29:                        //      $hash[
                     30:                        //              $key1[$i]
                     31:                        //              ^i.inc[]  ^rem{allow such calls}
                     32:                        //              $key2[$1]
                     33:                        fconstructing=false;
1.1       paf        34: 
1.6     ! paf        35:                        String& auto_created_hash_name=*NEW String(aname);
1.4       paf        36:                        fvalue->set_name(auto_created_hash_name.APPEND_CONST(" storage"));
1.3       paf        37:                }
                     38: 
                     39:                fvalue->put_element(aname, avalue); 
1.1       paf        40:        }
                     41: 
                     42: public: // usage
                     43: 
                     44:        WWrapper(Pool& apool, Value *avalue, bool aconstructed) : 
                     45:                WContext(apool, avalue, aconstructed) {
                     46:        }
                     47:        
                     48: private:
                     49:        // raises an exception on 0 value
                     50:        Value *check_value() const {
                     51:                if(!fvalue)
                     52:                        THROW(0,0,
                     53:                                0,
                     54:                                "accessing wrapper without value");
                     55: 
                     56:                return fvalue;
                     57:        }
                     58: };
                     59: 
                     60: #endif

E-mail: