Annotation of parser3/src/types/pa_wwrapper.h, revision 1.8
1.7 paf 1: /** @file
1.8 ! paf 2: Parser: @b write_wrapper write context
1.7 paf 3:
1.1 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.7 paf 5:
1.2 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1 paf 7:
1.8 ! paf 8: $Id: pa_wwrapper.h,v 1.7 2001/04/26 14:55:35 paf Exp $
1.1 paf 9: */
10:
11: #ifndef PA_WWRAPPER_H
12: #define PA_WWRAPPER_H
13:
14: #include "pa_wcontext.h"
15: #include "pa_exception.h"
16:
1.7 paf 17: /// specialized write context, adds to WContext VHash autocreation ability
1.1 paf 18: class WWrapper : public WContext {
19: public: // Value
20:
1.7 paf 21: /// all: for error reporting after fail(), etc
1.1 paf 22: const char *type() const { return "wwrapper"; }
1.7 paf 23: /// WWrapper: transparent
1.1 paf 24: Value *get_element(const String& name) { return check_value()->get_element(name); }
1.7 paf 25: /// WWrapper: transparent
1.3 paf 26: void put_element(const String& aname, Value *avalue){
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[
33: // $key1[$i]
34: // ^i.inc[] ^rem{allow such calls}
35: // $key2[$1]
36: fconstructing=false;
1.1 paf 37:
1.6 paf 38: String& auto_created_hash_name=*NEW String(aname);
1.4 paf 39: fvalue->set_name(auto_created_hash_name.APPEND_CONST(" storage"));
1.3 paf 40: }
41:
42: fvalue->put_element(aname, avalue);
1.1 paf 43: }
44:
45: public: // usage
46:
47: WWrapper(Pool& apool, Value *avalue, bool aconstructed) :
48: WContext(apool, avalue, aconstructed) {
49: }
50:
51: private:
52: // raises an exception on 0 value
53: Value *check_value() const {
54: if(!fvalue)
55: THROW(0,0,
56: 0,
57: "accessing wrapper without value");
58:
59: return fvalue;
60: }
61: };
62:
63: #endif
E-mail: