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

1.1       paf         1: /*
1.4     ! paf         2:   $Id: pa_wcontext.h,v 1.3 2001/02/22 08:16:09 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
                     18:        /*virtual*/ const char *get_type() const { return "WContext"; }
                     19:        // wcontext: accumulated string
                     20:        /*virtual*/ String *get_string() { return &string; };
                     21:        // wcontext: transparent
                     22:        /*virtual*/ Value *get_element(const String& name) const { return check_value()->get_element(name); }
                     23:        // wcontext: transparent
                     24:        /*virtual*/ void put_element(const String& name, Value *avalue){ check_value()->put_element(name, avalue); }
                     25:        // wcontext: transparent
                     26:        /*virtual*/ Method *get_method(const String& name) const { return check_value()->get_method(name); }
                     27:        // wcontext: none yet | transparent
                     28:        /*virtual*/ VClass *get_class() const { return fvalue?fvalue->get_class():0; }
                     29:        // wcontext: none yet | transparent
                     30:        /*virtual*/ bool is_or_derived_from(VClass& ancestor) { return fvalue?fvalue->is_or_derived_from(ancestor):false; }
                     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.1       paf        46:        // if value.string!=0 writes string altogether[for showing class names, etc]
                     47:        // writes Value; raises an error if already
1.3       paf        48:        void write(Value *avalue) {
                     49:                if(!avalue)
                     50:                        return;
                     51: 
1.4     ! paf        52:                if(fvalue) // already have value?
        !            53:                        pool().exception().raise(0,0,  // don't need to construct twice
        !            54:                                0,
        !            55:                                "value already assigned");
        !            56:                else
        !            57:                        fvalue=avalue;
        !            58:                
1.3       paf        59:                String *string=avalue->get_string();
                     60:                if(string)
                     61:                        write(string);
                     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)
                     79:                        pool().exception().raise(0,0,
                     80:                                0,
                     81:                                "accessing wcontext without value");
                     82: 
                     83:                return fvalue;
                     84:        }
1.1       paf        85: };
                     86: 
                     87: #endif

E-mail: