|
|
| version 1.12, 2001/02/23 14:18:26 | version 1.24, 2001/03/09 04:47:27 |
|---|---|
| Line 5 | Line 5 |
| #ifndef PA_WCONTEXT_H | #ifndef PA_WCONTEXT_H |
| #define PA_WCONTEXT_H | #define PA_WCONTEXT_H |
| #include "pa_wvalue.h" | #include "pa_value.h" |
| #include "pa_vstring.h" | |
| #include "pa_vhash.h" | |
| class WContext : public WValue { | class WContext : public Value { |
| public: // Value | public: // Value |
| // all: for error reporting after fail(), etc | // all: for error reporting after fail(), etc |
| const char *type() const { return "WContext"; } | const char *type() const { return "wcontext"; } |
| // wcontext: transparent | // WContext: accumulated fstring |
| Value *get_element(const String& name) { return check_value()->get_element(name); } | String *get_string() { return &fstring; }; |
| // wcontext: transparent | |
| void put_element(const String& name, Value *avalue){ | |
| if(!fvalue) | |
| fvalue=NEW VHash(pool()); | |
| fvalue->put_element(name, avalue); | |
| } | |
| // WContext: none yet | transparent | |
| VClass *get_class() { return fvalue?fvalue->get_class():0; } | |
| // wcontext: transparent | // wcontext: transparent |
| Method *get_method(const String& name) const { return check_value()->get_method(name); } | VAliased *get_aliased() { return fvalue?fvalue->get_aliased():0; } |
| // wcontext: none yet | transparent | |
| VClass *get_class() const { return fvalue?fvalue->get_class():0; } | public: // WContext |
| // wcontext: none yet | transparent | |
| bool is_or_derived_from(VClass& ancestor) { return fvalue?fvalue->is_or_derived_from(ancestor):false; } | // appends a fstring to result |
| virtual void write(String& astring); | |
| // if value is VString writes fstring, | |
| // else writes Value; raises an error if already | |
| virtual void write(Value& avalue); | |
| public: // usage | public: // usage |
| WContext(Pool& apool, Value *avalue) : WValue(apool, avalue) { | WContext(Pool& apool, Value *avalue, bool aconstructing) : Value(apool), |
| fvalue(avalue), | |
| fconstructing(aconstructing), | |
| fstring(*new(apool) String(apool)) { | |
| } | } |
| private: | |
| // raises an exception on 0 value | |
| Value *check_value() const { | |
| if(!fvalue) | |
| THROW(0,0, | |
| 0, | |
| "accessing wcontext without value"); | |
| return fvalue; | bool constructing() { return fconstructing; } |
| // retrives the resulting value | |
| // that can be VString if value==0 or the Value object | |
| Value *result() const { | |
| return fvalue?fvalue:NEW VString(fstring); | |
| } | } |
| protected: | |
| Value *fvalue; | |
| private: | |
| bool fconstructing; | |
| String& fstring; | |
| }; | }; |
| #endif | #endif |