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

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.3     ! paf         6:        $Id: pa_wwrapper.h,v 1.2 2001/03/11 08:16:39 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.3     ! paf        35:                        String& auto_created_hash_name=*NEW String(pool());
        !            36:                        auto_created_hash_name.append(aname, String::Untaint_lang::NO);
        !            37:                        auto_created_hash_name.APPEND_CONST(" storage");
        !            38:                        fvalue->set_name(auto_created_hash_name);
        !            39:                }
        !            40: 
        !            41:                fvalue->put_element(aname, avalue); 
1.1       paf        42:        }
                     43: 
                     44: public: // usage
                     45: 
                     46:        WWrapper(Pool& apool, Value *avalue, bool aconstructed) : 
                     47:                WContext(apool, avalue, aconstructed) {
                     48:        }
                     49:        
                     50: private:
                     51:        // raises an exception on 0 value
                     52:        Value *check_value() const {
                     53:                if(!fvalue)
                     54:                        THROW(0,0,
                     55:                                0,
                     56:                                "accessing wrapper without value");
                     57: 
                     58:                return fvalue;
                     59:        }
                     60: };
                     61: 
                     62: #endif

E-mail: