Annotation of parser3/src/include/pa_wcontext.h, revision 1.6

1.1       paf         1: /*
1.6     ! paf         2:   $Id: pa_wcontext.h,v 1.5 2001/02/22 09:14:25 paf Exp $
1.1       paf         3: */
                      4: 
                      5: /*
                      6:        data core
                      7: */
                      8: 
                      9: #ifndef PA_WCONTEXT_H
                     10: #define PA_WCONTEXT_H
                     11: 
                     12: #include "pa_value.h"
                     13: 
                     14: class WContext : public Value {
1.2       paf        15: public: // Value
                     16: 
                     17:        // all: for error reporting after fail(), etc
1.5       paf        18:        const char *type() const { return "WContext"; }
1.2       paf        19:        // wcontext: accumulated string
1.5       paf        20:        String *get_string() { return &string; };
1.2       paf        21:        // wcontext: transparent
1.5       paf        22:        Value *get_element(const String& name) const { return check_value()->get_element(name); }
1.2       paf        23:        // wcontext: transparent
1.5       paf        24:        void put_element(const String& name, Value *avalue){ check_value()->put_element(name, avalue); }
1.2       paf        25:        // wcontext: transparent
1.5       paf        26:        Method *get_method(const String& name) const { return check_value()->get_method(name); }
1.2       paf        27:        // wcontext: none yet | transparent
1.5       paf        28:        VClass *get_class() const { return fvalue?fvalue->get_class():0; }
1.2       paf        29:        // wcontext: none yet | transparent
1.5       paf        30:        bool is_or_derived_from(VClass& ancestor) { return fvalue?fvalue->is_or_derived_from(ancestor):false; }
1.2       paf        31: 
                     32: public: // usage
                     33: 
                     34:        WContext(Pool& apool, Value *avalue) : Value(apool), 
                     35:                fvalue(avalue),
                     36:                string(apool) {
                     37:        }
1.1       paf        38: 
                     39:        // appends a string to result
1.3       paf        40:        void write(String *astring) {
                     41:                if(!astring)
                     42:                        return;
                     43: 
                     44:                string+=*astring;
                     45:        }
1.5       paf        46:        // if value is VString writes string,
                     47:        // else writes Value; raises an error if already
1.3       paf        48:        void write(Value *avalue) {
                     49:                if(!avalue)
                     50:                        return;
                     51: 
                     52:                String *string=avalue->get_string();
                     53:                if(string)
                     54:                        write(string);
1.5       paf        55:                else
                     56:                        if(fvalue) // already have value?
1.6     ! paf        57:                                THROW(0,0,  // don't need to construct twice
        !            58:                                        0,
        !            59:                                        "value already assigned, use constructor to reassign it");
1.5       paf        60:                        else
                     61:                                fvalue=avalue;
1.3       paf        62:        }
1.1       paf        63:        //void write(String_iterator& from, String_iterator& to);
                     64: 
                     65:        // retrives the resulting value
1.3       paf        66:        // that can be VString if value==0 or the Value object
1.1       paf        67:        Value *value() const {
1.3       paf        68:                return fvalue?fvalue:0;//TODO: new VString(string);
1.1       paf        69:        }
                     70:        
                     71: private:
                     72:        String string;
1.2       paf        73:        Value *fvalue;
1.1       paf        74: 
                     75: private:
                     76:        // raises an exception on 0 value
1.2       paf        77:        Value *check_value() const {
                     78:                if(!fvalue)
1.6     ! paf        79:                        THROW(0,0,
1.2       paf        80:                                0,
                     81:                                "accessing wcontext without value");
                     82: 
                     83:                return fvalue;
                     84:        }
1.1       paf        85: };
                     86: 
                     87: #endif

E-mail: