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