Annotation of parser3/src/types/pa_wwrapper.h, revision 1.5
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.5 ! paf 6: $Id: pa_wwrapper.h,v 1.4.8.1 2001/03/20 17:21:57 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());
1.5 ! paf 36: auto_created_hash_name.append(aname, String::UL_NO);
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:
45: WWrapper(Pool& apool, Value *avalue, bool aconstructed) :
46: WContext(apool, avalue, aconstructed) {
47: }
48:
49: private:
50: // raises an exception on 0 value
51: Value *check_value() const {
52: if(!fvalue)
53: THROW(0,0,
54: 0,
55: "accessing wrapper without value");
56:
57: return fvalue;
58: }
59: };
60:
61: #endif
E-mail: