--- parser3/src/include/Attic/pa_wcontext.h 2001/02/21 17:36:30 1.2 +++ parser3/src/include/Attic/pa_wcontext.h 2001/02/22 10:43:42 1.6 @@ -1,5 +1,5 @@ /* - $Id: pa_wcontext.h,v 1.2 2001/02/21 17:36:30 paf Exp $ + $Id: pa_wcontext.h,v 1.6 2001/02/22 10:43:42 paf Exp $ */ /* @@ -15,19 +15,19 @@ class WContext : public Value { public: // Value // all: for error reporting after fail(), etc - /*virtual*/ const char *get_type() const { return "WContext"; } + const char *type() const { return "WContext"; } // wcontext: accumulated string - /*virtual*/ String *get_string() { return &string; }; + String *get_string() { return &string; }; // wcontext: transparent - /*virtual*/ Value *get_element(const String& name) const { return check_value()->get_element(name); } + Value *get_element(const String& name) const { return check_value()->get_element(name); } // wcontext: transparent - /*virtual*/ void put_element(const String& name, Value *avalue){ check_value()->put_element(name, avalue); } + void put_element(const String& name, Value *avalue){ check_value()->put_element(name, avalue); } // wcontext: transparent - /*virtual*/ Method *get_method(const String& name) const { return check_value()->get_method(name); } + Method *get_method(const String& name) const { return check_value()->get_method(name); } // wcontext: none yet | transparent - /*virtual*/ VClass *get_class() const { return fvalue?fvalue->get_class():0; } + VClass *get_class() const { return fvalue?fvalue->get_class():0; } // wcontext: none yet | transparent - /*virtual*/ bool is_or_derived_from(VClass& ancestor) { return fvalue?fvalue->is_or_derived_from(ancestor):false; } + bool is_or_derived_from(VClass& ancestor) { return fvalue?fvalue->is_or_derived_from(ancestor):false; } public: // usage @@ -37,17 +37,35 @@ public: // usage } // appends a string to result - // until Value written, ignores afterwards - void write(String& astring); - // if value.string!=0 writes string altogether[for showing class names, etc] - // writes Value; raises an error if already - void write(Value& avalue); + void write(String *astring) { + if(!astring) + return; + + string+=*astring; + } + // if value is VString writes string, + // else writes Value; raises an error if already + void write(Value *avalue) { + if(!avalue) + return; + + String *string=avalue->get_string(); + if(string) + write(string); + else + if(fvalue) // already have value? + THROW(0,0, // don't need to construct twice + 0, + "value already assigned, use constructor to reassign it"); + else + fvalue=avalue; + } //void write(String_iterator& from, String_iterator& to); // retrives the resulting value - // that can be Text if value==0 or the Value object + // that can be VString if value==0 or the Value object Value *value() const { - return fvalue?fvalue:0;//TODO: new Text(string); + return fvalue?fvalue:0;//TODO: new VString(string); } private: @@ -58,7 +76,7 @@ private: // raises an exception on 0 value Value *check_value() const { if(!fvalue) - pool().exception().raise(0,0, + THROW(0,0, 0, "accessing wcontext without value");