--- parser3/src/include/Attic/pa_wcontext.h 2001/02/22 08:25:51 1.4 +++ parser3/src/include/Attic/pa_wcontext.h 2001/03/10 11:44:32 1.26 @@ -1,87 +1,60 @@ /* - $Id: pa_wcontext.h,v 1.4 2001/02/22 08:25:51 paf Exp $ -*/ - -/* - data core + $Id: pa_wcontext.h,v 1.26 2001/03/10 11:44:32 paf Exp $ */ #ifndef PA_WCONTEXT_H #define PA_WCONTEXT_H #include "pa_value.h" +#include "pa_vstring.h" +#include "pa_vhash.h" + +class Request; class WContext : public Value { + friend Request; public: // Value // all: for error reporting after fail(), etc - /*virtual*/ const char *get_type() const { return "WContext"; } - // wcontext: accumulated string - /*virtual*/ String *get_string() { return &string; }; - // wcontext: transparent - /*virtual*/ 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); } + const char *type() const { return "wcontext"; } + // WContext: accumulated fstring + const String *get_string() { return &fstring; }; + + // WContext: none yet | transparent + VClass *get_class() { return fvalue?fvalue->get_class():0; } // wcontext: transparent - /*virtual*/ 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; } - // wcontext: none yet | transparent - /*virtual*/ bool is_or_derived_from(VClass& ancestor) { return fvalue?fvalue->is_or_derived_from(ancestor):false; } + VAliased *get_aliased() { return fvalue?fvalue->get_aliased():0; } + +public: // WContext + + // appends a fstring to result + virtual void write(const String& astring, String::Untaint_lang lang); + + // if value is VString writes fstring, + // else writes Value; raises an error if already + virtual void write(Value& avalue); public: // usage - WContext(Pool& apool, Value *avalue) : Value(apool), + WContext(Pool& apool, Value *avalue, bool aconstructing) : Value(apool), fvalue(avalue), - string(apool) { + fconstructing(aconstructing), + fstring(*new(apool) String(apool)) { } - // appends a string to result - void write(String *astring) { - if(!astring) - return; - - 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) { - if(!avalue) - return; - - if(fvalue) // already have value? - pool().exception().raise(0,0, // don't need to construct twice - 0, - "value already assigned"); - else - fvalue=avalue; - - String *string=avalue->get_string(); - if(string) - write(string); - } - //void write(String_iterator& from, String_iterator& to); + bool constructing() { return fconstructing; } // retrives the resulting value // that can be VString if value==0 or the Value object - Value *value() const { - return fvalue?fvalue:0;//TODO: new VString(string); + Value *result() const { + return fvalue?fvalue:NEW VString(fstring); } - -private: - String string; - Value *fvalue; +protected: + Value *fvalue; private: - // raises an exception on 0 value - Value *check_value() const { - if(!fvalue) - pool().exception().raise(0,0, - 0, - "accessing wcontext without value"); - - return fvalue; - } + bool fconstructing; + String& fstring; }; #endif