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

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: 
1.29    ! paf         7:        $Id: pa_wcontext.h,v 1.28 2002/02/18 15:21:01 paf Exp $
1.1       paf         8: */
                      9: 
                     10: #ifndef PA_WCONTEXT_H
                     11: #define PA_WCONTEXT_H
                     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]
        !            23:        StringOrValue(String *astring, Value *avalue) : fstring(astring), fvalue(avalue) {}
        !            24:        void set_value(Value& avalue) { fvalue=&avalue; }
        !            25:        Value& as_value() const {
        !            26:                return *(fvalue?fvalue:new(fstring->pool()) VString(*fstring));
        !            27:        }
        !            28:        const String& as_string() const {
        !            29:                return fstring?*fstring:fvalue->as_string();
        !            30:        }
        !            31: private:
        !            32:        String *fstring;
        !            33:        Value *fvalue;
        !            34: };
        !            35: 
1.12      paf        36: /** Write context
                     37:        they do different write()s here, later picking up the result
                     38:        @see Request::wcontext
                     39: */
1.1       paf        40: class WContext : public Value {
1.18      paf        41:        friend class Request;
1.19      paf        42: 
1.1       paf        43: public: // Value
                     44: 
                     45:        const char *type() const { return "wcontext"; }
1.12      paf        46:        /// WContext: accumulated fstring
1.1       paf        47:        const String *get_string() { return &fstring; };
                     48: 
1.12      paf        49:        /// WContext: none yet | transparent
1.5       paf        50:        VStateless_class *get_class() { return fvalue?fvalue->get_class():0; }
1.12      paf        51:        /// WContext: transparent
1.1       paf        52:        VAliased *get_aliased() { return fvalue?fvalue->get_aliased():0; }
                     53: 
                     54: public: // WContext
                     55: 
1.12      paf        56:        /// appends a fstring to result
1.22      paf        57:        virtual void write(const String& astring, uchar lang);
1.6       paf        58: 
1.12      paf        59:        /// writes Value; raises an error if already
1.6       paf        60:        virtual void write(Value& avalue);
1.1       paf        61: 
1.12      paf        62:        /**
                     63:                if value is VString writes fstring,
                     64:                else writes Value; raises an error if already
                     65:        */
1.22      paf        66:        virtual void write(Value& avalue, uchar lang);
1.1       paf        67: 
1.12      paf        68:        /**
                     69:                retrives the resulting value
1.29    ! paf        70:                that can be String if value==0 or the Value object
1.12      paf        71:                wmethod_frame first checks for $result and if there is one, returns it instead
                     72:        */
1.29    ! paf        73:        virtual StringOrValue result() {
        !            74:                return fvalue?StringOrValue(0, fvalue):StringOrValue(&fstring, 0);
1.7       paf        75:        }
                     76: 
1.1       paf        77: public: // usage
                     78: 
1.16      parser     79:        WContext(Pool& apool, Value *avalue) : Value(apool), 
1.7       paf        80:                fstring(*new(apool) String(apool)),
1.20      paf        81:                fvalue(avalue) {
                     82:                flags.constructing=
                     83:                        flags.entered_class=
                     84:                        flags.entered_object=0;
1.1       paf        85:        }
                     86: 
1.20      paf        87:        void set_constructing(bool aconstructing) { flags.constructing=aconstructing?1:0; }
                     88:        bool get_constructing() { return flags.constructing!=0; }
1.19      paf        89: 
1.28      paf        90:        void set_in_expression(bool ain_expression) { flags.in_expression=ain_expression?1:0; }
                     91:        bool get_in_expression() { return flags.in_expression!=0; }
                     92: 
1.25      paf        93:        void set_somebody_entered_some_class() { flags.entered_class=1; }
1.20      paf        94:        bool get_somebody_entered_some_class() { return flags.entered_class!=0; }
1.19      paf        95: 
                     96:        void set_somebody_entered_some_object(bool aentered_object) {   
1.24      paf        97:                flags.entered_object=aentered_object?1:0; 
                     98:        }
1.20      paf        99:        bool get_somebody_entered_some_object() { return flags.entered_object!=0; }
1.14      paf       100: 
1.1       paf       101: protected:
1.7       paf       102:        String& fstring;
1.19      paf       103:        Value *fvalue;
1.1       paf       104: private:
1.19      paf       105:        struct {
1.20      paf       106:                int constructing:1;
1.28      paf       107:                int in_expression:1;
1.20      paf       108:                int entered_object:1;
                    109:                int entered_class:1;
                    110:        } flags;
1.1       paf       111: };
                    112: 
                    113: #endif

E-mail: