Annotation of parser3/src/types/pa_value.C, revision 1.28
1.1 paf 1: /** @file
2: Parser: Value class.
3:
1.26 misha 4: Copyright (c) 2001-2009 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.28 ! misha 8: static const char * const IDENT_VALUE_C="$Date: 2009-07-13 02:18:41 $";
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: Junction* Value::get_junction() { return 0; }
27:
1.28 ! misha 28: Value* Value::get_element(const String& /*aname*/) {
1.11 paf 29: return bark("is '%s', it has no elements");
1.10 paf 30: }
31:
32: VFile* Value::as_vfile(String::Language /*lang*/, const Request_charsets* /*charsets*/) {
1.11 paf 33: bark("is '%s', it does not have file value"); return 0;
1.10 paf 34: }
1.1 paf 35:
36: /// call this before invoking to ensure proper actual numbered params count
1.10 paf 37: void Method::check_actual_numbered_params(Value& self,
1.28 ! misha 38: MethodParams* actual_numbered_params) const {
1.1 paf 39:
1.10 paf 40: int actual_count=actual_numbered_params?actual_numbered_params->count():0;
1.1 paf 41: if(actual_count<min_numbered_params_count) // not proper count? bark
1.22 misha 42: throw Exception(PARSER_RUNTIME,
1.10 paf 43: 0,
1.1 paf 44: "native method of %s (%s) accepts minimum %d parameter(s) (%d present)",
1.8 paf 45: self.get_class()->name_cstr(),
46: self.type(),
1.1 paf 47: min_numbered_params_count,
48: actual_count);
49:
50: }
1.4 paf 51:
1.10 paf 52: // attributed meaning
53:
54: static String::C date_attribute(const VDate& vdate) {
55: time_t when=vdate.get_time();
56: struct tm *tms=gmtime(&when);
57: if(!tms)
1.25 misha 58: throw Exception(DATE_RANGE_EXCEPTION_TYPE,
1.10 paf 59: 0,
1.15 paf 60: "bad time in attribute value (seconds from epoch=%u)", when);
1.24 misha 61: return date_gmt_string(tms);
62: }
1.10 paf 63:
64: static void append_attribute_meaning(String& result,
1.28 ! misha 65: Value& value, String::Language lang, bool forced) {
1.10 paf 66: if(const String* string=value.get_string())
67: result.append(*string, lang, forced);
68: else
1.28 ! misha 69: if(Value* vdate=value.as(VDATE_TYPE)) {
1.10 paf 70: String::C attribute=date_attribute(static_cast<VDate&>(*vdate));
71:
72: result.append_help_length(attribute.str, attribute.length, String::L_CLEAN);
73: } else
1.22 misha 74: throw Exception(PARSER_RUNTIME,
1.10 paf 75: &result,
76: "trying to append here neither string nor date (%s)",
77: value.type());
78: }
79: #ifndef DOXYGEN
80: struct Attributed_meaning_info {
81: String* header; // header line being constructed
82: String::Language lang; // language in which to append to that line
83: bool forced; // do they force that lang?
1.23 misha 84: bool allow_bool; // allow bool types during print attributes
1.10 paf 85: };
86: #endif
87: static void append_attribute_subattribute(HashStringValue::key_type akey,
88: HashStringValue::value_type avalue,
89: Attributed_meaning_info *info) {
90: if(akey==VALUE_NAME)
91: return;
92:
1.27 misha 93: if(avalue->is_bool() && (!info->allow_bool || avalue->as_bool()==false))
94: return;
95:
1.10 paf 96: // ...; charset=windows1251
97: *info->header << "; ";
98: info->header->append(String(akey, String::L_TAINTED), info->lang, info->forced);
1.27 misha 99: if(!avalue->is_bool()){
1.21 misha 100: *info->header << "=";
101: append_attribute_meaning(*info->header, *avalue, info->lang, info->forced);
102: }
1.10 paf 103: }
104: const String& attributed_meaning_to_string(Value& meaning,
1.21 misha 105: String::Language lang, bool forced, bool allow_bool) {
1.10 paf 106: String& result=*new String;
107: if(HashStringValue *hash=meaning.get_hash()) {
108: // $value(value) $subattribute(subattribute value)
109: if(Value* value=hash->get(value_name))
110: append_attribute_meaning(result, *value, lang, forced);
111:
1.21 misha 112: Attributed_meaning_info attributed_meaning_info={&result, lang, false, allow_bool};
1.20 paf 113: hash->for_each<Attributed_meaning_info*>(append_attribute_subattribute, &attributed_meaning_info);
1.10 paf 114: } else // result value
115: append_attribute_meaning(result, meaning, lang, forced);
116:
117: return result;
118: }
E-mail: