Annotation of parser3/src/types/pa_value.h, revision 1.109.2.25.2.2
1.22 paf 1: /** @file
1.109.2.11 paf 2: Parser: Value, Method, Junction .
1.24 paf 3:
1.109.2.14 paf 4: Copyright (c) 2001-2003 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.109.2.25.2. (paf 11:): static const char* IDENT_VALUE_H="$Date: 2003/03/18 15:14:20 $";
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;
21: class Request;
1.109.2.4 paf 22: class Junction; DECLARE_OBJECT_PTR(Junction);
1.109.2.12 paf 23: class Method; DECLARE_OBJECT_PTR(Method);
1.109.2.2 paf 24: template<typename K, typename V> class Hash;
1.109.2.12 paf 25: class Value; DECLARE_OBJECT_PTR(Value);
1.109.2.25.2. (paf 26:): typedef Hash<String* , ValuePtr> HashStringValue; DECLARE_OBJECT_PTR(HashStringValue);
27:): typedef Hash<String* , PA_Object* > HashStringObject; DECLARE_OBJECT_PTR(HashStringObject);
1.109.2.17 paf 28: typedef Array<ValuePtr> ArrayValue; DECLARE_OBJECT_PTR(ArrayValue);
1.64 parser 29: class MethodParams;
1.109.2.4 paf 30: class VObject; DECLARE_OBJECT_PTR(VObject);
1.99 paf 31: class VMethodFrame;
1.109.2.15 paf 32: class VFile; DECLARE_OBJECT_PTR(VFile);
33: class Table;
1.1 paf 34:
1.31 paf 35: /// grandfather of all @a values in @b Parser
1.109.2.11 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.109.2.14 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.109.2.25 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.109.2.18 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.109.2.14 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.59 parser 62:
1.106 paf 63: /// what's the meaning of this value in context of expression?
1.109.2.19 paf 64: virtual ValuePtr as_expr_result(bool /*return_string_as_is*/=false) {
65: bark("(%s) can not be used in expression"); return ValuePtr(0);
1.34 paf 66: }
1.59 parser 67:
1.109.2.19 paf 68:
69:
1.109.2.7 paf 70: /** extract HashStringValue if any
71: WARNING: FOR LOCAL USE ONLY, THIS POINTER IS NOT TO PASS TO ANYBODY!
72: */
1.109.2.25.2. (paf 73:): virtual HashStringValue* get_hash(const String& /*source*/) { return 0; }
1.59 parser 74:
1.106 paf 75: /// extract const String
1.109.2.25.2. (paf 76:): virtual const String* get_string() { return 0; }
1.59 parser 77:
1.106 paf 78: /// extract double
1.72 parser 79: virtual double as_double() const { bark("(%s) does not have numerical (double) value"); return 0; }
1.59 parser 80:
1.106 paf 81: /// extract integer
1.72 parser 82: virtual int as_int () const { bark("(%s) does not have numerical (int) value"); return 0; }
1.59 parser 83:
1.106 paf 84: /// extract bool
1.72 parser 85: virtual bool as_bool() const { bark("(%s) does not have logical value"); return 0; }
1.59 parser 86:
1.106 paf 87: /// extract file
1.109.2.25.2. (paf 88:): virtual VFilePtr as_vfile(String::Untaint_lang lang=String::UL_UNSPECIFIED,
1.109.2.4 paf 89: bool origins_mode=false);
1.59 parser 90:
1.106 paf 91: /// extract Junction
1.109.2.19 paf 92: virtual JunctionPtr get_junction();
1.59 parser 93:
1.93 paf 94: /** extract base object of Value
95: @return for
96: - VObject: fbase
97: */
1.109.2.19 paf 98: virtual ValuePtr base_object();
1.93 paf 99:
1.106 paf 100: /// extract Value element
1.109.2.25.2. (paf 101:): virtual ValuePtr get_element(const String& /*aname*/, Value& /*aself*/, bool /*looking_up*/);
1.92 paf 102:
1.106 paf 103: /// store Value element under @a name
1.109.2.25.2. (paf 104:): virtual bool put_element(const String& aname, ValuePtr /*avalue*/, bool /*areplace*/) {
1.65 parser 105: // to prevent modification of system classes,
106: // created at system startup, and not having exception
107: // handler installed, we neet to bark using request.pool
108: bark("(%s) does not accept elements",
1.109.2.25.2. (paf 109:): "element can not be stored to %s", &aname);
1.93 paf 110: return false;
1.65 parser 111: }
1.59 parser 112:
1.106 paf 113: /// extract VStateless_class
1.85 paf 114: virtual VStateless_class *get_class()=0;
1.107 paf 115:
116: /// extract VStateless_class
117: virtual VStateless_class *get_last_derived_class() {
118: return get_class();
119: };
1.108 paf 120: /// extract base object or class of Value, if any
1.109.2.24 paf 121: virtual ValuePtr base() { return ValuePtr(0); }
1.32 paf 122:
1.106 paf 123: /// extract VTable
1.109.2.15 paf 124: virtual Table* get_table() { return 0; }
1.1 paf 125:
126: public: // usage
127:
1.26 paf 128: /// @return sure String. if it doesn't have string value barks
1.109.2.25.2. (paf 129:): const String& as_string() {
130:): const String* result=get_string();
131:): if(!result)
1.35 paf 132: bark("(%s) has no string representation");
1.6 paf 133:
1.109.2.25.2. (paf 134:): return *result;
1.1 paf 135: }
136:
1.6 paf 137: protected:
1.1 paf 138:
1.22 paf 139: /// throws exception specifying bark-reason and name() type() of problematic value
1.65 parser 140: void bark(char *reason,
1.109.2.25.2. (paf 141:): const char* alt_reason=0) const {
1.80 paf 142: throw Exception("parser.runtime",
1.84 paf 143: problem_source,
144: alt_reason?alt_reason:reason, type());
1.1 paf 145: }
146:
1.17 paf 147: };
1.39 paf 148:
1.109.2.1 paf 149:
150: /**
151: $content-type[text/html] ->
152: content-type: text/html
153: $content-type[$value[text/html] charset[windows-1251]] ->
154: content-type: text/html; charset=windows-1251
155: */
1.109.2.25.2. (paf 156:): const String& attributed_meaning_to_string(
1.109.2.17 paf 157: ValuePtr meaning,
158: String::Untaint_lang lang=String::UL_UNSPECIFIED, bool forced=false);
1.109.2.7 paf 159:
160: // defines
161:
162: ///@{common field names
163: #define CHARSET_NAME "charset"
1.109.2.8 paf 164: #define VALUE_NAME "value"
1.109.2.9 paf 165: #define CONTENT_TYPE_NAME "content-type"
166: //@}
1.109.2.8 paf 167:
168: ///@{common field names
1.109.2.25.2. (paf 169:): extern const String& value_name;
170:): extern const String& content_type_name;
171:): extern const String& name_name;
1.109.2.7 paf 172: ///@}
1.1 paf 173:
174: #endif
E-mail: