Annotation of parser3/src/types/pa_value.h, revision 1.119.6.3

1.22      paf         1: /** @file
1.110     paf         2:        Parser: Value, Method, Junction .
1.24      paf         3: 
1.119.6.1  paf         4:        Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.79      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_VALUE_H
                      9: #define PA_VALUE_H
1.87      paf        10: 
1.119.6.3! paf        11: static const char * const IDENT_VALUE_H="$Date: 2005/08/09 08:12:50 $";
1.1       paf        12: 
                     13: #include "pa_string.h"
                     14: #include "pa_array.h"
                     15: #include "pa_exception.h"
                     16: 
1.99      paf        17: // forwards
                     18: 
1.9       paf        19: class VStateless_class;
1.1       paf        20: class WContext;
1.110     paf        21: class Request; class Request_charsets;
1.17      paf        22: class Junction;
                     23: class Method;
1.110     paf        24: template<typename K, typename V> class Hash;
                     25: class Value;
1.113     paf        26: typedef Hash<const String::Body, Value*> HashStringValue; 
                     27: typedef Hash<const String::Body, PA_Object*> HashStringObject;
1.110     paf        28: typedef Array<Value*> ArrayValue;
1.64      parser     29: class MethodParams;
1.93      paf        30: class VObject;
1.99      paf        31: class VMethodFrame;
1.110     paf        32: class VFile;
                     33: class Table;
1.1       paf        34: 
1.31      paf        35: ///    grandfather of all @a values in @b Parser
1.110     paf        36: class Value: public PA_Object {
1.1       paf        37: public: // Value
                     38: 
1.106     paf        39:        /// value type, used for error reporting and 'is' expression operator
1.110     paf        40:        virtual const char* type() const =0;
1.89      paf        41: 
1.91      paf        42:        /** remember derived class instance 
                     43:            - VObject: the only client
                     44:        */
1.110     paf        45:        virtual VObject* set_derived(VObject* /*aderived*/);
1.91      paf        46: 
1.89      paf        47:        /**
1.95      paf        48:                all except VObject/VClass: this if @atype eq type()
                     49:                VObject/VClass: can locate parent class by it's type
1.89      paf        50:        */
1.111     paf        51:        virtual Value* as(const char* atype, bool /*looking_up*/) {
1.96      paf        52:                return atype && strcmp(type(), atype)==0?this:0;
1.89      paf        53:        }
1.97      paf        54:        /// type checking helper, uses Value::as
1.110     paf        55:        bool is(const char* atype) { return as(atype, false)!=0; }
1.59      parser     56:        
1.106     paf        57:        /// is this value defined?
1.38      paf        58:        virtual bool is_defined() const { return true; }
1.59      parser     59:        
1.106     paf        60:        /// is this value string?
1.38      paf        61:        virtual bool is_string() const { return false; }
1.119.6.2  paf        62: 
                     63:        /// is this value number?
1.119.6.3! paf        64:        virtual bool is_evaluated_expr() const { return false; }
1.119.6.2  paf        65: 
1.106     paf        66:        /// what's the meaning of this value in context of expression?
1.110     paf        67:        virtual Value& as_expr_result(bool /*return_string_as_is*/=false) {
1.112     paf        68:                return *bark("is '%s', can not be used in expression"); 
1.34      paf        69:        }
1.59      parser     70:        
1.110     paf        71:        
                     72: 
                     73:        /** extract HashStringValue if any
                     74:                WARNING: FOR LOCAL USE ONLY, THIS POINTER IS NOT TO PASS TO ANYBODY!
                     75:        */
                     76:        virtual HashStringValue* get_hash() { return 0; }
1.59      parser     77:        
1.106     paf        78:        /// extract const String
1.110     paf        79:        virtual const String* get_string() { return 0; }
1.59      parser     80:        
1.106     paf        81:        /// extract double
1.110     paf        82:        virtual double as_double() const { bark("is '%s', it does not have numerical (double) value"); return 0; }
1.59      parser     83:        
1.106     paf        84:        /// extract integer
1.110     paf        85:        virtual int as_int () const { bark("is '%s', it does not have numerical (int) value"); return 0; }
1.59      parser     86: 
1.106     paf        87:        /// extract bool
1.110     paf        88:        virtual bool as_bool() const { bark("is '%s', it does not have logical value"); return 0; }
1.59      parser     89:        
1.106     paf        90:        /// extract file
1.110     paf        91:        virtual VFile* as_vfile(String::Language lang=String::L_UNSPECIFIED, 
                     92:                const Request_charsets* charsets=0);
