Annotation of parser3/src/types/pa_wwrapper.h, revision 1.13
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.2 paf 5: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1 paf 6:
1.13 ! paf 7: $Id: pa_wwrapper.h,v 1.12 2001/10/19 12:43:30 parser Exp $
1.1 paf 8: */
9:
10: #ifndef PA_WWRAPPER_H
11: #define PA_WWRAPPER_H
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.1 paf 35:
1.6 paf 36: String& auto_created_hash_name=*NEW String(aname);
1.4 paf 37: fvalue->set_name(auto_created_hash_name.APPEND_CONST(" storage"));
1.3 paf 38: }
39:
40: fvalue->put_element(aname, avalue);
1.1 paf 41: }
42:
43: public: // usage
44:
1.10 parser 45: WWrapper(Pool& apool, Value *avalue) :
46: WContext(apool, avalue) {
1.1 paf 47: }
48:
49: private:
50: // raises an exception on 0 value
51: Value *check_value() const {
52: if(!fvalue)
1.12 parser 53: throw Exception(0,0,
1.1 paf 54: 0,
55: "accessing wrapper without value");
56:
57: return fvalue;
58: }
59: };
60:
61: #endif
E-mail: