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