Annotation of parser3/src/include/pa_wcontext.h, revision 1.11
1.1 paf 1: /*
1.11 ! paf 2: $Id: pa_wcontext.h,v 1.10 2001/02/23 09:43:14 paf Exp $
1.1 paf 3: */
4:
5: #ifndef PA_WCONTEXT_H
6: #define PA_WCONTEXT_H
7:
8: #include "pa_value.h"
1.7 paf 9: #include "pa_vstring.h"
1.10 paf 10: #include "pa_vhash.h"
1.1 paf 11:
12: class WContext : public Value {
1.2 paf 13: public: // Value
14:
15: // all: for error reporting after fail(), etc
1.5 paf 16: const char *type() const { return "WContext"; }
1.2 paf 17: // wcontext: accumulated string
1.7 paf 18: String *get_string() { return string; };
1.2 paf 19: // wcontext: transparent
1.8 paf 20: Value *get_element(const String& name) { return check_value()->get_element(name); }
1.2 paf 21: // wcontext: transparent
1.10 paf 22: // void put_element(const String& name, Value *avalue){ check_value()->put_element(name, avalue); }
23: void put_element(const String& name, Value *avalue){
24: if(!fvalue)
25: fvalue=NEW VHash(pool());
26: fvalue->put_element(name, avalue);
27: }
28:
1.2 paf 29: // wcontext: transparent
1.5 paf 30: Method *get_method(const String& name) const { return check_value()->get_method(name); }
1.2 paf 31: // wcontext: none yet | transparent
1.5 paf 32: VClass *get_class() const { return fvalue?fvalue->get_class():0; }
1.2 paf 33: // wcontext: none yet | transparent
1.5 paf 34: bool is_or_derived_from(VClass& ancestor) { return fvalue?fvalue->is_or_derived_from(ancestor):false; }
1.2 paf 35:
36: public: // usage
37:
38: WContext(Pool& apool, Value *avalue) : Value(apool),
39: fvalue(avalue),
1.7 paf 40: string(new(apool) String(apool)) {
1.2 paf 41: }
1.1 paf 42:
43: // appends a string to result
1.3 paf 44: void write(String *astring) {
45: if(!astring)
46: return;
47:
1.7 paf 48: *string+=*astring;
1.3 paf 49: }
1.5 paf 50: // if value is VString writes string,
51: // else writes Value; raises an error if already
1.3 paf 52: void write(Value *avalue) {
53: if(!avalue)
54: return;
55:
56: String *string=avalue->get_string();
57: if(string)
58: write(string);
1.5 paf 59: else
60: if(fvalue) // already have value?
1.6 paf 61: THROW(0,0, // don't need to construct twice
1.11 ! paf 62: fvalue->name(),
1.6 paf 63: "value already assigned, use constructor to reassign it");
1.5 paf 64: else
65: fvalue=avalue;
1.3 paf 66: }
1.1 paf 67:
68: // retrives the resulting value
1.3 paf 69: // that can be VString if value==0 or the Value object
1.1 paf 70: Value *value() const {
1.7 paf 71: return fvalue?fvalue:NEW VString(string);
1.1 paf 72: }
73:
74: private:
1.7 paf 75: String *string;
1.2 paf 76: Value *fvalue;
1.1 paf 77:
78: private:
79: // raises an exception on 0 value
1.2 paf 80: Value *check_value() const {
81: if(!fvalue)
1.6 paf 82: THROW(0,0,
1.2 paf 83: 0,
84: "accessing wcontext without value");
85:
86: return fvalue;
87: }
1.1 paf 88: };
89:
90: #endif
E-mail: