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