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