Annotation of parser3/src/include/pa_wcontext.h, revision 1.3
1.1 paf 1: /*
1.3 ! paf 2: $Id: pa_wcontext.h,v 1.2 2001/02/21 17:36:30 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"
13:
14: class WContext : public Value {
1.2 paf 15: public: // Value
16:
17: // all: for error reporting after fail(), etc
18: /*virtual*/ const char *get_type() const { return "WContext"; }
19: // wcontext: accumulated string
20: /*virtual*/ String *get_string() { return &string; };
21: // wcontext: transparent
22: /*virtual*/ Value *get_element(const String& name) const { return check_value()->get_element(name); }
23: // wcontext: transparent
24: /*virtual*/ void put_element(const String& name, Value *avalue){ check_value()->put_element(name, avalue); }
25: // wcontext: transparent
26: /*virtual*/ Method *get_method(const String& name) const { return check_value()->get_method(name); }
27: // wcontext: none yet | transparent
28: /*virtual*/ VClass *get_class() const { return fvalue?fvalue->get_class():0; }
29: // wcontext: none yet | transparent
30: /*virtual*/ bool is_or_derived_from(VClass& ancestor) { return fvalue?fvalue->is_or_derived_from(ancestor):false; }
31:
32: public: // usage
33:
34: WContext(Pool& apool, Value *avalue) : Value(apool),
35: fvalue(avalue),
36: string(apool) {
37: }
1.1 paf 38:
39: // appends a string to result
40: // until Value written, ignores afterwards
1.3 ! paf 41: void write(String *astring) {
! 42: if(!astring)
! 43: return;
! 44:
! 45: if(fvalue) // already have value?
! 46: return; // don't need any strings anymore
! 47:
! 48: string+=*astring;
! 49: }
1.1 paf 50: // if value.string!=0 writes string altogether[for showing class names, etc]
51: // 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);
! 59: else
! 60: if(fvalue) // already have value?
! 61: pool().exception().raise(0,0, // don't need to construct twice
! 62: 0,
! 63: "value already assigned");
! 64: else
! 65: fvalue=avalue;
! 66: }
1.1 paf 67: //void write(String_iterator& from, String_iterator& to);
68:
69: // retrives the resulting value
1.3 ! paf 70: // that can be VString if value==0 or the Value object
1.1 paf 71: Value *value() const {
1.3 ! paf 72: return fvalue?fvalue:0;//TODO: new VString(string);
1.1 paf 73: }
74:
75: private:
76: String string;
1.2 paf 77: Value *fvalue;
1.1 paf 78:
79: private:
80: // raises an exception on 0 value
1.2 paf 81: Value *check_value() const {
82: if(!fvalue)
83: pool().exception().raise(0,0,
84: 0,
85: "accessing wcontext without value");
86:
87: return fvalue;
88: }
1.1 paf 89: };
90:
91: #endif
E-mail: