Annotation of parser3/src/types/pa_value.C, revision 1.18.8.1
1.1 paf 1: /** @file
2: Parser: Value class.
3:
1.18.8.1! paf 4: Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.1 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.2 paf 6: */
1.1 paf 7:
1.18.8.1! paf 8: static const char * const IDENT_VALUE_C="$Date: 2004/09/01 09:16:58 $";
1.1 paf 9:
10: #include "pa_value.h"
11: #include "pa_vstateless_class.h"
1.4 paf 12: #include "pa_vmethod_frame.h"
1.10 paf 13: #include "pa_vdate.h"
14: #include "pa_vobject.h"
15:
16: // globals
17:
18: const String name_name(NAME_NAME);
19:
20: const String value_name(VALUE_NAME);
1.12 paf 21: const String expires_name(EXPIRES_NAME);
1.10 paf 22: const String content_type_name(CONTENT_TYPE_NAME);
23:
24: // methods
25:
26: VObject* Value::set_derived(VObject* /*aderived*/) { return 0; }
27:
28: Junction* Value::get_junction() { return 0; }
29:
1.11 paf 30: Value* Value::base_object() { return bark("is '%s', it has no base object"); }
1.10 paf 31:
32: Value* Value::get_element(const String& /*aname*/, Value& /*aself*/, bool /*looking_up*/) {
1.11 paf 33: return bark("is '%s', it has no elements");
1.10 paf 34: }
35:
36:
37: VFile* Value::as_vfile(String::Language /*lang*/, const Request_charsets* /*charsets*/) {
1.11 paf 38: bark("is '%s', it does not have file value"); return 0;
1.10 paf 39: }
1.1 paf 40:
41: /// call this before invoking to ensure proper actual numbered params count
1.10 paf 42: void Method::check_actual_numbered_params(Value& self,
43: MethodParams* actual_numbered_params) const {
1.1 paf 44:
1.10 paf 45: int actual_count=actual_numbered_params?actual_numbered_params->count():0;
1.1 paf 46: if(actual_count<min_numbered_params_count) // not proper count? bark
47: throw Exception("parser.runtime",
1.10 paf 48: 0,
1.1 paf 49: "native method of %s (%s) accepts minimum %d parameter(s) (%d present)",
1.8 paf 50: self.get_class()->name_cstr(),
51: self.type(),
1.1 paf 52: min_numbered_params_count,
53: actual_count);
54:
55: }
1.4 paf 56:
1.10 paf 57: Junction::Junction(Value& aself,
58: const Method* amethod,
59: VMethodFrame* amethod_frame,
60: Value* arcontext,
61: WContext* awcontext,
62: ArrayOperation* acode): self(aself),
1.7 paf 63: method(amethod),
1.4 paf 64: method_frame(amethod_frame),
65: rcontext(arcontext),
66: wcontext(awcontext),
67: code(acode) {
1.5 paf 68: if(wcontext)
1.10 paf 69: wcontext->attach_junction(this);
1.4 paf 70: }
71:
1.5 paf 72: void Junction::reattach(WContext *new_wcontext) {
1.17 paf 73: if(new_wcontext) {
74: assert(wcontext!=new_wcontext);
1.5 paf 75: wcontext=new_wcontext;
1.17 paf 76: wcontext->attach_junction(this);
77: } else {
1.5 paf 78: method_frame=0;
79: rcontext=0;
80: wcontext=0;
81: }
1.4 paf 82: }
83:
1.10 paf 84: // attributed meaning
85:
86: static String::C date_attribute(const VDate& vdate) {
87: /// http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3
88: const char month_names[12][4]={
89: "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
90: const char days[7][4]={
91: "Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
92:
93: time_t when=vdate.get_time();
94: struct tm *tms=gmtime(&when);
95: if(!tms)
96: throw Exception(0,
97: 0,
1.15 paf 98: "bad time in attribute value (seconds from epoch=%u)", when);
1.10 paf 99:
100: char *buf=new(PointerFreeGC) char[MAX_STRING];
101: return String::C(buf,
102: snprintf(buf, MAX_STRING, "%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT",
103: days[tms->tm_wday],
104: tms->tm_mday,month_names[tms->tm_mon],tms->tm_year+1900,
105: tms->tm_hour,tms->tm_min,tms->tm_sec));
106: }
107: static void append_attribute_meaning(String& result,
108: Value& value, String::Language lang, bool forced) {
109: if(const String* string=value.get_string())
110: result.append(*string, lang, forced);
111: else
112: if(Value* vdate=value.as(VDATE_TYPE, false)) {
113: String::C attribute=date_attribute(static_cast<VDate&>(*vdate));
114:
115: result.append_help_length(attribute.str, attribute.length, String::L_CLEAN);
116: } else
117: throw Exception("parser.runtime",
118: &result,
119: "trying to append here neither string nor date (%s)",
120: value.type());
121: }
122: #ifndef DOXYGEN
123: struct Attributed_meaning_info {
124: String* header; // header line being constructed
125: String::Language lang; // language in which to append to that line
126: bool forced; // do they force that lang?
127: };
128: #endif
129: static void append_attribute_subattribute(HashStringValue::key_type akey,
130: HashStringValue::value_type avalue,
131: Attributed_meaning_info *info) {
132: if(akey==VALUE_NAME)
133: return;
134:
135: // ...; charset=windows1251
136: *info->header << "; ";
137: info->header->append(String(akey, String::L_TAINTED), info->lang, info->forced);
138: *info->header << "=";
139: append_attribute_meaning(*info->header, *avalue, info->lang, info->forced);
140: }
141: const String& attributed_meaning_to_string(Value& meaning,
142: String::Language lang, bool forced) {
143: String& result=*new String;
144: if(HashStringValue *hash=meaning.get_hash()) {
145: // $value(value) $subattribute(subattribute value)
146: if(Value* value=hash->get(value_name))
147: append_attribute_meaning(result, *value, lang, forced);
148:
1.14 paf 149: Attributed_meaning_info attributed_meaning_info={&result, lang, false};
1.10 paf 150: hash->for_each(append_attribute_subattribute, &attributed_meaning_info);
151: } else // result value
152: append_attribute_meaning(result, meaning, lang, forced);
153:
154: return result;
155: }
E-mail: