Annotation of parser3/src/types/pa_value.C, revision 1.9.2.15.2.10
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.10! (paf 8:: static const char* IDENT_VALUE_C="$Date: 2003/03/25 12:10:09 $";
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.6 paf 33: Value* Value::base_object() { bark("(%s) 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.10 paf 36: bark("(%s) 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.2 paf 42: bark("(%s) 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
47: void Method::check_actual_numbered_params(
1.9.2.15.2.6 paf 48: Value& self, 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.6 paf 122: static void append_attribute_meaning(
123: String& result,
1.9.2.15.2.7 paf 124: Value& value, String::Language lang, bool forced) {
125: if(const String* string=value.get_string())
1.9.2.15.2.6 paf 126: result.append(*string, lang, forced);
1.9.2.1 paf 127: else
1.9.2.15.2.7 paf 128: if(Value* vdate=value.as(VDATE_TYPE, false)) {
1.9.2.15.2.10! (paf 129:: String::C attribute=date_attribute(static_cast<VDate&>(*vdate));
1.9.2.1 paf 130:
1.9.2.15.2.10! (paf 131:: result.append_help_length(attribute.str, attribute.length, String::L_CLEAN);
1.9.2.1 paf 132: } else
133: throw Exception("parser.runtime",
1.9.2.15.2.6 paf 134: &result,
1.9.2.1 paf 135: "trying to append here neither string nor date (%s)",
1.9.2.15.2.7 paf 136: value.type());
1.9.2.1 paf 137: }
138: #ifndef DOXYGEN
139: struct Attributed_meaning_info {
1.9.2.5 paf 140: String* header; // header line being constructed
1.9.2.15.2.4 paf 141: String::Language lang; // language in which to append to that line
1.9.2.1 paf 142: bool forced; // do they force that lang?
143: };
144: #endif
1.9.2.5 paf 145: static void append_attribute_subattribute(
1.9.2.15.2.6 paf 146: HashStringValue::key_type akey,
147: HashStringValue::value_type avalue,
148: Attributed_meaning_info *info) {
149: if(akey==VALUE_NAME)
1.9.2.1 paf 150: return;
151:
152: // ...; charset=windows1251
1.9.2.5 paf 153: *info->header << "; ";
1.9.2.15.2.6 paf 154: info->header->append(String(akey, String::L_TAINTED), info->lang, info->forced);
1.9.2.5 paf 155: *info->header << "=";
1.9.2.15.2.7 paf 156: append_attribute_meaning(*info->header, *avalue, info->lang, info->forced);
1.9.2.1 paf 157: }
1.9.2.15.2.1 paf 158: const String& attributed_meaning_to_string(
1.9.2.15.2.7 paf 159: Value& meaning,
1.9.2.15.2.6 paf 160: String::Language lang, bool forced) {
161: String& result=*new String;
1.9.2.15.2.7 paf 162: if(HashStringValue *hash=meaning.get_hash()) {
1.9.2.1 paf 163: // $value(value) $subattribute(subattribute value)
1.9.2.15.2.4 paf 164: if(Value* value=hash->get(value_name))
1.9.2.15.2.7 paf 165: append_attribute_meaning(result, *value, lang, forced);
1.9.2.1 paf 166:
1.9.2.15.2.6 paf 167: Attributed_meaning_info attributed_meaning_info={&result, lang};
1.9.2.1 paf 168: hash->for_each(append_attribute_subattribute, &attributed_meaning_info);
169: } else // result value
1.9.2.15.2.6 paf 170: append_attribute_meaning(result, meaning, lang, forced);
1.9.2.1 paf 171:
172: return result;
173: }
E-mail: