--- parser3/src/include/Attic/pa_wcontext.h 2001/02/23 12:47:08 1.11 +++ parser3/src/include/Attic/pa_wcontext.h 2001/02/25 17:33:43 1.19 @@ -1,5 +1,5 @@ /* - $Id: pa_wcontext.h,v 1.11 2001/02/23 12:47:08 paf Exp $ + $Id: pa_wcontext.h,v 1.19 2001/02/25 17:33:43 paf Exp $ */ #ifndef PA_WCONTEXT_H @@ -14,77 +14,48 @@ public: // Value // all: for error reporting after fail(), etc const char *type() const { return "WContext"; } - // wcontext: accumulated string - String *get_string() { return string; }; - // wcontext: transparent - Value *get_element(const String& name) { return check_value()->get_element(name); } - // wcontext: transparent -// void put_element(const String& name, Value *avalue){ check_value()->put_element(name, avalue); } - void put_element(const String& name, Value *avalue){ - if(!fvalue) - fvalue=NEW VHash(pool()); - fvalue->put_element(name, avalue); - } + // WContext: accumulated string + String *get_string() { return &string; }; + // WContext: none yet | transparent + VClass *get_class() { return fvalue?fvalue->get_class():0; } // wcontext: transparent - Method *get_method(const String& name) const { return check_value()->get_method(name); } - // wcontext: none yet | transparent - VClass *get_class() const { return fvalue?fvalue->get_class():0; } - // wcontext: none yet | transparent - bool is_or_derived_from(VClass& ancestor) { return fvalue?fvalue->is_or_derived_from(ancestor):false; } + Value *get_aliased() { return fvalue?fvalue->get_aliased():0; } -public: // usage - - WContext(Pool& apool, Value *avalue) : Value(apool), - fvalue(avalue), - string(new(apool) String(apool)) { - } +public: // WContext // appends a string to result - void write(String *astring) { - if(!astring) - return; + virtual void write(String *astring); - *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 - fvalue->name(), - "value already assigned, use constructor to reassign it"); - else - fvalue=avalue; + virtual void write(Value *avalue); + +public: // usage + + WContext(Pool& apool, Value *avalue, bool aconstructing) : Value(apool), + fvalue(avalue), + fconstructing(aconstructing), + string(*new(apool) String(apool)) { } + bool constructing() { return fconstructing; } + + // retrives the resulting value + Value *object() const { + return fvalue; + } // retrives the resulting value // that can be VString if value==0 or the Value object - Value *value() const { + Value *result() const { return fvalue?fvalue:NEW VString(string); } - -private: - String *string; - Value *fvalue; +protected: + Value *fvalue; private: - // raises an exception on 0 value - Value *check_value() const { - if(!fvalue) - THROW(0,0, - 0, - "accessing wcontext without value"); - - return fvalue; - } + bool fconstructing; + String& string; }; #endif