00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "smart/varmap.hpp"
00029 #include "smart/varvalue.hpp"
00030 #include "base/string.hpp"
00031 #include "base/memory.hpp"
00032
00033
00034 BEGIN_TERIMBER_NAMESPACE
00035 #pragma pack(4)
00036
00037
00038
00039
00040 main_map_key::main_map_key(vt_types type, const var_value& val, variant_factory* factory)
00041 {
00042 if (factory)
00043 {
00044 factory->clone(type, _var_res._val, val);
00045 }
00046 else
00047 {
00048 _var_res._val = val;
00049 }
00050 }
00051
00052
00053
00054
00055 main_map_key::main_map_key(const char* val, variant_factory* factory)
00056 {
00057 _var_res._key._offsets = 0;
00058
00059 if (factory)
00060 {
00061 _var_res._key._res = 0;
00062
00063 var_value val_in, val_out;
00064 val_in._not_null = val != 0;
00065 val_in._value.strVal = val;
00066
00067 factory->clone(vt_string, val_out, val_in);
00068
00069 _var_res._key._res = val_out._value.strVal;
00070
00071 ub1_t offlen = 0;
00072 ub4_t offsets[0xff];
00073
00074
00075 const char* begin = val;
00076 bool space_found = false;
00077
00078 while (val && *val == ' ')
00079 ++val;
00080
00081 while (val && *val && offlen < 0xff)
00082 {
00083
00084
00085 switch (*val)
00086 {
00087 case 0x20:
00088 case 0x09:
00089 case 0x0D:
00090 case 0x0A:
00091 if (!space_found)
00092 space_found = true;
00093 break;
00094 default:
00095 if (space_found)
00096 {
00097 offsets[offlen] = (ub4_t)(val - begin);
00098 space_found = false;
00099 ++offlen;
00100 }
00101 }
00102
00103 ++val;
00104 }
00105
00106 if (offlen)
00107 {
00108
00109 factory->create(vt_numeric, val_out, sizeof(ub4_t) * (offlen + 1));
00110 ub4_t* p = (ub4_t*)val_out._value.bufVal;
00111
00112 memcpy(p + 1, offsets, sizeof(ub4_t) * offlen);
00113 *p = offlen;
00114 _var_res._key._offsets = p;
00115 }
00116 }
00117 else
00118 {
00119 _var_res._key._res = val;
00120 }
00121 }
00122
00123 main_map_key::main_map_key(size_t fuzzyident, const char* val, variant_factory* factory)
00124 {
00125 _var_res._ngram._fuzzy_key = fuzzyident;
00126
00127 if (factory)
00128 {
00129 _var_res._ngram._res = 0;
00130
00131 var_value val_in, val_out;
00132 val_in._not_null = val != 0;
00133 val_in._value.strVal = val;
00134
00135 factory->clone(vt_string, val_out, val_in);
00136
00137 _var_res._ngram._res = val_out._value.strVal;
00138 }
00139 else
00140 {
00141 _var_res._key._res = val;
00142 }
00143 }
00144
00145 main_map_key::main_map_key(const main_map_key& x)
00146 {
00147 memcpy(&_var_res, &x._var_res, sizeof(var_key));
00148 }
00149
00150 #pragma pack()
00151 END_TERIMBER_NAMESPACE