1.59      parser     93:        
1.106     paf        94:        /// extract Junction
1.110     paf        95:        virtual Junction* get_junction();
1.59      parser     96:        
1.93      paf        97:        /** extract base object of Value
                     98:                @return for
                     99:                - VObject: fbase
                    100:        */
1.110     paf       101:        virtual Value* base_object();
1.93      paf       102:        
1.106     paf       103:        /// extract Value element
1.110     paf       104:        virtual Value* get_element(const String& /*aname*/, Value& /*aself*/, bool /*looking_up*/);
1.92      paf       105: 
1.106     paf       106:        /// store Value element under @a name
1.110     paf       107:        virtual bool put_element(const String& aname, Value* /*avalue*/, bool /*areplace*/) { 
1.65      parser    108:                // to prevent modification of system classes,
                    109:                // created at system startup, and not having exception
                    110:                // handler installed, we neet to bark using request.pool
1.112     paf       111:                bark("element can not be stored to %s", &aname); 
1.93      paf       112:                return false;
1.65      parser    113:        }
1.59      parser    114:        
1.106     paf       115:        /// extract VStateless_class
1.85      paf       116:        virtual VStateless_class *get_class()=0;
1.107     paf       117: 
                    118:        /// extract VStateless_class
                    119:        virtual VStateless_class *get_last_derived_class() {
                    120:                return get_class();
                    121:        };
1.108     paf       122:        /// extract base object or class of Value, if any
1.110     paf       123:        virtual Value* base() { return 0; }
1.32      paf       124: 
1.106     paf       125:        /// extract VTable
1.110     paf       126:        virtual Table* get_table() { return 0; }
1.1       paf       127: 
                    128: public: // usage
                    129: 
1.26      paf       130:        /// @return sure String. if it doesn't have string value barks
1.1       paf       131:        const String& as_string() {
1.110     paf       132:                const String* result=get_string(); 
1.1       paf       133:                if(!result)
1.110     paf       134:                        bark("is '%s', it has no string representation");
1.6       paf       135: 
1.1       paf       136:                return *result;
                    137:        }
                    138: 
1.6       paf       139: protected: 
1.1       paf       140: 
1.22      paf       141:        /// throws exception specifying bark-reason and name() type() of problematic value
1.112     paf       142:        Value* bark(const char *reason, const String *problem_source=0) const {
1.117     paf       143:                if(this) // removing warnings on unreachable code
                    144:                        throw Exception("parser.runtime",
                    145:                                problem_source, 
                    146:                                reason, type());
                    147: 
                    148:                return 0;
1.1       paf       149:        }
                    150: 
1.17      paf       151: };
1.110     paf       152:        
1.48      paf       153: 
                    154: /**
1.110     paf       155:        $content-type[text/html] -> 
                    156:                content-type: text/html
                    157:        $content-type[$value[text/html] charset[windows-1251]] -> 
                    158:                content-type: text/html; charset=windows-1251
1.48      paf       159: */
1.110     paf       160: const String& attributed_meaning_to_string(Value& meaning, 
                    161:                                           String::Language lang, 
                    162:                                           bool forced=false);
                    163: 
                    164: // defines
                    165: 
                    166: ///@{common field names
                    167: #define CHARSET_NAME "charset"
                    168: #define VALUE_NAME "value"
1.114     paf       169: #define EXPIRES_NAME "expires"
1.110     paf       170: #define CONTENT_TYPE_NAME "content-type"
1.119     paf       171: #define NAME_NAME "name"
1.110     paf       172: //@}
                    173: 
                    174: ///@{common field names
                    175: extern const String value_name;
1.114     paf       176: extern const String expires_name;
1.110     paf       177: extern const String content_type_name;
                    178: extern const String name_name;
                    179: ///@}
1.1       paf       180: 
                    181: #endif

E-mail: