|
|
| version 1.3, 2001/02/22 08:16:09 | version 1.7, 2001/02/22 13:33:25 |
|---|---|
| Line 10 | Line 10 |
| #define PA_WCONTEXT_H | #define PA_WCONTEXT_H |
| #include "pa_value.h" | #include "pa_value.h" |
| #include "pa_vstring.h" | |
| class WContext : public Value { | class WContext : public Value { |
| public: // Value | public: // Value |
| // all: for error reporting after fail(), etc | // all: for error reporting after fail(), etc |
| /*virtual*/ const char *get_type() const { return "WContext"; } | const char *type() const { return "WContext"; } |
| // wcontext: accumulated string | // wcontext: accumulated string |
| /*virtual*/ String *get_string() { return &string; }; | String *get_string() { return string; }; |
| // wcontext: transparent | // 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 | // 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 | // 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 | // 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 | // 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 | public: // usage |
| WContext(Pool& apool, Value *avalue) : Value(apool), | WContext(Pool& apool, Value *avalue) : Value(apool), |
| fvalue(avalue), | fvalue(avalue), |
| string(apool) { | string(new(apool) String(apool)) { |
| } | } |
| // appends a string to result | // appends a string to result |
| // until Value written, ignores afterwards | |
| void write(String *astring) { | void write(String *astring) { |
| if(!astring) | if(!astring) |
| return; | return; |
| if(fvalue) // already have value? | *string+=*astring; |
| return; // don't need any strings anymore | |
| string+=*astring; | |
| } | } |
| // if value.string!=0 writes string altogether[for showing class names, etc] | // if value is VString writes string, |
| // writes Value; raises an error if already | // else writes Value; raises an error if already |
| void write(Value *avalue) { | void write(Value *avalue) { |
| if(!avalue) | if(!avalue) |
| return; | return; |
| Line 58 public: // usage | Line 55 public: // usage |
| write(string); | write(string); |
| else | else |
| if(fvalue) // already have value? | if(fvalue) // already have value? |
| pool().exception().raise(0,0, // don't need to construct twice | THROW(0,0, // don't need to construct twice |
| 0, | 0, |
| "value already assigned"); | "value already assigned, use constructor to reassign it"); |
| else | else |
| fvalue=avalue; | fvalue=avalue; |
| } | } |
| //void write(String_iterator& from, String_iterator& to); | |
| // retrives the resulting value | // retrives the resulting value |
| // that can be VString if value==0 or the Value object | // that can be VString if value==0 or the Value object |
| Value *value() const { | Value *value() const { |
| return fvalue?fvalue:0;//TODO: new VString(string); | return fvalue?fvalue:NEW VString(string); |
| } | } |
| private: | private: |
| String string; | String *string; |
| Value *fvalue; | Value *fvalue; |
| private: | private: |
| // raises an exception on 0 value | // raises an exception on 0 value |
| Value *check_value() const { | Value *check_value() const { |
| if(!fvalue) | if(!fvalue) |
| pool().exception().raise(0,0, | THROW(0,0, |
| 0, | 0, |
| "accessing wcontext without value"); | "accessing wcontext without value"); |