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

1.12      paf         1: /**    @file
                      2:        Parser: write context class decl.
                      3: 
1.43      paf         4:        Copyright (c) 2001-2003 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.45    ! paf        11: static const char * const IDENT_WCONTEXT_H="$Date: 2003/11/20 16:32:12 $";
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.43      paf        23:        StringOrValue(const String* astring, Value* avalue) : fstring(astring), fvalue(avalue) {}
1.30      paf        24:        void set_string(const String& astring) { fstring=&astring; }
1.29      paf        25:        void set_value(Value& avalue) { fvalue=&avalue; }
1.43      paf        26:        const String* get_string() { return fstring; }
                     27:        Value* get_value() { return fvalue; }
1.29      paf        28:        Value& as_value() const {
1.43      paf        29:                Value* result=fvalue?fvalue:new VString(*fstring);
                     30:                return *result;
1.29      paf        31:        }
                     32:        const String& as_string() const {
                     33:                return fstring?*fstring:fvalue->as_string();
                     34:        }
                     35: private:
1.43      paf        36:        const String* fstring;
                     37:        Value* fvalue;
1.29      paf        38: };
                     39: 
1.12      paf        40: /** Write context
                     41:        they do different write()s here, later picking up the result
                     42:        @see Request::wcontext
                     43: */
1.43      paf        44: class WContext: public Value {
1.18      paf        45:        friend class Request;
1.19      paf        46: 
1.1       paf        47: public: // Value
                     48: 
1.43      paf        49:        override const char* type() const { return "wcontext"; }
1.12      paf        50:        /// WContext: accumulated fstring
1.43      paf        51:        override const String* get_string() { return &fstring; };
1.1       paf        52: 
1.12      paf        53:        /// WContext: none yet | transparent
1.43      paf        54:        override VStateless_class *get_class() { return fvalue?fvalue->get_class():0; }
1.1       paf        55: 
                     56: public: // WContext
                     57: 
1.12      paf        58:        /// appends a fstring to result
1.43      paf        59:        virtual void write(const String& astring, String::Language alang) {
                     60:                fstring.append(astring, alang);
1.35      paf        61:        }
1.32      paf        62:        /// writes Value; raises an error if already, providing origin
1.43      paf        63:        virtual void write(Value& avalue);
1.1       paf        64: 
1.12      paf        65:        /**
                     66:                if value is VString writes fstring,
1.32      paf        67:                else writes Value; raises an error if already, providing origin
                     68:        */
1.43      paf        69:        void write(
                     70:                Value& avalue, String::Language alang) {
                     71:                if(const String* fstring=avalue.get_string())
                     72:                        write(*fstring, alang);
1.32      paf        73:                else
1.43      paf        74:                        write(avalue);
1.32      paf        75:        }
1.1       paf        76: 
1.12      paf        77:        /**
                     78:                retrives the resulting value
1.29      paf        79:                that can be String if value==0 or the Value object
1.12      paf        80:                wmethod_frame first checks for $result and if there is one, returns it instead
                     81:        */
1.29      paf        82:        virtual StringOrValue result() {
                     83:                return fvalue?StringOrValue(0, fvalue):StringOrValue(&fstring, 0);
1.7       paf        84:        }
                     85: 
1.43      paf        86:        void attach_junction(Junction* ajunction) {
                     87:                junctions+=ajunction;
1.39      paf        88:        }
                     89: 
1.1       paf        90: public: // usage
                     91: 
1.43      paf        92:        WContext(Value* avalue, WContext *aparent):
                     93:                fstring(*new String),
1.39      paf        94:                fvalue(avalue),
1.43      paf        95:                fparent(aparent) {
1.20      paf        96:                flags.constructing=
                     97:                        flags.entered_class=
                     98:                        flags.entered_object=0;
1.1       paf        99:        }
1.44      paf       100:        virtual ~WContext() {
1.39      paf       101:                detach_junctions();
                    102:        }
1.1       paf       103: 
1.20      paf       104:        void set_constructing(bool aconstructing) { flags.constructing=aconstructing?1:0; }
                    105:        bool get_constructing() { return flags.constructing!=0; }
1.19      paf       106: 
1.28      paf       107:        void set_in_expression(bool ain_expression) { flags.in_expression=ain_expression?1:0; }
                    108:        bool get_in_expression() { return flags.in_expression!=0; }
                    109: 
1.25      paf       110:        void set_somebody_entered_some_class() { flags.entered_class=1; }
1.20      paf       111:        bool get_somebody_entered_some_class() { return flags.entered_class!=0; }
1.14      paf       112: 
1.39      paf       113: private:
                    114: 
                    115:        void detach_junctions(); 
                    116: 
1.1       paf       117: protected:
1.7       paf       118:        String& fstring;
1.43      paf       119:        Value* fvalue;
1.1       paf       120: private:
1.19      paf       121:        struct {
1.20      paf       122:                int constructing:1;
1.28      paf       123:                int in_expression:1;
1.20      paf       124:                int entered_object:1;
                    125:                int entered_class:1;
                    126:        } flags;
1.39      paf       127: 
                    128: private:
                    129: 
                    130:        WContext *fparent;
1.43      paf       131:        Array<Junction*>  junctions;
1.38      paf       132: 
1.1       paf       133: };
                    134: 
                    135: #endif

E-mail: