Annotation of parser3/src/types/pa_wwrapper.h, revision 1.9
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.9 ! paf 8: $Id: pa_wwrapper.h,v 1.8 2001/04/26 15:01:53 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:
21: const char *type() const { return "wwrapper"; }
1.7 paf 22: /// WWrapper: transparent
1.1 paf 23: Value *get_element(const String& name) { return check_value()->get_element(name); }
1.7 paf 24: /// WWrapper: transparent
1.3 paf 25: void put_element(const String& aname, Value *avalue){
26: if(!fvalue) {
1.1 paf 27: fvalue=NEW VHash(pool());
1.3 paf 28: // not constructing anymore [if were constructing]
29: // so to allow method calls after real constructor-method call
30: // sample:
31: // $hash[
32: // $key1[$i]
33: // ^i.inc[] ^rem{allow such calls}
34: // $key2[$1]
35: fconstructing=false;
1.1 paf 36:
1.6 paf 37: String& auto_created_hash_name=*NEW String(aname);
1.4 paf 38: fvalue->set_name(auto_created_hash_name.APPEND_CONST(" storage"));
1.3 paf 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: