Annotation of parser3/src/types/pa_wcontext.h, revision 1.34

1.12      paf         1: /**    @file
                      2:        Parser: write context class decl.
                      3: 
1.26      paf         4:        Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.27      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_WCONTEXT_H
                      9: #define PA_WCONTEXT_H
1.33      paf        10: 
1.34    ! paf        11: static const char* IDENT_WCONTEXT_H="$Date: pa_wcontext.h,v 1.33 2002/08/01 11:26:58 paf Exp $";
1.1       paf        12: 
                     13: #include "pa_value.h"
                     14: #include "pa_vstring.h"
                     15: #include "pa_vhash.h"
                     16: 
                     17: class Request;
                     18: 
1.29      paf        19: class StringOrValue {
                     20: public:
                     21:        StringOrValue() : fstring(0), fvalue(0) {}
                     22:        /// anticipating either String or Value [must not be 0&0]
1.30      paf        23:        StringOrValue(const String *astring, Value *avalue) : fstring(astring), fvalue(avalue) {}
                     24:        void set_string(const String& astring) { fstring=&astring; }
1.29      paf        25:        void set_value(Value& avalue) { fvalue=&avalue; }
1.31      paf        26:        const String *get_string() { return fstring; }
                     27:        Value *get_value() { return fvalue; }
1.29      paf        28:        Value& as_value() const {
                     29:                return *(fvalue?fvalue:new(fstring->pool()) VString(*fstring));
                     30:        }
                     31:        const String& as_string() const {
                     32:                return fstring?*fstring:fvalue->as_string();
                     33:        }
                     34: private:
1.30      paf        35:        const String *fstring;
1.29      paf        36:        Value *fvalue;
                     37: };
                     38: 
1.12      paf        39: /** Write context
                     40:        they do different write()s here, later picking up the result
                     41:        @see Request::wcontext
                     42: */
1.1       paf        43: class WContext : public Value {
1.18      paf        44:        friend class Request;
1.19      paf        45: 
1.1       paf        46: public: // Value
                     47: 
                     48:        const char *type() const { return "wcontext"; }
1.12      paf        49:        /// WContext: accumulated fstring
1.1       paf        50:        const String *get_string() { return &fstring; };
                     51: 
1.12      paf        52:        /// WContext: none yet | transparent
1.5       paf        53:        VStateless_class *get_class() { return fvalue?fvalue->get_class():0; }
1.12      paf        54:        /// WContext: transparent
1.1       paf        55:        VAliased *get_aliased() { return fvalue?fvalue->get_aliased():0; }
                     56: 
                     57: public: // WContext
                     58: 
1.12      paf        59:        /// appends a fstring to result
1.22      paf        60:        virtual void write(const String& astring, uchar lang);
1.6       paf        61: 
1.12      paf        62:        /// writes Value; raises an error if already
1.6       paf        63:        virtual void write(Value& avalue);
1.32      paf        64:        /// writes Value; raises an error if already, providing origin
                     65:        virtual void write(Value& avalue, const String* origin);
1.1       paf        66: 
1.12      paf        67:        /**
                     68:                if value is VString writes fstring,
                     69:                else writes Value; raises an error if already
                     70:        */
1.32      paf        71:        virtual void write(Value& avalue, uchar lang) {
                     72:                if(const String *fstring=avalue.get_string())
                     73:                        write(*fstring, lang);
                     74:                else
                     75:                        write(avalue);
                     76:        }
                     77:        /**
                     78:                if value is VString writes fstring,
                     79:                else writes Value; raises an error if already, providing origin
                     80:        */
                     81:        virtual void write(Value& avalue, uchar lang, const String* origin) {
                     82:                if(const String *fstring=avalue.get_string())
                     83:                        write(*fstring, lang);
                     84:                else
                     85:                        write(avalue, origin);
                     86:        }
1.1       paf        87: 
1.12      paf        88:        /**
                     89:                retrives the resulting value
1.29      paf        90:                that can be String if value==0 or the Value object
1.12      paf        91:                wmethod_frame first checks for $result and if there is one, returns it instead
                     92:        */
1.29      paf        93:        virtual StringOrValue result() {
                     94:                return fvalue?StringOrValue(0, fvalue):StringOrValue(&fstring, 0);
1.7       paf        95:        }
                     96: 
1.1       paf        97: public: // usage
                     98: 
1.16      parser     99:        WContext(Pool& apool, Value *avalue) : Value(apool), 
1.7       paf       100:                fstring(*new(apool) String(apool)),
1.20      paf       101:                fvalue(avalue) {
                    102:                flags.constructing=
                    103:                        flags.entered_class=
                    104:                        flags.entered_object=0;
1.1       paf       105:        }
                    106: 
1.20      paf       107:        void set_constructing(bool aconstructing) { flags.constructing=aconstructing?1:0; }
                    108:        bool get_constructing() { return flags.constructing!=0; }
1.19      paf       109: 
1.28      paf       110:        void set_in_expression(bool ain_expression) { flags.in_expression=ain_expression?1:0; }
                    111:        bool get_in_expression() { return flags.in_expression!=0; }
                    112: 
1.25      paf       113:        void set_somebody_entered_some_class() { flags.entered_class=1; }
1.20      paf       114:        bool get_somebody_entered_some_class() { return flags.entered_class!=0; }
1.19      paf       115: 
                    116:        void set_somebody_entered_some_object(bool aentered_object) {   
1.24      paf       117:                flags.entered_object=aentered_object?1:0; 
                    118:        }
1.20      paf       119:        bool get_somebody_entered_some_object() { return flags.entered_object!=0; }
1.14      paf       120: 
1.1       paf       121: protected:
1.7       paf       122:        String& fstring;
1.19      paf       123:        Value *fvalue;
1.1       paf       124: private:
1.19      paf       125:        struct {
1.20      paf       126:                int constructing:1;
1.28      paf       127:                int in_expression:1;
1.20      paf       128:                int entered_object:1;
                    129:                int entered_class:1;
                    130:        } flags;
1.1       paf       131: };
                    132: 
                    133: #endif

E-mail: