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

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

E-mail: