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

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

E-mail: