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