12 #ifndef XPACE_TRANSLATE_STRING_NODE_H 13 #define XPACE_TRANSLATE_STRING_NODE_H 17 #include <QtCore/qstring.h> 26 # pragma warning(push) 27 # pragma warning(disable : 4355) 60 template <
typename LOC>
110 template<
typename LOC,
typename STR>
120 virtual bool operator()
128 TranslationError onError) :
134 template<
typename LOC,
typename STR>
144 virtual bool operator()
153 template<
typename LOC,
typename STR>
163 this->loc = this->sink->
add(name, BaseDataType::stringType<STR>().getBaseType(), ~0);
172 this->loc = sink->add(config, ~0);
176 (
const STR val)
override 178 return this->sink->
set(this->loc, val);
184 template<
typename LOC,
typename STR>
196 this->loc = this->sink->
add(this->
name, BaseDataType::btUint, ~0);
202 TranslationError onErr) :
206 this->loc = this->sink->
add(config, ~0);
210 (
const STR val)
override 215 return (buf.size() <= 1)
216 ? this->sink->
set(this->loc, buf[0])
217 : this->sink->
set(this->loc,
BytesRef(reinterpret_cast<byte*>(&buf[0]),
sizeof(buf[0]) * buf.size()));
222 std::vector<uint64> buf;
225 template<
typename LOC,
typename STR>
243 TranslationError onErr) :
247 this->loc = this->sink->
add(config, ~0);
250 virtual bool operator()
251 (
const STR val)
override 256 return (buf.size() <= 1)
257 ? this->sink->
set(this->loc,
int64(buf[0]))
258 : this->sink->
set(this->loc,
BytesRef(reinterpret_cast<byte*>(&buf[0]),
sizeof(buf[0]) * buf.size()));
263 std::vector<uint64> buf;
266 #ifdef XPACE_DECIMAL_FLOAT_H 269 template<
typename LOC,
typename STR>
276 TranslationError onErr) :
280 this->loc = this->sink->
add(config, ~0);
284 (
const STR val)
override 291 const uint precision;
297 template<
typename LOC,
typename STR>
304 TranslationError onErr) :
308 this->loc = this->sink->
add(this->
name, BaseDataType::btInt, ~0);
314 TranslationError onErr) :
320 this->loc = this->sink->
add(config, ~0);
323 virtual bool operator()
324 (
const STR val)
override 326 return this->sink->
set(this->loc,
DateTime(
String(val.data, val.length), format).toInt());
335 template<
typename LOC,
typename STR>
342 TranslationError onErr) :
346 has_port(matcher.add(
typename STR::charType(
'p'),
IntWrapper<_num>(&port))),
353 port_loc = this->sink->
add(
name +
".port", BaseDataType::btUint, ~0);
355 xnum_loc = this->sink->
add(
name +
".xnum", BaseDataType::btUint, ~0);
358 virtual bool operator()
359 (
const STR val)
override 363 if (matcher.match(val))
366 return (!has_addrs || !addrs.get(&n) || this->sink->
set(addrs_loc, n)) &&
367 (!has_port || !port.get(&n) || this->sink->
set(port_loc, n)) &&
368 (!has_xnum || !xnum.get(&n) || this->sink->
set(xnum_loc, n));
378 bool has_addrs, has_port, has_xnum;
379 uint addrs_loc, port_loc, xnum_loc;
403 return (cnt == 4) ? (*n = val,
true) :
false;
429 return (num == -1) ?
false : (*n = num,
true);
441 template<
typename LOC,
typename STR>
446 TranslationError onError)
470 case BaseDataType::btUint:
472 case BaseDataType::btInt:
474 #ifdef XPACE_DECIMAL_FLOAT_H 476 return new TranslateStringFloat<LOC, STR>(config,
sink, onError);
487 # pragma warning(pop)
const Xpace_Char16 Xpace_Data_Type type
virtual RET set(LOC location, int64 value)
Write an int64.
Copyright (C) 2012 Xpace, LLC.
Each high-level Xpace object has a Configuration.
static const char * FORMAT_TAG
A string, Unicode UTF-16 and reference-counted.
static const char * COUNT_TAG
A floatimg-point number with explicit mantissa and decimals TODO: normalize.
static const char * PRECISION_TAG
Copyright (C) 2012 Xpace, LLC.
type getDerivedType() const
Can't find a named value.
bool stringToInt(const String8 &str, uint radix, std::vector< uint64 > *val)
int64 getValueInt(const String &tag=String(), int64 def=0, bool *ok=0) const
String getValue(const String &tag=String()) const
get a node's value or an attribute search for attribute first, then child value
static TranslateString * create(const Configuration &config, Sink< LOC > *sink, TranslationError onError=default_on_error)
static const char * RADIX_TAG
static const char * NUMERAL_TAG
const Xpace_Char16 * name
Sink callbacks for table data.
bool stringToUint(const String8 &str, uint radix, std::vector< uint64 > *val)
static const char * DELIMS_TAG
static const char * SUBTYPE_TAG
static const char * SIZE_TAG
static const char * VECTOR_TAG
static const char * LENGTH_TAG
uint uint64 Xpace_Table_Sink * sink
virtual LOC add(const String &name, DerivedDataType type, LOC location, bool *added=0)
Add a field by name.
Translate content Input can be anything Output is to a Sink<LOC> so must be one of its supported type...
std::function< bool(utf16_t ch, const String &term)> TranslationError
Called on translation error.
Xpace project main namespace
class XPACE_EXPORT DateTime
bool default_on_error(utf16_t, const String &)
Default error handler.