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