|
|
| version 1.10, 2001/02/23 09:43:14 | version 1.15, 2001/02/24 11:46:03 |
|---|---|
| Line 14 public: // Value | Line 14 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: accumulated string | // WContext: accumulated string |
| String *get_string() { return 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: transparent | public: // WContext |
| Method *get_method(const String& name) const { return check_value()->get_method(name); } | |
| // wcontext: none yet | transparent | // appends a string to result |
| VClass *get_class() const { return fvalue?fvalue->get_class():0; } | virtual void write(String *astring); |
| // wcontext: none yet | transparent | |
| bool is_or_derived_from(VClass& ancestor) { return fvalue?fvalue->is_or_derived_from(ancestor):false; } | // if value is VString writes string, |
| // else writes Value; raises an error if already | |
| virtual void write(Value *avalue); | |
| public: // usage | public: // usage |
| Line 40 public: // usage | Line 33 public: // usage |
| string(new(apool) String(apool)) { | string(new(apool) String(apool)) { |
| } | } |
| // appends a string to result | // retrives the resulting value |
| void write(String *astring) { | Value *object() const { |
| if(!astring) | return fvalue; |
| 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; | |
| } | } |
| // 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 *result() const { |
| return fvalue?fvalue:NEW VString(string); | return fvalue?fvalue:NEW VString(string); |
| } | } |
| private: | |
| String *string; | |
| Value *fvalue; | |
| protected: | |
| Value *fvalue; | |
| private: | private: |
| // raises an exception on 0 value | String *string; |
| Value *check_value() const { | |
| if(!fvalue) | |
| THROW(0,0, | |
| 0, | |
| "accessing wcontext without value"); | |
| return fvalue; | |
| } | |
| }; | }; |
| #endif | #endif |