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