1 //
2 // VarHolder.h
3 //
4 // Library: Foundation
5 // Package: Dynamic
6 // Module:  VarHolder
7 //
8 // Definition of the VarHolder class.
9 //
10 // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
11 // and Contributors.
12 //
13 // SPDX-License-Identifier:	BSL-1.0
14 //
15 
16 
17 #ifndef Foundation_VarHolder_INCLUDED
18 #define Foundation_VarHolder_INCLUDED
19 
20 
21 #include "Poco/Foundation.h"
22 #include "Poco/NumberFormatter.h"
23 #include "Poco/NumberParser.h"
24 #include "Poco/DateTime.h"
25 #include "Poco/Timestamp.h"
26 #include "Poco/LocalDateTime.h"
27 #include "Poco/DateTimeFormat.h"
28 #include "Poco/DateTimeFormatter.h"
29 #include "Poco/DateTimeParser.h"
30 #include "Poco/String.h"
31 #include "Poco/UnicodeConverter.h"
32 #include "Poco/UTFString.h"
33 #include "Poco/UTF8String.h"
34 #include "Poco/Any.h"
35 #include "Poco/Exception.h"
36 #include <vector>
37 #include <list>
38 #include <deque>
39 #include <typeinfo>
40 #undef min
41 #undef max
42 #include <limits>
43 
44 
45 namespace Poco {
46 namespace Dynamic {
47 
48 
49 class Var;
50 
51 
52 namespace Impl {
53 
54 
55 bool Foundation_API isJSONString(const Var& any);
56 	/// Returns true for values that should be JSON-formatted as string.
57 
58 
59 void Foundation_API appendJSONKey(std::string& val, const Var& any);
60 	/// Converts the any to a JSON key (i.e. wraps it into double quotes
61 	/// regardless of the underlying type) and appends it to val.
62 
63 
64 void Foundation_API appendJSONString(std::string& val, const Var& any);
65 	/// Converts the any to a JSON string (i.e. wraps it into double quotes)
66 	/// regardless of the underlying type) and appends it to val.
67 
68 
69 void Foundation_API appendJSONValue(std::string& val, const Var& any);
70 	/// Converts the any to a JSON value (if underlying type qualifies
71 	/// as string - see isJSONString() - , it is wrapped into double quotes)
72 	/// and appends it to val
73 
74 
75 template <typename C>
containerToJSON(C & cont,std::string & val)76 void containerToJSON(C& cont, std::string& val)
77 {
78 	// Serialize in JSON format. Note: although this is a vector<T>, the code only
79 	// supports vector<Var>. Total specialization is not possible
80 	// because of the cyclic dependency between Var and VarHolder
81 
82 	// JSON format definition: [ n times: elem ',' ], no ',' for last elem
83 	val.append("[ ");
84 	typename C::const_iterator it = cont.begin();
85 	typename C::const_iterator itEnd = cont.end();
86 	if (!cont.empty())
87 	{
88 		appendJSONValue(val, *it);
89 		++it;
90 	}
91 	for (; it != itEnd; ++it)
92 	{
93 		val.append(", ");
94 		appendJSONValue(val, *it);
95 	}
96 	val.append(" ]");
97 }
98 
99 
100 } // namespace Impl
101 
102 
103 class Foundation_API VarHolder
104 	/// Interface for a data holder used by the Var class.
105 	/// Provides methods to convert between data types.
106 	/// Only data types for which VarHolder specialization exists are supported.
107 	///
108 	/// Provided are specializations for all C++ built-in types with addition of
109 	/// std::string, Poco::UTF16String, DateTime, LocalDateTime, Timestamp, std::vector<Var> and DynamicStruct.
110 	///
111 	/// Additional types can be supported by adding specializations. When implementing specializations,
112 	/// the only condition is that they reside in Poco namespace and implement the pure virtual functions
113 	/// clone() and type().
114 	///
115 	/// Those conversions that are not implemented shall fail back to this base
116 	/// class implementation. All the convert() function overloads in this class
117 	/// throw BadCastException.
118 {
119 public:
120 	typedef Var ArrayValueType;
121 
122 	virtual ~VarHolder();
123 		/// Destroys the VarHolder.
124 
125 	virtual VarHolder* clone(Placeholder<VarHolder>* pHolder = 0) const = 0;
126 		/// Implementation must implement this function to
127 		/// deep-copy the VarHolder.
128 		/// If small object optimization is enabled (i.e. if
129 		/// POCO_NO_SOO is not defined), VarHolder will be
130 		/// instantiated in-place if it's size is smaller
131 		/// than POCO_SMALL_OBJECT_SIZE.
132 
133 	virtual const std::type_info& type() const = 0;
134 		/// Implementation must return the type information
135 		/// (typeid) for the stored content.
136 
137 	virtual void convert(Int8& val) const;
138 		/// Throws BadCastException. Must be overriden in a type
139 		/// specialization in order to support the conversion.
140 
141 	virtual void convert(Int16& val) const;
142 		/// Throws BadCastException. Must be overriden in a type
143 		/// specialization in order to support the conversion.
144 
145 	virtual void convert(Int32& val) const;
146 		/// Throws BadCastException. Must be overriden in a type
147 		/// specialization in order to support the conversion.
148 
149 	virtual void convert(Int64& val) const;
150 		/// Throws BadCastException. Must be overriden in a type
151 		/// specialization in order to support the conversion.
152 
153 	virtual void convert(UInt8& val) const;
154 		/// Throws BadCastException. Must be overriden in a type
155 		/// specialization in order to support the conversion.
156 
157 	virtual void convert(UInt16& val) const;
158 		/// Throws BadCastException. Must be overriden in a type
159 		/// specialization in order to support the conversion.
160 
161 	virtual void convert(UInt32& val) const;
162 		/// Throws BadCastException. Must be overriden in a type
163 		/// specialization in order to support the conversion.
164 
165 	virtual void convert(UInt64& val) const;
166 		/// Throws BadCastException. Must be overriden in a type
167 		/// specialization in order to support the conversion.
168 
169 	virtual void convert(DateTime& val) const;
170 		/// Throws BadCastException. Must be overriden in a type
171 		/// specialization in order to support the conversion.
172 
173 	virtual void convert(LocalDateTime& val) const;
174 		/// Throws BadCastException. Must be overriden in a type
175 		/// specialization in order to support the conversion.
176 
177 	virtual void convert(Timestamp& val) const;
178 		/// Throws BadCastException. Must be overriden in a type
179 		/// specialization in order to support the conversion.
180 
181 #ifndef POCO_INT64_IS_LONG
182 
183 	void convert(long& val) const;
184 		/// Calls convert(Int32).
185 
186 	void convert(unsigned long& val) const;
187 		/// Calls convert(UInt32).
188 
189 #else
190 
191 	virtual void convert(long long& val) const;
192 		/// Throws BadCastException. Must be overriden in a type
193 		/// specialization in order to suport the conversion.
194 
195 	virtual void convert(unsigned long long & val) const;
196 		/// Throws BadCastException. Must be overriden in a type
197 		/// specialization in order to suport the conversion.
198 
199 #endif
200 
201 	virtual void convert(bool& val) const;
202 		/// Throws BadCastException. Must be overriden in a type
203 		/// specialization in order to support the conversion.
204 
205 	virtual void convert(float& val) const;
206 		/// Throws BadCastException. Must be overriden in a type
207 		/// specialization in order to support the conversion.
208 
209 	virtual void convert(double& val) const;
210 		/// Throws BadCastException. Must be overriden in a type
211 		/// specialization in order to support the conversion.
212 
213 	virtual void convert(char& val) const;
214 		/// Throws BadCastException. Must be overriden in a type
215 		/// specialization in order to support the conversion.
216 
217 	virtual void convert(std::string& val) const;
218 		/// Throws BadCastException. Must be overriden in a type
219 		/// specialization in order to support the conversion.
220 
221 	virtual void convert(Poco::UTF16String& val) const;
222 	/// Throws BadCastException. Must be overriden in a type
223 	/// specialization in order to support the conversion.
224 
225 	virtual bool isArray() const;
226 		/// Returns true.
227 
228 	virtual bool isVector() const;
229 		/// Returns false. Must be properly overriden in a type
230 		/// specialization in order to support the diagnostic.
231 
232 	virtual bool isList() const;
233 		/// Returns false. Must be properly overriden in a type
234 		/// specialization in order to support the diagnostic.
235 
236 	virtual bool isDeque() const;
237 		/// Returns false. Must be properly overriden in a type
238 		/// specialization in order to support the diagnostic.
239 
240 	virtual bool isStruct() const;
241 		/// Returns false. Must be properly overriden in a type
242 		/// specialization in order to support the diagnostic.
243 
244 	virtual bool isOrdered() const;
245 		/// Returns false. Must be properly overriden in a type
246 		/// specialization in order to support the diagnostic.
247 
248 	virtual bool isInteger() const;
249 		/// Returns false. Must be properly overriden in a type
250 		/// specialization in order to support the diagnostic.
251 
252 	virtual bool isSigned() const;
253 		/// Returns false. Must be properly overriden in a type
254 		/// specialization in order to support the diagnostic.
255 
256 	virtual bool isNumeric() const;
257 		/// Returns false. Must be properly overriden in a type
258 		/// specialization in order to support the diagnostic.
259 
260 	virtual bool isBoolean() const;
261 		/// Returns false. Must be properly overriden in a type
262 		/// specialization in order to support the diagnostic.
263 
264 	virtual bool isString() const;
265 		/// Returns false. Must be properly overriden in a type
266 		/// specialization in order to support the diagnostic.
267 
268 	virtual bool isDate() const;
269 		/// Returns false. Must be properly overriden in a type
270 		/// specialization in order to support the diagnostic.
271 
272 	virtual bool isTime() const;
273 		/// Returns false. Must be properly overriden in a type
274 		/// specialization in order to support the diagnostic.
275 
276 	virtual bool isDateTime() const;
277 		/// Returns false. Must be properly overriden in a type
278 		/// specialization in order to support the diagnostic.
279 
280 	virtual std::size_t size() const;
281 		/// Returns 1 iff Var is not empty or this function overriden.
282 
283 protected:
284 	VarHolder();
285 		/// Creates the VarHolder.
286 
287 	template <typename T>
cloneHolder(Placeholder<VarHolder> * pVarHolder,const T & val)288 	VarHolder* cloneHolder(Placeholder<VarHolder>* pVarHolder, const T& val) const
289 		/// Instantiates value holder wrapper. If size of the wrapper is
290 		/// larger than POCO_SMALL_OBJECT_SIZE, holder is instantiated on
291 		/// the heap, otherwise it is instantiated in-place (in the
292 		/// pre-allocated buffer inside the holder).
293 		///
294 		/// Called from clone() member function of the implementation when
295 		/// small object optimization is enabled.
296 	{
297 #ifdef POCO_NO_SOO
298 		(void)pVarHolder;
299 		return new VarHolderImpl<T>(val);
300 #else
301 		poco_check_ptr (pVarHolder);
302 		if ((sizeof(VarHolderImpl<T>) <= Placeholder<T>::Size::value))
303 		{
304 			new ((VarHolder*) pVarHolder->holder) VarHolderImpl<T>(val);
305 			pVarHolder->setLocal(true);
306 			return (VarHolder*) pVarHolder->holder;
307 		}
308 		else
309 		{
310 			pVarHolder->pHolder = new VarHolderImpl<T>(val);
311 			pVarHolder->setLocal(false);
312 			return pVarHolder->pHolder;
313 		}
314 #endif
315 	}
316 
317 	template <typename F, typename T>
convertToSmaller(const F & from,T & to)318 	void convertToSmaller(const F& from, T& to) const
319 		/// This function is meant to convert signed numeric values from
320 		/// larger to smaller type. It checks the upper and lower bound and
321 		/// if from value is within limits of type T (i.e. check calls do not throw),
322 		/// it is converted.
323 	{
324 		poco_static_assert (std::numeric_limits<F>::is_specialized);
325 		poco_static_assert (std::numeric_limits<T>::is_specialized);
326 		poco_static_assert (std::numeric_limits<F>::is_signed);
327 		poco_static_assert (std::numeric_limits<T>::is_signed);
328 
329 		if (std::numeric_limits<F>::is_integer)
330 		{
331 			checkUpperLimit<F,T>(from);
332 			checkLowerLimit<F,T>(from);
333 		}
334 		else
335 		{
336 			checkUpperLimitFloat<F,T>(from);
337 			checkLowerLimitFloat<F,T>(from);
338 		}
339 
340 		to = static_cast<T>(from);
341 	}
342 
343 	template <typename F, typename T>
convertToSmallerUnsigned(const F & from,T & to)344 	void convertToSmallerUnsigned(const F& from, T& to) const
345 		/// This function is meant for converting unsigned integral data types,
346 		/// from larger to smaller type. Since lower limit is always 0 for unsigned types,
347 		/// only the upper limit is checked, thus saving some cycles compared to the signed
348 		/// version of the function. If the value to be converted is smaller than
349 		/// the maximum value for the target type, the conversion is performed.
350 	{
351 		poco_static_assert (std::numeric_limits<F>::is_specialized);
352 		poco_static_assert (std::numeric_limits<T>::is_specialized);
353 		poco_static_assert (!std::numeric_limits<F>::is_signed);
354 		poco_static_assert (!std::numeric_limits<T>::is_signed);
355 
356 		checkUpperLimit<F,T>(from);
357 		to = static_cast<T>(from);
358 	}
359 
360 	template <typename F, typename T>
convertSignedToUnsigned(const F & from,T & to)361 	void convertSignedToUnsigned(const F& from, T& to) const
362 		/// This function is meant for converting signed integral data types to
363 		/// unsigned data types. Negative values can not be converted and if one
364 		/// is encountered, RangeException is thrown.
365 		/// If upper limit is within the target data type limits, the conversion is performed.
366 	{
367 		poco_static_assert (std::numeric_limits<F>::is_specialized);
368 		poco_static_assert (std::numeric_limits<T>::is_specialized);
369 		poco_static_assert (std::numeric_limits<F>::is_signed);
370 		poco_static_assert (!std::numeric_limits<T>::is_signed);
371 
372 		if (from < 0)
373 			throw RangeException("Value too small.");
374 		checkUpperLimit<F,T>(from);
375 		to = static_cast<T>(from);
376 	}
377 
378 	template <typename F, typename T>
convertSignedFloatToUnsigned(const F & from,T & to)379 	void convertSignedFloatToUnsigned(const F& from, T& to) const
380 		/// This function is meant for converting floating point data types to
381 		/// unsigned integral data types. Negative values can not be converted and if one
382 		/// is encountered, RangeException is thrown.
383 		/// If upper limit is within the target data type limits, the conversion is performed.
384 	{
385 		poco_static_assert (std::numeric_limits<F>::is_specialized);
386 		poco_static_assert (std::numeric_limits<T>::is_specialized);
387 		poco_static_assert (!std::numeric_limits<F>::is_integer);
388 		poco_static_assert (std::numeric_limits<T>::is_integer);
389 		poco_static_assert (!std::numeric_limits<T>::is_signed);
390 
391 		if (from < 0)
392 			throw RangeException("Value too small.");
393 		checkUpperLimitFloat<F,T>(from);
394 		to = static_cast<T>(from);
395 	}
396 
397 	template <typename F, typename T>
convertUnsignedToSigned(const F & from,T & to)398 	void convertUnsignedToSigned(const F& from, T& to) const
399 		/// This function is meant for converting unsigned integral data types to
400 		/// signed integral data types. Negative values can not be converted and if one
401 		/// is encountered, RangeException is thrown.
402 		/// If upper limit is within the target data type limits, the conversion is performed.
403 	{
404 		poco_static_assert (std::numeric_limits<F>::is_specialized);
405 		poco_static_assert (std::numeric_limits<T>::is_specialized);
406 		poco_static_assert (!std::numeric_limits<F>::is_signed);
407 		poco_static_assert (std::numeric_limits<T>::is_signed);
408 
409 		checkUpperLimit<F,T>(from);
410 		to = static_cast<T>(from);
411 	}
412 
413 private:
414 	template <typename F, typename T>
checkUpperLimit(const F & from)415 	void checkUpperLimit(const F& from) const
416 	{
417 		if ((sizeof(T) < sizeof(F)) &&
418 			(from > static_cast<F>(std::numeric_limits<T>::max())))
419 		{
420 			throw RangeException("Value too large.");
421 		}
422 		else
423 		if (from > std::numeric_limits<T>::max())
424 		{
425 			throw RangeException("Value too large.");
426 		}
427 	}
428 
429 	template <typename F, typename T>
checkUpperLimitFloat(const F & from)430 	void checkUpperLimitFloat(const F& from) const
431 	{
432 		if (from > std::numeric_limits<T>::max())
433 			throw RangeException("Value too large.");
434 	}
435 
436 	template <typename F, typename T>
checkLowerLimitFloat(const F & from)437 	void checkLowerLimitFloat(const F& from) const
438 	{
439 		if (from < -std::numeric_limits<T>::max())
440 			throw RangeException("Value too small.");
441 	}
442 
443 	template <typename F, typename T>
checkLowerLimit(const F & from)444 	void checkLowerLimit(const F& from) const
445 	{
446 		if (from < std::numeric_limits<T>::min())
447 			throw RangeException("Value too small.");
448 	}
449 };
450 
451 
452 //
453 // inlines
454 //
455 
456 
convert(Int8 &)457 inline void VarHolder::convert(Int8& /*val*/) const
458 {
459 	throw BadCastException("Can not convert to Int8");
460 }
461 
462 
convert(Int16 &)463 inline void VarHolder::convert(Int16& /*val*/) const
464 {
465 	throw BadCastException("Can not convert to Int16");
466 }
467 
468 
convert(Int32 &)469 inline void VarHolder::convert(Int32& /*val*/) const
470 {
471 	throw BadCastException("Can not convert to Int32");
472 }
473 
474 
convert(Int64 &)475 inline void VarHolder::convert(Int64& /*val*/) const
476 {
477 	throw BadCastException("Can not convert to Int64");
478 }
479 
480 
convert(UInt8 &)481 inline void VarHolder::convert(UInt8& /*val*/) const
482 {
483 	throw BadCastException("Can not convert to UInt8");
484 }
485 
486 
convert(UInt16 &)487 inline void VarHolder::convert(UInt16& /*val*/) const
488 {
489 	throw BadCastException("Can not convert to UInt16");
490 }
491 
492 
convert(UInt32 &)493 inline void VarHolder::convert(UInt32& /*val*/) const
494 {
495 	throw BadCastException("Can not convert to UInt32");
496 }
497 
498 
convert(UInt64 &)499 inline void VarHolder::convert(UInt64& /*val*/) const
500 {
501 	throw BadCastException("Can not convert to UInt64");
502 }
503 
504 
convert(DateTime &)505 inline void VarHolder::convert(DateTime& /*val*/) const
506 {
507 	throw BadCastException("Can not convert to DateTime");
508 }
509 
510 
convert(LocalDateTime &)511 inline void VarHolder::convert(LocalDateTime& /*val*/) const
512 {
513 	throw BadCastException("Can not convert to LocalDateTime");
514 }
515 
516 
convert(Timestamp &)517 inline void VarHolder::convert(Timestamp& /*val*/) const
518 {
519 	throw BadCastException("Can not convert to Timestamp");
520 }
521 
522 #ifndef POCO_INT64_IS_LONG
523 
convert(long & val)524 inline void VarHolder::convert(long& val) const
525 {
526 	Int32 tmp;
527 	convert(tmp);
528 	val = tmp;
529 }
530 
531 
convert(unsigned long & val)532 inline void VarHolder::convert(unsigned long& val) const
533 {
534 	UInt32 tmp;
535 	convert(tmp);
536 	val = tmp;
537 }
538 
539 #else
540 
convert(long long &)541 inline void VarHolder::convert(long long& /*val*/) const
542 {
543 	throw BadCastException("Can not convert to long long");
544 }
545 
546 
convert(unsigned long long &)547 inline void VarHolder::convert(unsigned long long& /*val*/) const
548 {
549 	throw BadCastException("Can not convert to unsigned long long");
550 }
551 
552 #endif
553 
convert(bool &)554 inline void VarHolder::convert(bool& /*val*/) const
555 {
556 	throw BadCastException("Can not convert to bool");
557 }
558 
559 
convert(float &)560 inline void VarHolder::convert(float& /*val*/) const
561 {
562 	throw BadCastException("Can not convert to float");
563 }
564 
565 
convert(double &)566 inline void VarHolder::convert(double& /*val*/) const
567 {
568 	throw BadCastException("Can not convert to double");
569 }
570 
571 
convert(char &)572 inline void VarHolder::convert(char& /*val*/) const
573 {
574 	throw BadCastException("Can not convert to char");
575 }
576 
577 
convert(std::string &)578 inline void VarHolder::convert(std::string& /*val*/) const
579 {
580 	throw BadCastException("Can not convert to std::string");
581 }
582 
583 
convert(Poco::UTF16String &)584 inline void VarHolder::convert(Poco::UTF16String& /*val*/) const
585 {
586 	throw BadCastException("Can not convert to Poco::UTF16String");
587 }
588 
589 
isArray()590 inline bool VarHolder::isArray() const
591 {
592 	return true;
593 }
594 
595 
isVector()596 inline bool VarHolder::isVector() const
597 {
598 	return false;
599 }
600 
601 
isList()602 inline bool VarHolder::isList() const
603 {
604 	return false;
605 }
606 
607 
isDeque()608 inline bool VarHolder::isDeque() const
609 {
610 	return false;
611 }
612 
613 
isStruct()614 inline bool VarHolder::isStruct() const
615 {
616 	return false;
617 }
618 
619 
isOrdered()620 inline bool VarHolder::isOrdered() const
621 {
622 	return false;
623 }
624 
625 
isInteger()626 inline bool VarHolder::isInteger() const
627 {
628 	return false;
629 }
630 
631 
isSigned()632 inline bool VarHolder::isSigned() const
633 {
634 	return false;
635 }
636 
637 
isNumeric()638 inline bool VarHolder::isNumeric() const
639 {
640 	return false;
641 }
642 
643 
isBoolean()644 inline bool VarHolder::isBoolean() const
645 {
646 	return false;
647 }
648 
649 
isString()650 inline bool VarHolder::isString() const
651 {
652 	return false;
653 }
654 
655 
isDate()656 inline bool VarHolder::isDate() const
657 {
658 	return false;
659 }
660 
661 
isTime()662 inline bool VarHolder::isTime() const
663 {
664 	return false;
665 }
666 
667 
isDateTime()668 inline bool VarHolder::isDateTime() const
669 {
670 	return false;
671 }
672 
673 
size()674 inline std::size_t VarHolder::size() const
675 {
676 	return 1u;
677 }
678 
679 
680 template <typename T>
681 class VarHolderImpl: public VarHolder
682 	/// Template based implementation of a VarHolder.
683 	/// This class provides type storage for user-defined types
684 	/// that do not have VarHolderImpl specialization.
685 	///
686 	/// The actual conversion work happens in the template specializations
687 	/// of this class.
688 	///
689 	/// VarHolderImpl throws following exceptions:
690 	///		BadCastException (if the requested conversion is not implemented)
691 	///		RangeException (if an attempt is made to assign a numeric value outside of the target min/max limits
692 	///		SyntaxException (if an attempt is made to convert a string containing non-numeric characters to number)
693 	///
694 	/// In order to support efficient direct extraction of the held value,
695 	/// all specializations must additionally implement a public member function:
696 	///
697 	///     const T& value() const
698 	///
699 	/// returning a const reference to the actual stored value.
700 {
701 public:
VarHolderImpl(const T & val)702 	VarHolderImpl(const T& val): _val(val)
703 	{
704 	}
705 
~VarHolderImpl()706 	~VarHolderImpl()
707 	{
708 	}
709 
type()710 	const std::type_info& type() const
711 	{
712 		return typeid(T);
713 	}
714 
715 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
716 	{
717 		return cloneHolder(pVarHolder, _val);
718 	}
719 
value()720 	const T& value() const
721 	{
722 		return _val;
723 	}
724 
725 private:
726 	VarHolderImpl();
727 	VarHolderImpl(const VarHolderImpl&);
728 	VarHolderImpl& operator = (const VarHolderImpl&);
729 
730 	T _val;
731 };
732 
733 
734 template <>
735 class VarHolderImpl<Int8>: public VarHolder
736 {
737 public:
VarHolderImpl(Int8 val)738 	VarHolderImpl(Int8 val): _val(val)
739 	{
740 	}
741 
~VarHolderImpl()742 	~VarHolderImpl()
743 	{
744 	}
745 
type()746 	const std::type_info& type() const
747 	{
748 		return typeid(Int8);
749 	}
750 
convert(Int8 & val)751 	void convert(Int8& val) const
752 	{
753 		val = _val;
754 	}
755 
convert(Int16 & val)756 	void convert(Int16& val) const
757 	{
758 		val = _val;
759 	}
760 
convert(Int32 & val)761 	void convert(Int32& val) const
762 	{
763 		val = _val;
764 	}
765 
convert(Int64 & val)766 	void convert(Int64& val) const
767 	{
768 		val = _val;
769 	}
770 
convert(UInt8 & val)771 	void convert(UInt8& val) const
772 	{
773 		convertSignedToUnsigned(_val, val);
774 	}
775 
convert(UInt16 & val)776 	void convert(UInt16& val) const
777 	{
778 		convertSignedToUnsigned(_val, val);
779 	}
780 
convert(UInt32 & val)781 	void convert(UInt32& val) const
782 	{
783 		convertSignedToUnsigned(_val, val);
784 	}
785 
convert(UInt64 & val)786 	void convert(UInt64& val) const
787 	{
788 		convertSignedToUnsigned(_val, val);
789 	}
790 
791 #ifdef POCO_INT64_IS_LONG
792 
convert(long long & val)793 	void convert(long long& val) const
794 	{
795 		val = _val;
796 	}
797 
convert(unsigned long long & val)798 	void convert(unsigned long long& val) const
799 	{
800 		convertSignedToUnsigned(_val, val);
801 	}
802 
803 #endif
804 
convert(bool & val)805 	void convert(bool& val) const
806 	{
807 		val = (_val != 0);
808 	}
809 
convert(float & val)810 	void convert(float& val) const
811 	{
812 		val = static_cast<float>(_val);
813 	}
814 
convert(double & val)815 	void convert(double& val) const
816 	{
817 		val = static_cast<double>(_val);
818 	}
819 
convert(char & val)820 	void convert(char& val) const
821 	{
822 		val = static_cast<char>(_val);
823 	}
824 
convert(std::string & val)825 	void convert(std::string& val) const
826 	{
827 		val = NumberFormatter::format(_val);
828 	}
829 
convert(Poco::UTF16String & val)830 	void convert(Poco::UTF16String& val) const
831 	{
832 		std::string str = NumberFormatter::format(_val);
833 		Poco::UnicodeConverter::convert(str, val);
834 	}
835 
836 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
837 	{
838 		return cloneHolder(pVarHolder, _val);
839 	}
840 
value()841 	const Int8& value() const
842 	{
843 		return _val;
844 	}
845 
isArray()846 	bool isArray() const
847 	{
848 		return false;
849 	}
850 
isStruct()851 	bool isStruct() const
852 	{
853 		return false;
854 	}
855 
isInteger()856 	bool isInteger() const
857 	{
858 		return std::numeric_limits<Int8>::is_integer;
859 	}
860 
isSigned()861 	bool isSigned() const
862 	{
863 		return std::numeric_limits<Int8>::is_signed;
864 	}
865 
isNumeric()866 	bool isNumeric() const
867 	{
868 		return std::numeric_limits<Int8>::is_specialized;
869 	}
870 
isBoolean()871 	bool isBoolean() const
872 	{
873 		return false;
874 	}
875 
isString()876 	bool isString() const
877 	{
878 		return false;
879 	}
880 
881 private:
882 	VarHolderImpl();
883 	VarHolderImpl(const VarHolderImpl&);
884 	VarHolderImpl& operator = (const VarHolderImpl&);
885 
886 	Int8 _val;
887 };
888 
889 
890 template <>
891 class VarHolderImpl<Int16>: public VarHolder
892 {
893 public:
VarHolderImpl(Int16 val)894 	VarHolderImpl(Int16 val): _val(val)
895 	{
896 	}
897 
~VarHolderImpl()898 	~VarHolderImpl()
899 	{
900 	}
901 
type()902 	const std::type_info& type() const
903 	{
904 		return typeid(Int16);
905 	}
906 
convert(Int8 & val)907 	void convert(Int8& val) const
908 	{
909 		convertToSmaller(_val, val);
910 	}
911 
convert(Int16 & val)912 	void convert(Int16& val) const
913 	{
914 		val = _val;
915 	}
916 
convert(Int32 & val)917 	void convert(Int32& val) const
918 	{
919 		val = _val;
920 	}
921 
convert(Int64 & val)922 	void convert(Int64& val) const
923 	{
924 		val = _val;
925 	}
926 
convert(UInt8 & val)927 	void convert(UInt8& val) const
928 	{
929 		convertSignedToUnsigned(_val, val);
930 	}
931 
convert(UInt16 & val)932 	void convert(UInt16& val) const
933 	{
934 		convertSignedToUnsigned(_val, val);
935 	}
936 
convert(UInt32 & val)937 	void convert(UInt32& val) const
938 	{
939 		convertSignedToUnsigned(_val, val);
940 	}
941 
convert(UInt64 & val)942 	void convert(UInt64& val) const
943 	{
944 		convertSignedToUnsigned(_val, val);
945 	}
946 
947 #ifdef POCO_INT64_IS_LONG
948 
convert(long long & val)949 	void convert(long long& val) const
950 	{
951 		val = _val;
952 	}
953 
convert(unsigned long long & val)954 	void convert(unsigned long long& val) const
955 	{
956 		convertSignedToUnsigned(_val, val);
957 	}
958 
959 #endif
960 
convert(bool & val)961 	void convert(bool& val) const
962 	{
963 		val = (_val != 0);
964 	}
965 
convert(float & val)966 	void convert(float& val) const
967 	{
968 		val = static_cast<float>(_val);
969 	}
970 
convert(double & val)971 	void convert(double& val) const
972 	{
973 		val = static_cast<double>(_val);
974 	}
975 
convert(char & val)976 	void convert(char& val) const
977 	{
978 		UInt8 tmp;
979 		convert(tmp);
980 		val = static_cast<char>(tmp);
981 	}
982 
convert(std::string & val)983 	void convert(std::string& val) const
984 	{
985 		val = NumberFormatter::format(_val);
986 	}
987 
convert(Poco::UTF16String & val)988 	void convert(Poco::UTF16String& val) const
989 	{
990 		std::string str = NumberFormatter::format(_val);
991 		Poco::UnicodeConverter::convert(str, val);
992 	}
993 
994 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
995 	{
996 		return cloneHolder(pVarHolder, _val);
997 	}
998 
value()999 	const Int16& value() const
1000 	{
1001 		return _val;
1002 	}
1003 
isArray()1004 	bool isArray() const
1005 	{
1006 		return false;
1007 	}
1008 
isStruct()1009 	bool isStruct() const
1010 	{
1011 		return false;
1012 	}
1013 
isInteger()1014 	bool isInteger() const
1015 	{
1016 		return std::numeric_limits<Int16>::is_integer;
1017 	}
1018 
isSigned()1019 	bool isSigned() const
1020 	{
1021 		return std::numeric_limits<Int16>::is_signed;
1022 	}
1023 
isNumeric()1024 	bool isNumeric() const
1025 	{
1026 		return std::numeric_limits<Int16>::is_specialized;
1027 	}
1028 
1029 
isString()1030 	bool isString() const
1031 	{
1032 		return false;
1033 	}
1034 
1035 private:
1036 	VarHolderImpl();
1037 	VarHolderImpl(const VarHolderImpl&);
1038 	VarHolderImpl& operator = (const VarHolderImpl&);
1039 
1040 	Int16 _val;
1041 };
1042 
1043 
1044 template <>
1045 class VarHolderImpl<Int32>: public VarHolder
1046 {
1047 public:
VarHolderImpl(Int32 val)1048 	VarHolderImpl(Int32 val): _val(val)
1049 	{
1050 	}
1051 
~VarHolderImpl()1052 	~VarHolderImpl()
1053 	{
1054 	}
1055 
type()1056 	const std::type_info& type() const
1057 	{
1058 		return typeid(Int32);
1059 	}
1060 
convert(Int8 & val)1061 	void convert(Int8& val) const
1062 	{
1063 		convertToSmaller(_val, val);
1064 	}
1065 
convert(Int16 & val)1066 	void convert(Int16& val) const
1067 	{
1068 		convertToSmaller(_val, val);
1069 	}
1070 
convert(Int32 & val)1071 	void convert(Int32& val) const
1072 	{
1073 		val = _val;
1074 	}
1075 
convert(Int64 & val)1076 	void convert(Int64& val) const
1077 	{
1078 		val = _val;
1079 	}
1080 
convert(UInt8 & val)1081 	void convert(UInt8& val) const
1082 	{
1083 		convertSignedToUnsigned(_val, val);
1084 	}
1085 
convert(UInt16 & val)1086 	void convert(UInt16& val) const
1087 	{
1088 		convertSignedToUnsigned(_val, val);
1089 	}
1090 
convert(UInt32 & val)1091 	void convert(UInt32& val) const
1092 	{
1093 		convertSignedToUnsigned(_val, val);
1094 	}
1095 
convert(UInt64 & val)1096 	void convert(UInt64& val) const
1097 	{
1098 		convertSignedToUnsigned(_val, val);
1099 	}
1100 
1101 #ifdef POCO_INT64_IS_LONG
1102 
convert(long long & val)1103 	void convert(long long& val) const
1104 	{
1105 		val = _val;
1106 	}
1107 
convert(unsigned long long & val)1108 	void convert(unsigned long long& val) const
1109 	{
1110 		convertSignedToUnsigned(_val, val);
1111 	}
1112 
1113 #endif
1114 
convert(bool & val)1115 	void convert(bool& val) const
1116 	{
1117 		val = (_val != 0);
1118 	}
1119 
convert(float & val)1120 	void convert(float& val) const
1121 	{
1122 		val = static_cast<float>(_val);
1123 	}
1124 
convert(double & val)1125 	void convert(double& val) const
1126 	{
1127 		val = static_cast<double>(_val);
1128 	}
1129 
convert(char & val)1130 	void convert(char& val) const
1131 	{
1132 		UInt8 tmp;
1133 		convert(tmp);
1134 		val = static_cast<char>(tmp);
1135 	}
1136 
convert(std::string & val)1137 	void convert(std::string& val) const
1138 	{
1139 		val = NumberFormatter::format(_val);
1140 	}
1141 
1142 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
1143 	{
1144 		return cloneHolder(pVarHolder, _val);
1145 	}
1146 
value()1147 	const Int32& value() const
1148 	{
1149 		return _val;
1150 	}
1151 
isArray()1152 	bool isArray() const
1153 	{
1154 		return false;
1155 	}
1156 
isStruct()1157 	bool isStruct() const
1158 	{
1159 		return false;
1160 	}
1161 
isInteger()1162 	bool isInteger() const
1163 	{
1164 		return std::numeric_limits<Int32>::is_integer;
1165 	}
1166 
isSigned()1167 	bool isSigned() const
1168 	{
1169 		return std::numeric_limits<Int32>::is_signed;
1170 	}
1171 
isNumeric()1172 	bool isNumeric() const
1173 	{
1174 		return std::numeric_limits<Int32>::is_specialized;
1175 	}
1176 
isBoolean()1177 	bool isBoolean() const
1178 	{
1179 		return false;
1180 	}
1181 
isString()1182 	bool isString() const
1183 	{
1184 		return false;
1185 	}
1186 
1187 private:
1188 	VarHolderImpl();
1189 	VarHolderImpl(const VarHolderImpl&);
1190 	VarHolderImpl& operator = (const VarHolderImpl&);
1191 
1192 	Int32 _val;
1193 };
1194 
1195 
1196 template <>
1197 class VarHolderImpl<Int64>: public VarHolder
1198 {
1199 public:
VarHolderImpl(Int64 val)1200 	VarHolderImpl(Int64 val): _val(val)
1201 	{
1202 	}
1203 
~VarHolderImpl()1204 	~VarHolderImpl()
1205 	{
1206 	}
1207 
type()1208 	const std::type_info& type() const
1209 	{
1210 		return typeid(Int64);
1211 	}
1212 
convert(Int8 & val)1213 	void convert(Int8& val) const
1214 	{
1215 		convertToSmaller(_val, val);
1216 	}
1217 
convert(Int16 & val)1218 	void convert(Int16& val) const
1219 	{
1220 		convertToSmaller(_val, val);
1221 	}
1222 
convert(Int32 & val)1223 	void convert(Int32& val) const
1224 	{
1225 		convertToSmaller(_val, val);
1226 	}
1227 
convert(Int64 & val)1228 	void convert(Int64& val) const
1229 	{
1230 		val = _val;
1231 	}
1232 
convert(UInt8 & val)1233 	void convert(UInt8& val) const
1234 	{
1235 		convertSignedToUnsigned(_val, val);
1236 	}
1237 
convert(UInt16 & val)1238 	void convert(UInt16& val) const
1239 	{
1240 		convertSignedToUnsigned(_val, val);
1241 	}
1242 
convert(UInt32 & val)1243 	void convert(UInt32& val) const
1244 	{
1245 		convertSignedToUnsigned(_val, val);
1246 	}
1247 
convert(UInt64 & val)1248 	void convert(UInt64& val) const
1249 	{
1250 		convertSignedToUnsigned(_val, val);
1251 	}
1252 
1253 #ifdef POCO_INT64_IS_LONG
1254 
convert(long long & val)1255 	void convert(long long& val) const
1256 	{
1257 		val = _val;
1258 	}
1259 
convert(unsigned long long & val)1260 	void convert(unsigned long long& val) const
1261 	{
1262 		convertSignedToUnsigned(_val, val);
1263 	}
1264 
1265 #endif
1266 
convert(bool & val)1267 	void convert(bool& val) const
1268 	{
1269 		val = (_val != 0);
1270 	}
1271 
convert(float & val)1272 	void convert(float& val) const
1273 	{
1274 		val = static_cast<float>(_val);
1275 	}
1276 
convert(double & val)1277 	void convert(double& val) const
1278 	{
1279 		val = static_cast<double>(_val);
1280 	}
1281 
convert(char & val)1282 	void convert(char& val) const
1283 	{
1284 		UInt8 tmp;
1285 		convert(tmp);
1286 		val = static_cast<char>(tmp);
1287 	}
1288 
convert(std::string & val)1289 	void convert(std::string& val) const
1290 	{
1291 		val = NumberFormatter::format(_val);
1292 	}
1293 
convert(DateTime & dt)1294 	void convert(DateTime& dt) const
1295 	{
1296 		dt = Timestamp(_val);
1297 	}
1298 
convert(LocalDateTime & ldt)1299 	void convert(LocalDateTime& ldt) const
1300 	{
1301 		ldt = Timestamp(_val);
1302 	}
1303 
convert(Timestamp & val)1304 	void convert(Timestamp& val) const
1305 	{
1306 		val = Timestamp(_val);
1307 	}
1308 
1309 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
1310 	{
1311 		return cloneHolder(pVarHolder, _val);
1312 	}
1313 
value()1314 	const Int64& value() const
1315 	{
1316 		return _val;
1317 	}
1318 
isArray()1319 	bool isArray() const
1320 	{
1321 		return false;
1322 	}
1323 
isStruct()1324 	bool isStruct() const
1325 	{
1326 		return false;
1327 	}
1328 
isInteger()1329 	bool isInteger() const
1330 	{
1331 		return std::numeric_limits<Int64>::is_integer;
1332 	}
1333 
isSigned()1334 	bool isSigned() const
1335 	{
1336 		return std::numeric_limits<Int64>::is_signed;
1337 	}
1338 
isNumeric()1339 	bool isNumeric() const
1340 	{
1341 		return std::numeric_limits<Int64>::is_specialized;
1342 	}
1343 
isBoolean()1344 	bool isBoolean() const
1345 	{
1346 		return false;
1347 	}
1348 
isString()1349 	bool isString() const
1350 	{
1351 		return false;
1352 	}
1353 
1354 private:
1355 	VarHolderImpl();
1356 	VarHolderImpl(const VarHolderImpl&);
1357 	VarHolderImpl& operator = (const VarHolderImpl&);
1358 
1359 	Int64 _val;
1360 };
1361 
1362 
1363 template <>
1364 class VarHolderImpl<UInt8>: public VarHolder
1365 {
1366 public:
VarHolderImpl(UInt8 val)1367 	VarHolderImpl(UInt8 val): _val(val)
1368 	{
1369 	}
1370 
~VarHolderImpl()1371 	~VarHolderImpl()
1372 	{
1373 	}
1374 
type()1375 	const std::type_info& type() const
1376 	{
1377 		return typeid(UInt8);
1378 	}
1379 
convert(Int8 & val)1380 	void convert(Int8& val) const
1381 	{
1382 		convertUnsignedToSigned(_val, val);
1383 	}
1384 
convert(Int16 & val)1385 	void convert(Int16& val) const
1386 	{
1387 		convertUnsignedToSigned(_val, val);
1388 	}
1389 
convert(Int32 & val)1390 	void convert(Int32& val) const
1391 	{
1392 		val = static_cast<Int32>(_val);
1393 	}
1394 
convert(Int64 & val)1395 	void convert(Int64& val) const
1396 	{
1397 		val = static_cast<Int64>(_val);
1398 	}
1399 
convert(UInt8 & val)1400 	void convert(UInt8& val) const
1401 	{
1402 		val = _val;
1403 	}
1404 
convert(UInt16 & val)1405 	void convert(UInt16& val) const
1406 	{
1407 		val = _val;
1408 	}
1409 
convert(UInt32 & val)1410 	void convert(UInt32& val) const
1411 	{
1412 		val = _val;
1413 	}
1414 
convert(UInt64 & val)1415 	void convert(UInt64& val) const
1416 	{
1417 		val = _val;
1418 	}
1419 
1420 #ifdef POCO_INT64_IS_LONG
1421 
convert(long long & val)1422 	void convert(long long& val) const
1423 	{
1424 		val = static_cast<long long>(_val);
1425 	}
1426 
convert(unsigned long long & val)1427 	void convert(unsigned long long& val) const
1428 	{
1429 		val = _val;
1430 	}
1431 
1432 #endif
1433 
convert(bool & val)1434 	void convert(bool& val) const
1435 	{
1436 		val = (_val != 0);
1437 	}
1438 
convert(float & val)1439 	void convert(float& val) const
1440 	{
1441 		val = static_cast<float>(_val);
1442 	}
1443 
convert(double & val)1444 	void convert(double& val) const
1445 	{
1446 		val = static_cast<double>(_val);
1447 	}
1448 
convert(char & val)1449 	void convert(char& val) const
1450 	{
1451 		UInt8 tmp;
1452 		convert(tmp);
1453 		val = static_cast<char>(tmp);
1454 	}
1455 
convert(std::string & val)1456 	void convert(std::string& val) const
1457 	{
1458 		val = NumberFormatter::format(_val);
1459 	}
1460 
1461 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
1462 	{
1463 		return cloneHolder(pVarHolder, _val);
1464 	}
1465 
value()1466 	const UInt8& value() const
1467 	{
1468 		return _val;
1469 	}
1470 
isArray()1471 	bool isArray() const
1472 	{
1473 		return false;
1474 	}
1475 
isStruct()1476 	bool isStruct() const
1477 	{
1478 		return false;
1479 	}
1480 
isInteger()1481 	bool isInteger() const
1482 	{
1483 		return std::numeric_limits<UInt8>::is_integer;
1484 	}
1485 
isSigned()1486 	bool isSigned() const
1487 	{
1488 		return std::numeric_limits<UInt8>::is_signed;
1489 	}
1490 
isNumeric()1491 	bool isNumeric() const
1492 	{
1493 		return std::numeric_limits<UInt8>::is_specialized;
1494 	}
1495 
isBoolean()1496 	bool isBoolean() const
1497 	{
1498 		return false;
1499 	}
1500 
isString()1501 	bool isString() const
1502 	{
1503 		return false;
1504 	}
1505 
1506 private:
1507 	VarHolderImpl();
1508 	VarHolderImpl(const VarHolderImpl&);
1509 	VarHolderImpl& operator = (const VarHolderImpl&);
1510 
1511 	UInt8 _val;
1512 };
1513 
1514 
1515 template <>
1516 class VarHolderImpl<UInt16>: public VarHolder
1517 {
1518 public:
VarHolderImpl(UInt16 val)1519 	VarHolderImpl(UInt16 val): _val(val)
1520 	{
1521 	}
1522 
~VarHolderImpl()1523 	~VarHolderImpl()
1524 	{
1525 	}
1526 
type()1527 	const std::type_info& type() const
1528 	{
1529 		return typeid(UInt16);
1530 	}
1531 
convert(Int8 & val)1532 	void convert(Int8& val) const
1533 	{
1534 		convertUnsignedToSigned(_val, val);
1535 	}
1536 
convert(Int16 & val)1537 	void convert(Int16& val) const
1538 	{
1539 		convertUnsignedToSigned(_val, val);
1540 	}
1541 
convert(Int32 & val)1542 	void convert(Int32& val) const
1543 	{
1544 		convertUnsignedToSigned(_val, val);
1545 	}
1546 
convert(Int64 & val)1547 	void convert(Int64& val) const
1548 	{
1549 		val = static_cast<Int64>(_val);
1550 	}
1551 
convert(UInt8 & val)1552 	void convert(UInt8& val) const
1553 	{
1554 		convertToSmallerUnsigned(_val, val);
1555 	}
1556 
convert(UInt16 & val)1557 	void convert(UInt16& val) const
1558 	{
1559 		val = _val;
1560 	}
1561 
convert(UInt32 & val)1562 	void convert(UInt32& val) const
1563 	{
1564 		val = _val;
1565 	}
1566 
convert(UInt64 & val)1567 	void convert(UInt64& val) const
1568 	{
1569 		val = _val;
1570 	}
1571 
1572 #ifdef POCO_INT64_IS_LONG
1573 
convert(long long & val)1574 	void convert(long long& val) const
1575 	{
1576 		val = static_cast<long long>(_val);
1577 	}
1578 
convert(unsigned long long & val)1579 	void convert(unsigned long long& val) const
1580 	{
1581 		val = _val;
1582 	}
1583 
1584 #endif
1585 
convert(bool & val)1586 	void convert(bool& val) const
1587 	{
1588 		val = (_val != 0);
1589 	}
1590 
convert(float & val)1591 	void convert(float& val) const
1592 	{
1593 		val = static_cast<float>(_val);
1594 	}
1595 
convert(double & val)1596 	void convert(double& val) const
1597 	{
1598 		val = static_cast<double>(_val);
1599 	}
1600 
convert(char & val)1601 	void convert(char& val) const
1602 	{
1603 		UInt8 tmp;
1604 		convert(tmp);
1605 		val = static_cast<char>(tmp);
1606 	}
1607 
convert(std::string & val)1608 	void convert(std::string& val) const
1609 	{
1610 		val = NumberFormatter::format(_val);
1611 	}
1612 
1613 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
1614 	{
1615 		return cloneHolder(pVarHolder, _val);
1616 	}
1617 
value()1618 	const UInt16& value() const
1619 	{
1620 		return _val;
1621 	}
1622 
isArray()1623 	bool isArray() const
1624 	{
1625 		return false;
1626 	}
1627 
isStruct()1628 	bool isStruct() const
1629 	{
1630 		return false;
1631 	}
1632 
isInteger()1633 	bool isInteger() const
1634 	{
1635 		return std::numeric_limits<UInt16>::is_integer;
1636 	}
1637 
isSigned()1638 	bool isSigned() const
1639 	{
1640 		return std::numeric_limits<UInt16>::is_signed;
1641 	}
1642 
isNumeric()1643 	bool isNumeric() const
1644 	{
1645 		return std::numeric_limits<UInt16>::is_specialized;
1646 	}
1647 
isBoolean()1648 	bool isBoolean() const
1649 	{
1650 		return false;
1651 	}
1652 
isString()1653 	bool isString() const
1654 	{
1655 		return false;
1656 	}
1657 
1658 private:
1659 	VarHolderImpl();
1660 	VarHolderImpl(const VarHolderImpl&);
1661 	VarHolderImpl& operator = (const VarHolderImpl&);
1662 
1663 	UInt16 _val;
1664 };
1665 
1666 
1667 template <>
1668 class VarHolderImpl<UInt32>: public VarHolder
1669 {
1670 public:
VarHolderImpl(UInt32 val)1671 	VarHolderImpl(UInt32 val): _val(val)
1672 	{
1673 	}
1674 
~VarHolderImpl()1675 	~VarHolderImpl()
1676 	{
1677 	}
1678 
type()1679 	const std::type_info& type() const
1680 	{
1681 		return typeid(UInt32);
1682 	}
1683 
convert(Int8 & val)1684 	void convert(Int8& val) const
1685 	{
1686 		convertUnsignedToSigned(_val, val);
1687 	}
1688 
convert(Int16 & val)1689 	void convert(Int16& val) const
1690 	{
1691 		convertUnsignedToSigned(_val, val);
1692 	}
1693 
convert(Int32 & val)1694 	void convert(Int32& val) const
1695 	{
1696 		convertUnsignedToSigned(_val, val);
1697 	}
1698 
convert(Int64 & val)1699 	void convert(Int64& val) const
1700 	{
1701 		convertUnsignedToSigned(_val, val);
1702 	}
1703 
convert(UInt8 & val)1704 	void convert(UInt8& val) const
1705 	{
1706 		convertToSmallerUnsigned(_val, val);
1707 	}
1708 
convert(UInt16 & val)1709 	void convert(UInt16& val) const
1710 	{
1711 		convertToSmallerUnsigned(_val, val);
1712 	}
1713 
convert(UInt32 & val)1714 	void convert(UInt32& val) const
1715 	{
1716 		val = _val;
1717 	}
1718 
convert(UInt64 & val)1719 	void convert(UInt64& val) const
1720 	{
1721 		val = _val;
1722 	}
1723 
1724 #ifdef POCO_INT64_IS_LONG
1725 
convert(long long & val)1726 	void convert(long long& val) const
1727 	{
1728 		convertUnsignedToSigned(_val, val);
1729 	}
1730 
convert(unsigned long long & val)1731 	void convert(unsigned long long& val) const
1732 	{
1733 		val = _val;
1734 	}
1735 
1736 #endif
1737 
convert(bool & val)1738 	void convert(bool& val) const
1739 	{
1740 		val = (_val != 0);
1741 	}
1742 
convert(float & val)1743 	void convert(float& val) const
1744 	{
1745 		val = static_cast<float>(_val);
1746 	}
1747 
convert(double & val)1748 	void convert(double& val) const
1749 	{
1750 		val = static_cast<double>(_val);
1751 	}
1752 
convert(char & val)1753 	void convert(char& val) const
1754 	{
1755 		UInt8 tmp;
1756 		convert(tmp);
1757 		val = static_cast<char>(tmp);
1758 	}
1759 
convert(std::string & val)1760 	void convert(std::string& val) const
1761 	{
1762 		val = NumberFormatter::format(_val);
1763 	}
1764 
1765 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
1766 	{
1767 		return cloneHolder(pVarHolder, _val);
1768 	}
1769 
value()1770 	const UInt32& value() const
1771 	{
1772 		return _val;
1773 	}
1774 
isArray()1775 	bool isArray() const
1776 	{
1777 		return false;
1778 	}
1779 
isStruct()1780 	bool isStruct() const
1781 	{
1782 		return false;
1783 	}
1784 
isInteger()1785 	bool isInteger() const
1786 	{
1787 		return std::numeric_limits<UInt32>::is_integer;
1788 	}
1789 
isSigned()1790 	bool isSigned() const
1791 	{
1792 		return std::numeric_limits<UInt32>::is_signed;
1793 	}
1794 
isNumeric()1795 	bool isNumeric() const
1796 	{
1797 		return std::numeric_limits<UInt32>::is_specialized;
1798 	}
1799 
isBoolean()1800 	bool isBoolean() const
1801 	{
1802 		return false;
1803 	}
1804 
isString()1805 	bool isString() const
1806 	{
1807 		return false;
1808 	}
1809 
1810 private:
1811 	VarHolderImpl();
1812 	VarHolderImpl(const VarHolderImpl&);
1813 	VarHolderImpl& operator = (const VarHolderImpl&);
1814 
1815 	UInt32 _val;
1816 };
1817 
1818 
1819 template <>
1820 class VarHolderImpl<UInt64>: public VarHolder
1821 {
1822 public:
VarHolderImpl(UInt64 val)1823 	VarHolderImpl(UInt64 val): _val(val)
1824 	{
1825 	}
1826 
~VarHolderImpl()1827 	~VarHolderImpl()
1828 	{
1829 	}
1830 
type()1831 	const std::type_info& type() const
1832 	{
1833 		return typeid(UInt64);
1834 	}
1835 
convert(Int8 & val)1836 	void convert(Int8& val) const
1837 	{
1838 		convertUnsignedToSigned(_val, val);
1839 	}
1840 
convert(Int16 & val)1841 	void convert(Int16& val) const
1842 	{
1843 		convertUnsignedToSigned(_val, val);
1844 	}
1845 
convert(Int32 & val)1846 	void convert(Int32& val) const
1847 	{
1848 		convertUnsignedToSigned(_val, val);
1849 	}
1850 
convert(Int64 & val)1851 	void convert(Int64& val) const
1852 	{
1853 		convertUnsignedToSigned(_val, val);
1854 	}
1855 
convert(UInt8 & val)1856 	void convert(UInt8& val) const
1857 	{
1858 		convertToSmallerUnsigned(_val, val);
1859 	}
1860 
convert(UInt16 & val)1861 	void convert(UInt16& val) const
1862 	{
1863 		convertToSmallerUnsigned(_val, val);
1864 	}
1865 
convert(UInt32 & val)1866 	void convert(UInt32& val) const
1867 	{
1868 		convertToSmallerUnsigned(_val, val);
1869 	}
1870 
convert(UInt64 & val)1871 	void convert(UInt64& val) const
1872 	{
1873 		val = _val;
1874 	}
1875 
1876 #ifdef POCO_INT64_IS_LONG
1877 
convert(long long & val)1878 	void convert(long long& val) const
1879 	{
1880 		convertUnsignedToSigned(_val, val);
1881 	}
1882 
convert(unsigned long long & val)1883 	void convert(unsigned long long& val) const
1884 	{
1885 		val = _val;
1886 	}
1887 
1888 #endif
1889 
convert(bool & val)1890 	void convert(bool& val) const
1891 	{
1892 		val = (_val != 0);
1893 	}
1894 
convert(float & val)1895 	void convert(float& val) const
1896 	{
1897 		val = static_cast<float>(_val);
1898 	}
1899 
convert(double & val)1900 	void convert(double& val) const
1901 	{
1902 		val = static_cast<double>(_val);
1903 	}
1904 
convert(char & val)1905 	void convert(char& val) const
1906 	{
1907 		UInt8 tmp;
1908 		convert(tmp);
1909 		val = static_cast<char>(tmp);
1910 	}
1911 
convert(std::string & val)1912 	void convert(std::string& val) const
1913 	{
1914 		val = NumberFormatter::format(_val);
1915 	}
1916 
convert(DateTime & dt)1917 	void convert(DateTime& dt) const
1918 	{
1919 		Int64 val;
1920 		convertUnsignedToSigned(_val, val);
1921 		dt = Timestamp(val);
1922 	}
1923 
convert(LocalDateTime & ldt)1924 	void convert(LocalDateTime& ldt) const
1925 	{
1926 		Int64 val;
1927 		convertUnsignedToSigned(_val, val);
1928 		ldt = Timestamp(val);
1929 	}
1930 
convert(Timestamp & val)1931 	void convert(Timestamp& val) const
1932 	{
1933 		Int64 tmp;
1934 		convertUnsignedToSigned(_val, tmp);
1935 		val = Timestamp(tmp);
1936 	}
1937 
1938 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
1939 	{
1940 		return cloneHolder(pVarHolder, _val);
1941 	}
1942 
value()1943 	const UInt64& value() const
1944 	{
1945 		return _val;
1946 	}
1947 
isArray()1948 	bool isArray() const
1949 	{
1950 		return false;
1951 	}
1952 
isStruct()1953 	bool isStruct() const
1954 	{
1955 		return false;
1956 	}
1957 
isInteger()1958 	bool isInteger() const
1959 	{
1960 		return std::numeric_limits<UInt64>::is_integer;
1961 	}
1962 
isSigned()1963 	bool isSigned() const
1964 	{
1965 		return std::numeric_limits<UInt64>::is_signed;
1966 	}
1967 
isNumeric()1968 	bool isNumeric() const
1969 	{
1970 		return std::numeric_limits<UInt64>::is_specialized;
1971 	}
1972 
isBoolean()1973 	bool isBoolean() const
1974 	{
1975 		return false;
1976 	}
1977 
isString()1978 	bool isString() const
1979 	{
1980 		return false;
1981 	}
1982 
1983 private:
1984 	VarHolderImpl();
1985 	VarHolderImpl(const VarHolderImpl&);
1986 	VarHolderImpl& operator = (const VarHolderImpl&);
1987 
1988 	UInt64 _val;
1989 };
1990 
1991 
1992 template <>
1993 class VarHolderImpl<bool>: public VarHolder
1994 {
1995 public:
VarHolderImpl(bool val)1996 	VarHolderImpl(bool val): _val(val)
1997 	{
1998 	}
1999 
~VarHolderImpl()2000 	~VarHolderImpl()
2001 	{
2002 	}
2003 
type()2004 	const std::type_info& type() const
2005 	{
2006 		return typeid(bool);
2007 	}
2008 
convert(Int8 & val)2009 	void convert(Int8& val) const
2010 	{
2011 		val = static_cast<Int8>(_val ? 1 : 0);
2012 	}
2013 
convert(Int16 & val)2014 	void convert(Int16& val) const
2015 	{
2016 		val = static_cast<Int16>(_val ? 1 : 0);
2017 	}
2018 
convert(Int32 & val)2019 	void convert(Int32& val) const
2020 	{
2021 		val = static_cast<Int32>(_val ? 1 : 0);
2022 	}
2023 
convert(Int64 & val)2024 	void convert(Int64& val) const
2025 	{
2026 		val = static_cast<Int64>(_val ? 1 : 0);
2027 	}
2028 
convert(UInt8 & val)2029 	void convert(UInt8& val) const
2030 	{
2031 		val = static_cast<UInt8>(_val ? 1 : 0);
2032 	}
2033 
convert(UInt16 & val)2034 	void convert(UInt16& val) const
2035 	{
2036 		val = static_cast<UInt16>(_val ? 1 : 0);
2037 	}
2038 
convert(UInt32 & val)2039 	void convert(UInt32& val) const
2040 	{
2041 		val = static_cast<UInt32>(_val ? 1 : 0);
2042 	}
2043 
convert(UInt64 & val)2044 	void convert(UInt64& val) const
2045 	{
2046 		val = static_cast<UInt64>(_val ? 1 : 0);
2047 	}
2048 
2049 #ifdef POCO_INT64_IS_LONG
2050 
convert(long long & val)2051 	void convert(long long& val) const
2052 	{
2053 		val = static_cast<long long>(_val ? 1 : 0);
2054 	}
2055 
convert(unsigned long long & val)2056 	void convert(unsigned long long& val) const
2057 	{
2058 		val = static_cast<unsigned long long>(_val ? 1 : 0);
2059 	}
2060 
2061 #endif
2062 
convert(bool & val)2063 	void convert(bool& val) const
2064 	{
2065 		val = _val;
2066 	}
2067 
convert(float & val)2068 	void convert(float& val) const
2069 	{
2070 		val = (_val ? 1.0f : 0.0f);
2071 	}
2072 
convert(double & val)2073 	void convert(double& val) const
2074 	{
2075 		val = (_val ? 1.0 : 0.0);
2076 	}
2077 
convert(char & val)2078 	void convert(char& val) const
2079 	{
2080 		val = static_cast<char>(_val ? 1 : 0);
2081 	}
2082 
convert(std::string & val)2083 	void convert(std::string& val) const
2084 	{
2085 		val = (_val ? "true" : "false");
2086 	}
2087 
2088 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
2089 	{
2090 		return cloneHolder(pVarHolder, _val);
2091 	}
2092 
value()2093 	const bool& value() const
2094 	{
2095 		return _val;
2096 	}
2097 
isArray()2098 	bool isArray() const
2099 	{
2100 		return false;
2101 	}
2102 
isStruct()2103 	bool isStruct() const
2104 	{
2105 		return false;
2106 	}
2107 
isInteger()2108 	bool isInteger() const
2109 	{
2110 		return std::numeric_limits<bool>::is_integer;
2111 	}
2112 
isSigned()2113 	bool isSigned() const
2114 	{
2115 		return std::numeric_limits<bool>::is_signed;
2116 	}
2117 
isNumeric()2118 	bool isNumeric() const
2119 	{
2120 		return std::numeric_limits<bool>::is_specialized;
2121 	}
2122 
isBoolean()2123 	bool isBoolean() const
2124 	{
2125 		return true;
2126 	}
2127 
isString()2128 	bool isString() const
2129 	{
2130 		return false;
2131 	}
2132 
2133 private:
2134 	VarHolderImpl();
2135 	VarHolderImpl(const VarHolderImpl&);
2136 	VarHolderImpl& operator = (const VarHolderImpl&);
2137 
2138 	bool _val;
2139 };
2140 
2141 
2142 template <>
2143 class VarHolderImpl<float>: public VarHolder
2144 {
2145 public:
VarHolderImpl(float val)2146 	VarHolderImpl(float val): _val(val)
2147 	{
2148 	}
2149 
~VarHolderImpl()2150 	~VarHolderImpl()
2151 	{
2152 	}
2153 
type()2154 	const std::type_info& type() const
2155 	{
2156 		return typeid(float);
2157 	}
2158 
convert(Int8 & val)2159 	void convert(Int8& val) const
2160 	{
2161 		convertToSmaller(_val, val);
2162 	}
2163 
convert(Int16 & val)2164 	void convert(Int16& val) const
2165 	{
2166 		convertToSmaller(_val, val);
2167 	}
2168 
convert(Int32 & val)2169 	void convert(Int32& val) const
2170 	{
2171 		convertToSmaller(_val, val);
2172 	}
2173 
convert(Int64 & val)2174 	void convert(Int64& val) const
2175 	{
2176 		convertToSmaller(_val, val);
2177 	}
2178 
convert(UInt8 & val)2179 	void convert(UInt8& val) const
2180 	{
2181 		convertSignedFloatToUnsigned(_val, val);
2182 	}
2183 
convert(UInt16 & val)2184 	void convert(UInt16& val) const
2185 	{
2186 		convertSignedFloatToUnsigned(_val, val);
2187 	}
2188 
convert(UInt32 & val)2189 	void convert(UInt32& val) const
2190 	{
2191 		convertSignedFloatToUnsigned(_val, val);
2192 	}
2193 
convert(UInt64 & val)2194 	void convert(UInt64& val) const
2195 	{
2196 		convertSignedFloatToUnsigned(_val, val);
2197 	}
2198 
2199 #ifdef POCO_INT64_IS_LONG
2200 
convert(long long & val)2201 	void convert(long long& val) const
2202 	{
2203 		convertToSmaller(_val, val);
2204 	}
2205 
convert(unsigned long long & val)2206 	void convert(unsigned long long& val) const
2207 	{
2208 		convertSignedFloatToUnsigned(_val, val);
2209 	}
2210 
2211 #endif
2212 
convert(bool & val)2213 	void convert(bool& val) const
2214 	{
2215 		val = !(_val <= std::numeric_limits<float>::min() &&
2216 			_val >= -1 * std::numeric_limits<float>::min());
2217 	}
2218 
convert(float & val)2219 	void convert(float& val) const
2220 	{
2221 		val = _val;
2222 	}
2223 
convert(double & val)2224 	void convert(double& val) const
2225 	{
2226 		val = _val;
2227 	}
2228 
convert(char & val)2229 	void convert(char& val) const
2230 	{
2231 		UInt8 tmp;
2232 		convert(tmp);
2233 		val = static_cast<char>(tmp);
2234 	}
2235 
convert(std::string & val)2236 	void convert(std::string& val) const
2237 	{
2238 		val = NumberFormatter::format(_val);
2239 	}
2240 
2241 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
2242 	{
2243 		return cloneHolder(pVarHolder, _val);
2244 	}
2245 
value()2246 	const float& value() const
2247 	{
2248 		return _val;
2249 	}
2250 
isArray()2251 	bool isArray() const
2252 	{
2253 		return false;
2254 	}
2255 
isStruct()2256 	bool isStruct() const
2257 	{
2258 		return false;
2259 	}
2260 
isInteger()2261 	bool isInteger() const
2262 	{
2263 		return std::numeric_limits<float>::is_integer;
2264 	}
2265 
isSigned()2266 	bool isSigned() const
2267 	{
2268 		return std::numeric_limits<float>::is_signed;
2269 	}
2270 
isNumeric()2271 	bool isNumeric() const
2272 	{
2273 		return std::numeric_limits<float>::is_specialized;
2274 	}
2275 
isBoolean()2276 	bool isBoolean() const
2277 	{
2278 		return false;
2279 	}
2280 
isString()2281 	bool isString() const
2282 	{
2283 		return false;
2284 	}
2285 
2286 private:
2287 	VarHolderImpl();
2288 	VarHolderImpl(const VarHolderImpl&);
2289 	VarHolderImpl& operator = (const VarHolderImpl&);
2290 
2291 	float _val;
2292 };
2293 
2294 
2295 template <>
2296 class VarHolderImpl<double>: public VarHolder
2297 {
2298 public:
VarHolderImpl(double val)2299 	VarHolderImpl(double val): _val(val)
2300 	{
2301 	}
2302 
~VarHolderImpl()2303 	~VarHolderImpl()
2304 	{
2305 	}
2306 
type()2307 	const std::type_info& type() const
2308 	{
2309 		return typeid(double);
2310 	}
2311 
convert(Int8 & val)2312 	void convert(Int8& val) const
2313 	{
2314 		convertToSmaller(_val, val);
2315 	}
2316 
convert(Int16 & val)2317 	void convert(Int16& val) const
2318 	{
2319 		convertToSmaller(_val, val);
2320 	}
2321 
convert(Int32 & val)2322 	void convert(Int32& val) const
2323 	{
2324 		convertToSmaller(_val, val);
2325 	}
2326 
convert(Int64 & val)2327 	void convert(Int64& val) const
2328 	{
2329 		convertToSmaller(_val, val);
2330 	}
2331 
convert(UInt8 & val)2332 	void convert(UInt8& val) const
2333 	{
2334 		convertSignedFloatToUnsigned(_val, val);
2335 	}
2336 
convert(UInt16 & val)2337 	void convert(UInt16& val) const
2338 	{
2339 		convertSignedFloatToUnsigned(_val, val);
2340 	}
2341 
convert(UInt32 & val)2342 	void convert(UInt32& val) const
2343 	{
2344 		convertSignedFloatToUnsigned(_val, val);
2345 	}
2346 
convert(UInt64 & val)2347 	void convert(UInt64& val) const
2348 	{
2349 		convertSignedFloatToUnsigned(_val, val);
2350 	}
2351 
2352 #ifdef POCO_INT64_IS_LONG
2353 
convert(long long & val)2354 	void convert(long long& val) const
2355 	{
2356 		convertToSmaller(_val, val);
2357 	}
2358 
convert(unsigned long long & val)2359 	void convert(unsigned long long& val) const
2360 	{
2361 		convertSignedFloatToUnsigned(_val, val);
2362 	}
2363 
2364 #endif
2365 
convert(bool & val)2366 	void convert(bool& val) const
2367 	{
2368 		val = !(_val <= std::numeric_limits<double>::min() &&
2369 			_val >= -1 * std::numeric_limits<double>::min());
2370 	}
2371 
convert(float & val)2372 	void convert(float& val) const
2373 	{
2374 		double fMin = -1 * std::numeric_limits<float>::max();
2375 		double fMax = std::numeric_limits<float>::max();
2376 
2377 		if (_val < fMin) throw RangeException("Value too small.");
2378 		if (_val > fMax) throw RangeException("Value too large.");
2379 
2380 		val = static_cast<float>(_val);
2381 	}
2382 
convert(double & val)2383 	void convert(double& val) const
2384 	{
2385 		val = _val;
2386 	}
2387 
convert(char & val)2388 	void convert(char& val) const
2389 	{
2390 		UInt8 tmp;
2391 		convert(tmp);
2392 		val = static_cast<char>(tmp);
2393 	}
2394 
convert(std::string & val)2395 	void convert(std::string& val) const
2396 	{
2397 		val = NumberFormatter::format(_val);
2398 	}
2399 
2400 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
2401 	{
2402 		return cloneHolder(pVarHolder, _val);
2403 	}
2404 
value()2405 	const double& value() const
2406 	{
2407 		return _val;
2408 	}
2409 
isArray()2410 	bool isArray() const
2411 	{
2412 		return false;
2413 	}
2414 
isStruct()2415 	bool isStruct() const
2416 	{
2417 		return false;
2418 	}
2419 
isInteger()2420 	bool isInteger() const
2421 	{
2422 		return std::numeric_limits<double>::is_integer;
2423 	}
2424 
isSigned()2425 	bool isSigned() const
2426 	{
2427 		return std::numeric_limits<double>::is_signed;
2428 	}
2429 
isNumeric()2430 	bool isNumeric() const
2431 	{
2432 		return std::numeric_limits<double>::is_specialized;
2433 	}
2434 
isBoolean()2435 	bool isBoolean() const
2436 	{
2437 		return false;
2438 	}
2439 
isString()2440 	bool isString() const
2441 	{
2442 		return false;
2443 	}
2444 
2445 private:
2446 	VarHolderImpl();
2447 	VarHolderImpl(const VarHolderImpl&);
2448 	VarHolderImpl& operator = (const VarHolderImpl&);
2449 
2450 	double _val;
2451 };
2452 
2453 
2454 template <>
2455 class VarHolderImpl<char>: public VarHolder
2456 {
2457 public:
VarHolderImpl(char val)2458 	VarHolderImpl(char val): _val(val)
2459 	{
2460 	}
2461 
~VarHolderImpl()2462 	~VarHolderImpl()
2463 	{
2464 	}
2465 
type()2466 	const std::type_info& type() const
2467 	{
2468 		return typeid(char);
2469 	}
2470 
convert(Int8 & val)2471 	void convert(Int8& val) const
2472 	{
2473 		val = static_cast<Int8>(_val);
2474 	}
2475 
convert(Int16 & val)2476 	void convert(Int16& val) const
2477 	{
2478 		val = static_cast<UInt8>(_val);
2479 	}
2480 
convert(Int32 & val)2481 	void convert(Int32& val) const
2482 	{
2483 		val = static_cast<UInt8>(_val);
2484 	}
2485 
convert(Int64 & val)2486 	void convert(Int64& val) const
2487 	{
2488 		val = static_cast<UInt8>(_val);
2489 	}
2490 
convert(UInt8 & val)2491 	void convert(UInt8& val) const
2492 	{
2493 		val = static_cast<UInt8>(_val);
2494 	}
2495 
convert(UInt16 & val)2496 	void convert(UInt16& val) const
2497 	{
2498 		val = static_cast<UInt8>(_val);
2499 	}
2500 
convert(UInt32 & val)2501 	void convert(UInt32& val) const
2502 	{
2503 		val = static_cast<UInt8>(_val);
2504 	}
2505 
convert(UInt64 & val)2506 	void convert(UInt64& val) const
2507 	{
2508 		val = static_cast<UInt8>(_val);
2509 	}
2510 
2511 #ifdef POCO_INT64_IS_LONG
2512 
convert(long long & val)2513 	void convert(long long& val) const
2514 	{
2515 		val = static_cast<long long>(_val);
2516 	}
2517 
convert(unsigned long long & val)2518 	void convert(unsigned long long& val) const
2519 	{
2520 		val = static_cast<unsigned long long>(_val);
2521 	}
2522 
2523 #endif
2524 
convert(bool & val)2525 	void convert(bool& val) const
2526 	{
2527 		val = (_val != '\0');
2528 	}
2529 
convert(float & val)2530 	void convert(float& val) const
2531 	{
2532 		val = static_cast<float>(_val);
2533 	}
2534 
convert(double & val)2535 	void convert(double& val) const
2536 	{
2537 		val = static_cast<double>(_val);
2538 	}
2539 
convert(char & val)2540 	void convert(char& val) const
2541 	{
2542 		val = _val;
2543 	}
2544 
convert(std::string & val)2545 	void convert(std::string& val) const
2546 	{
2547 		val = std::string(1, _val);
2548 	}
2549 
2550 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
2551 	{
2552 		return cloneHolder(pVarHolder, _val);
2553 	}
2554 
value()2555 	const char& value() const
2556 	{
2557 		return _val;
2558 	}
2559 
isArray()2560 	bool isArray() const
2561 	{
2562 		return false;
2563 	}
2564 
isStruct()2565 	bool isStruct() const
2566 	{
2567 		return false;
2568 	}
2569 
isInteger()2570 	bool isInteger() const
2571 	{
2572 		return std::numeric_limits<char>::is_integer;
2573 	}
2574 
isSigned()2575 	bool isSigned() const
2576 	{
2577 		return std::numeric_limits<char>::is_signed;
2578 	}
2579 
isNumeric()2580 	bool isNumeric() const
2581 	{
2582 		return std::numeric_limits<char>::is_specialized;
2583 	}
2584 
isBoolean()2585 	bool isBoolean() const
2586 	{
2587 		return false;
2588 	}
2589 
isString()2590 	bool isString() const
2591 	{
2592 		return false;
2593 	}
2594 
2595 private:
2596 	VarHolderImpl();
2597 	VarHolderImpl(const VarHolderImpl&);
2598 	VarHolderImpl& operator = (const VarHolderImpl&);
2599 
2600 	char _val;
2601 };
2602 
2603 
2604 template <>
2605 class VarHolderImpl<std::string>: public VarHolder
2606 {
2607 public:
VarHolderImpl(const char * pVal)2608 	VarHolderImpl(const char* pVal): _val(pVal)
2609 	{
2610 	}
2611 
VarHolderImpl(const std::string & val)2612 	VarHolderImpl(const std::string& val) : _val(val)
2613 	{
2614 	}
2615 
~VarHolderImpl()2616 	~VarHolderImpl()
2617 	{
2618 	}
2619 
type()2620 	const std::type_info& type() const
2621 	{
2622 		return typeid(std::string);
2623 	}
2624 
convert(Int8 & val)2625 	void convert(Int8& val) const
2626 	{
2627 		int v = NumberParser::parse(_val);
2628 		convertToSmaller(v, val);
2629 	}
2630 
convert(Int16 & val)2631 	void convert(Int16& val) const
2632 	{
2633 		int v = NumberParser::parse(_val);
2634 		convertToSmaller(v, val);
2635 	}
2636 
convert(Int32 & val)2637 	void convert(Int32& val) const
2638 	{
2639 		val = NumberParser::parse(_val);
2640 	}
2641 
convert(Int64 & val)2642 	void convert(Int64& val) const
2643 	{
2644 		val = NumberParser::parse64(_val);
2645 	}
2646 
convert(UInt8 & val)2647 	void convert(UInt8& val) const
2648 	{
2649 		unsigned int v = NumberParser::parseUnsigned(_val);
2650 		convertToSmallerUnsigned(v, val);
2651 	}
2652 
convert(UInt16 & val)2653 	void convert(UInt16& val) const
2654 	{
2655 		unsigned int v = NumberParser::parseUnsigned(_val);
2656 		convertToSmallerUnsigned(v, val);
2657 	}
2658 
convert(UInt32 & val)2659 	void convert(UInt32& val) const
2660 	{
2661 		val = NumberParser::parseUnsigned(_val);
2662 	}
2663 
convert(UInt64 & val)2664 	void convert(UInt64& val) const
2665 	{
2666 		val = NumberParser::parseUnsigned64(_val);
2667 	}
2668 
2669 #ifdef POCO_INT64_IS_LONG
2670 
convert(long long & val)2671 	void convert(long long& val) const
2672 	{
2673 		val = NumberParser::parse64(_val);
2674 	}
2675 
convert(unsigned long long & val)2676 	void convert(unsigned long long& val) const
2677 	{
2678 		val = NumberParser::parseUnsigned64(_val);
2679 	}
2680 
2681 #endif
2682 
convert(bool & val)2683 	void convert(bool& val) const
2684 	{
2685 		if (_val.empty())
2686 		{
2687 			val = false;
2688 			return;
2689 		}
2690 
2691 		static const std::string VAL_FALSE("false");
2692 		static const std::string VAL_INT_FALSE("0");
2693 		val = (_val != VAL_INT_FALSE &&
2694 			(icompare(_val, VAL_FALSE) != 0));
2695 	}
2696 
convert(float & val)2697 	void convert(float& val) const
2698 	{
2699 		double v = NumberParser::parseFloat(_val);
2700 		convertToSmaller(v, val);
2701 	}
2702 
convert(double & val)2703 	void convert(double& val) const
2704 	{
2705 		val = NumberParser::parseFloat(_val);
2706 	}
2707 
convert(char & val)2708 	void convert(char& val) const
2709 	{
2710 		if (_val.empty())
2711 			val = '\0';
2712 		else
2713 			val = _val[0];
2714 	}
2715 
convert(std::string & val)2716 	void convert(std::string& val) const
2717 	{
2718 		val = _val;
2719 	}
2720 
convert(Poco::UTF16String & val)2721 	void convert(Poco::UTF16String& val) const
2722 	{
2723 		Poco::UnicodeConverter::convert(_val, val);
2724 	}
2725 
convert(DateTime & val)2726 	void convert(DateTime& val) const
2727 	{
2728 		int tzd = 0;
2729 		if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, val, tzd))
2730 			throw BadCastException("string -> DateTime");
2731 	}
2732 
convert(LocalDateTime & ldt)2733 	void convert(LocalDateTime& ldt) const
2734 	{
2735 		int tzd = 0;
2736 		DateTime tmp;
2737 		if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, tmp, tzd))
2738 			throw BadCastException("string -> LocalDateTime");
2739 
2740 		ldt = LocalDateTime(tzd, tmp, false);
2741 	}
2742 
convert(Timestamp & ts)2743 	void convert(Timestamp& ts) const
2744 	{
2745 		int tzd = 0;
2746 		DateTime tmp;
2747 		if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, tmp, tzd))
2748 			throw BadCastException("string -> Timestamp");
2749 
2750 		ts = tmp.timestamp();
2751 	}
2752 
2753 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
2754 	{
2755 		return cloneHolder(pVarHolder, _val);
2756 	}
2757 
value()2758 	const std:: string& value() const
2759 	{
2760 		return _val;
2761 	}
2762 
isString()2763 	bool isString() const
2764 	{
2765 		return true;
2766 	}
2767 
size()2768 	std::size_t size() const
2769 	{
2770 		return _val.length();
2771 	}
2772 
2773 	char& operator[](std::string::size_type n)
2774 	{
2775 		if (n < size()) return _val.operator[](n);
2776 
2777 		throw RangeException("String index out of range");
2778 	}
2779 
2780 	const char& operator[](std::string::size_type n) const
2781 	{
2782 		if (n < size()) return _val.operator[](n);
2783 
2784 		throw RangeException("String index out of range");
2785 	}
2786 
2787 private:
2788 	VarHolderImpl();
2789 	VarHolderImpl(const VarHolderImpl&);
2790 	VarHolderImpl& operator = (const VarHolderImpl&);
2791 
2792 	std::string _val;
2793 };
2794 
2795 
2796 template <>
2797 class VarHolderImpl<UTF16String>: public VarHolder
2798 {
2799 public:
VarHolderImpl(const char * pVal)2800 	VarHolderImpl(const char* pVal) : _val(Poco::UnicodeConverter::to<UTF16String>(pVal))
2801 	{
2802 	}
2803 
VarHolderImpl(const Poco::UTF16String & val)2804 	VarHolderImpl(const Poco::UTF16String& val) : _val(val)
2805 	{
2806 	}
2807 
~VarHolderImpl()2808 	~VarHolderImpl()
2809 	{
2810 	}
2811 
type()2812 	const std::type_info& type() const
2813 	{
2814 		return typeid(Poco::UTF16String);
2815 	}
2816 
convert(Int8 & val)2817 	void convert(Int8& val) const
2818 	{
2819 		int v = NumberParser::parse(toStdString());
2820 		convertToSmaller(v, val);
2821 	}
2822 
convert(Int16 & val)2823 	void convert(Int16& val) const
2824 	{
2825 		int v = NumberParser::parse(toStdString());
2826 		convertToSmaller(v, val);
2827 	}
2828 
convert(Int32 & val)2829 	void convert(Int32& val) const
2830 	{
2831 		val = NumberParser::parse(toStdString());
2832 	}
2833 
convert(Int64 & val)2834 	void convert(Int64& val) const
2835 	{
2836 		val = NumberParser::parse64(toStdString());
2837 	}
2838 
convert(UInt8 & val)2839 	void convert(UInt8& val) const
2840 	{
2841 		unsigned int v = NumberParser::parseUnsigned(toStdString());
2842 		convertToSmallerUnsigned(v, val);
2843 	}
2844 
convert(UInt16 & val)2845 	void convert(UInt16& val) const
2846 	{
2847 		unsigned int v = NumberParser::parseUnsigned(toStdString());
2848 		convertToSmallerUnsigned(v, val);
2849 	}
2850 
convert(UInt32 & val)2851 	void convert(UInt32& val) const
2852 	{
2853 		val = NumberParser::parseUnsigned(toStdString());
2854 	}
2855 
convert(UInt64 & val)2856 	void convert(UInt64& val) const
2857 	{
2858 		val = NumberParser::parseUnsigned64(toStdString());
2859 	}
2860 
2861 #ifdef POCO_INT64_IS_LONG
2862 
convert(long long & val)2863 	void convert(long long& val) const
2864 	{
2865 		val = NumberParser::parse64(toStdString());
2866 	}
2867 
convert(unsigned long long & val)2868 	void convert(unsigned long long& val) const
2869 	{
2870 		val = NumberParser::parseUnsigned64(toStdString());
2871 	}
2872 
2873 #endif
2874 
convert(bool & val)2875 	void convert(bool& val) const
2876 	{
2877 		static const std::string VAL_FALSE("false");
2878 		static const std::string VAL_INT_FALSE("0");
2879 
2880 		if (_val.empty()) val = false;
2881 
2882 		std::string str;
2883 		UnicodeConverter::convert(_val, str);
2884 		val = (str != VAL_INT_FALSE &&
2885 			(icompare(str, VAL_FALSE) != 0));
2886 	}
2887 
convert(float & val)2888 	void convert(float& val) const
2889 	{
2890 		double v = NumberParser::parseFloat(toStdString());
2891 		convertToSmaller(v, val);
2892 	}
2893 
convert(double & val)2894 	void convert(double& val) const
2895 	{
2896 		val = NumberParser::parseFloat(toStdString());
2897 	}
2898 
convert(char & val)2899 	void convert(char& val) const
2900 	{
2901 		if (_val.empty())
2902 			val = '\0';
2903 		else
2904 		{
2905 			std::string s;
2906 			UnicodeConverter::convert(_val, s);
2907 			val = s[0];
2908 		}
2909 	}
2910 
convert(Poco::UTF16String & val)2911 	void convert(Poco::UTF16String& val) const
2912 	{
2913 		val = _val;
2914 	}
2915 
convert(std::string & val)2916 	void convert(std::string& val) const
2917 	{
2918 		UnicodeConverter::convert(_val, val);
2919 	}
2920 
convert(DateTime & val)2921 	void convert(DateTime& val) const
2922 	{
2923 		int tzd = 0;
2924 		if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, toStdString(), val, tzd))
2925 			throw BadCastException("string -> DateTime");
2926 	}
2927 
convert(LocalDateTime & ldt)2928 	void convert(LocalDateTime& ldt) const
2929 	{
2930 		int tzd = 0;
2931 		DateTime tmp;
2932 		if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, toStdString(), tmp, tzd))
2933 			throw BadCastException("string -> LocalDateTime");
2934 
2935 		ldt = LocalDateTime(tzd, tmp, false);
2936 	}
2937 
convert(Timestamp & ts)2938 	void convert(Timestamp& ts) const
2939 	{
2940 		int tzd = 0;
2941 		DateTime tmp;
2942 		if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, toStdString(), tmp, tzd))
2943 			throw BadCastException("string -> Timestamp");
2944 
2945 		ts = tmp.timestamp();
2946 	}
2947 
2948 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
2949 	{
2950 		return cloneHolder(pVarHolder, _val);
2951 	}
2952 
value()2953 	const Poco::UTF16String& value() const
2954 	{
2955 		return _val;
2956 	}
2957 
isString()2958 	bool isString() const
2959 	{
2960 		return true;
2961 	}
2962 
size()2963 	std::size_t size() const
2964 	{
2965 		return _val.length();
2966 	}
2967 
2968 	UTF16Char& operator[](Poco::UTF16String::size_type n)
2969 	{
2970 		if (n < size()) return _val.operator[](n);
2971 
2972 		throw RangeException("String index out of range");
2973 	}
2974 
2975 	const UTF16Char& operator[](Poco::UTF16String::size_type n) const
2976 	{
2977 		if (n < size()) return _val.operator[](n);
2978 
2979 		throw RangeException("String index out of range");
2980 	}
2981 
2982 private:
2983 	VarHolderImpl();
2984 	VarHolderImpl(const VarHolderImpl&);
2985 	VarHolderImpl& operator = (const VarHolderImpl&);
2986 
toStdString()2987 	std::string toStdString() const
2988 	{
2989 		std::string str;
2990 		UnicodeConverter::convert(_val, str);
2991 		return str;
2992 	}
2993 
2994 	Poco::UTF16String _val;
2995 };
2996 
2997 
2998 #ifndef POCO_INT64_IS_LONG
2999 
3000 
3001 template <>
3002 class VarHolderImpl<long>: public VarHolder
3003 {
3004 public:
VarHolderImpl(long val)3005 	VarHolderImpl(long val): _val(val)
3006 	{
3007 	}
3008 
~VarHolderImpl()3009 	~VarHolderImpl()
3010 	{
3011 	}
3012 
type()3013 	const std::type_info& type() const
3014 	{
3015 		return typeid(long);
3016 	}
3017 
convert(Int8 & val)3018 	void convert(Int8& val) const
3019 	{
3020 		convertToSmaller(_val, val);
3021 	}
3022 
convert(Int16 & val)3023 	void convert(Int16& val) const
3024 	{
3025 		convertToSmaller(_val, val);
3026 	}
3027 
convert(Int32 & val)3028 	void convert(Int32& val) const
3029 	{
3030 		val = static_cast<Int32>(_val);
3031 	}
3032 
convert(Int64 & val)3033 	void convert(Int64& val) const
3034 	{
3035 		val = static_cast<Int64>(_val);
3036 	}
3037 
convert(UInt8 & val)3038 	void convert(UInt8& val) const
3039 	{
3040 		convertSignedToUnsigned(_val, val);
3041 	}
3042 
convert(UInt16 & val)3043 	void convert(UInt16& val) const
3044 	{
3045 		convertSignedToUnsigned(_val, val);
3046 	}
3047 
convert(UInt32 & val)3048 	void convert(UInt32& val) const
3049 	{
3050 		convertSignedToUnsigned(_val, val);
3051 	}
3052 
convert(UInt64 & val)3053 	void convert(UInt64& val) const
3054 	{
3055 		convertSignedToUnsigned(_val, val);
3056 	}
3057 
convert(bool & val)3058 	void convert(bool& val) const
3059 	{
3060 		val = (_val != 0);
3061 	}
3062 
convert(float & val)3063 	void convert(float& val) const
3064 	{
3065 		val = static_cast<float>(_val);
3066 	}
3067 
convert(double & val)3068 	void convert(double& val) const
3069 	{
3070 		val = static_cast<double>(_val);
3071 	}
3072 
convert(char & val)3073 	void convert(char& val) const
3074 	{
3075 		UInt8 tmp;
3076 		convert(tmp);
3077 		val = static_cast<char>(tmp);
3078 	}
3079 
convert(std::string & val)3080 	void convert(std::string& val) const
3081 	{
3082 		val = NumberFormatter::format(_val);
3083 	}
3084 
3085 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
3086 	{
3087 		return cloneHolder(pVarHolder, _val);
3088 	}
3089 
value()3090 	const long& value() const
3091 	{
3092 		return _val;
3093 	}
3094 
isArray()3095 	bool isArray() const
3096 	{
3097 		return false;
3098 	}
3099 
isStruct()3100 	bool isStruct() const
3101 	{
3102 		return false;
3103 	}
3104 
isInteger()3105 	bool isInteger() const
3106 	{
3107 		return std::numeric_limits<long>::is_integer;
3108 	}
3109 
isSigned()3110 	bool isSigned() const
3111 	{
3112 		return std::numeric_limits<long>::is_signed;
3113 	}
3114 
isNumeric()3115 	bool isNumeric() const
3116 	{
3117 		return std::numeric_limits<long>::is_specialized;
3118 	}
3119 
isBoolean()3120 	bool isBoolean() const
3121 	{
3122 		return false;
3123 	}
3124 
isString()3125 	bool isString() const
3126 	{
3127 		return false;
3128 	}
3129 
3130 private:
3131 	VarHolderImpl();
3132 	VarHolderImpl(const VarHolderImpl&);
3133 	VarHolderImpl& operator = (const VarHolderImpl&);
3134 
3135 	long _val;
3136 };
3137 
3138 
3139 template <>
3140 class VarHolderImpl<unsigned long>: public VarHolder
3141 {
3142 public:
VarHolderImpl(unsigned long val)3143 	VarHolderImpl(unsigned long val): _val(val)
3144 	{
3145 	}
3146 
~VarHolderImpl()3147 	~VarHolderImpl()
3148 	{
3149 	}
3150 
type()3151 	const std::type_info& type() const
3152 	{
3153 		return typeid(unsigned long);
3154 	}
3155 
convert(Int8 & val)3156 	void convert(Int8& val) const
3157 	{
3158 		convertUnsignedToSigned(_val, val);
3159 	}
3160 
convert(Int16 & val)3161 	void convert(Int16& val) const
3162 	{
3163 		convertUnsignedToSigned(_val, val);
3164 	}
3165 
convert(Int32 & val)3166 	void convert(Int32& val) const
3167 	{
3168 		convertUnsignedToSigned(_val, val);
3169 	}
3170 
convert(Int64 & val)3171 	void convert(Int64& val) const
3172 	{
3173 		convertUnsignedToSigned(_val, val);
3174 	}
3175 
convert(UInt8 & val)3176 	void convert(UInt8& val) const
3177 	{
3178 		convertToSmallerUnsigned(_val, val);
3179 	}
3180 
convert(UInt16 & val)3181 	void convert(UInt16& val) const
3182 	{
3183 		convertToSmallerUnsigned(_val, val);
3184 	}
3185 
convert(UInt32 & val)3186 	void convert(UInt32& val) const
3187 	{
3188 		convertToSmallerUnsigned(_val, val);
3189 	}
3190 
convert(UInt64 & val)3191 	void convert(UInt64& val) const
3192 	{
3193 		val = static_cast<UInt64>(_val);
3194 	}
3195 
convert(bool & val)3196 	void convert(bool& val) const
3197 	{
3198 		val = (_val != 0);
3199 	}
3200 
convert(float & val)3201 	void convert(float& val) const
3202 	{
3203 		val = static_cast<float>(_val);
3204 	}
3205 
convert(double & val)3206 	void convert(double& val) const
3207 	{
3208 		val = static_cast<double>(_val);
3209 	}
3210 
convert(char & val)3211 	void convert(char& val) const
3212 	{
3213 		UInt8 tmp;
3214 		convert(tmp);
3215 		val = static_cast<char>(tmp);
3216 	}
3217 
convert(std::string & val)3218 	void convert(std::string& val) const
3219 	{
3220 		val = NumberFormatter::format(_val);
3221 	}
3222 
3223 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
3224 	{
3225 		return cloneHolder(pVarHolder, _val);
3226 	}
3227 
value()3228 	const unsigned long& value() const
3229 	{
3230 		return _val;
3231 	}
3232 
isArray()3233 	bool isArray() const
3234 	{
3235 		return false;
3236 	}
3237 
isStruct()3238 	bool isStruct() const
3239 	{
3240 		return false;
3241 	}
3242 
isInteger()3243 	bool isInteger() const
3244 	{
3245 		return std::numeric_limits<unsigned long>::is_integer;
3246 	}
3247 
isSigned()3248 	bool isSigned() const
3249 	{
3250 		return std::numeric_limits<unsigned long>::is_signed;
3251 	}
3252 
isNumeric()3253 	bool isNumeric() const
3254 	{
3255 		return std::numeric_limits<unsigned long>::is_specialized;
3256 	}
3257 
isBoolean()3258 	bool isBoolean() const
3259 	{
3260 		return false;
3261 	}
3262 
isString()3263 	bool isString() const
3264 	{
3265 		return false;
3266 	}
3267 
3268 private:
3269 	VarHolderImpl();
3270 	VarHolderImpl(const VarHolderImpl&);
3271 	VarHolderImpl& operator = (const VarHolderImpl&);
3272 
3273 	unsigned long _val;
3274 };
3275 
3276 
3277 #else // if defined (POCO_INT64_IS_LONG)
3278 
3279 
3280 template <>
3281 class VarHolderImpl<long long>: public VarHolder
3282 {
3283 public:
VarHolderImpl(long long val)3284 	VarHolderImpl(long long val): _val(val)
3285 	{
3286 	}
3287 
~VarHolderImpl()3288 	~VarHolderImpl()
3289 	{
3290 	}
3291 
type()3292 	const std::type_info& type() const
3293 	{
3294 		return typeid(long long);
3295 	}
3296 
convert(Int8 & val)3297 	void convert(Int8& val) const
3298 	{
3299 		convertToSmaller(_val, val);
3300 	}
3301 
convert(Int16 & val)3302 	void convert(Int16& val) const
3303 	{
3304 		convertToSmaller(_val, val);
3305 	}
3306 
convert(Int32 & val)3307 	void convert(Int32& val) const
3308 	{
3309 		convertToSmaller(_val, val);
3310 	}
3311 
convert(Int64 & val)3312 	void convert(Int64& val) const
3313 	{
3314 		val = static_cast<Int64>(_val);
3315 	}
3316 
convert(UInt8 & val)3317 	void convert(UInt8& val) const
3318 	{
3319 		convertSignedToUnsigned(_val, val);
3320 	}
3321 
convert(UInt16 & val)3322 	void convert(UInt16& val) const
3323 	{
3324 		convertSignedToUnsigned(_val, val);
3325 	}
3326 
convert(UInt32 & val)3327 	void convert(UInt32& val) const
3328 	{
3329 		convertSignedToUnsigned(_val, val);
3330 	}
3331 
convert(UInt64 & val)3332 	void convert(UInt64& val) const
3333 	{
3334 		convertSignedToUnsigned(_val, val);
3335 	}
3336 
convert(long long & val)3337 	void convert(long long& val) const
3338 	{
3339 		val = _val;
3340 	}
3341 
convert(unsigned long long & val)3342 	void convert(unsigned long long& val) const
3343 	{
3344 		convertSignedToUnsigned(_val, val);
3345 	}
3346 
convert(bool & val)3347 	void convert(bool& val) const
3348 	{
3349 		val = (_val != 0);
3350 	}
3351 
convert(float & val)3352 	void convert(float& val) const
3353 	{
3354 		val = static_cast<float>(_val);
3355 	}
3356 
convert(double & val)3357 	void convert(double& val) const
3358 	{
3359 		val = static_cast<double>(_val);
3360 	}
3361 
convert(char & val)3362 	void convert(char& val) const
3363 	{
3364 		UInt8 tmp;
3365 		convert(tmp);
3366 		val = static_cast<char>(tmp);
3367 	}
3368 
convert(std::string & val)3369 	void convert(std::string& val) const
3370 	{
3371 		val = NumberFormatter::format(_val);
3372 	}
3373 
3374 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
3375 	{
3376 		return cloneHolder(pVarHolder, _val);
3377 	}
3378 
value()3379 	const long long& value() const
3380 	{
3381 		return _val;
3382 	}
3383 
isArray()3384 	bool isArray() const
3385 	{
3386 		return false;
3387 	}
3388 
isStruct()3389 	bool isStruct() const
3390 	{
3391 		return false;
3392 	}
3393 
isInteger()3394 	bool isInteger() const
3395 	{
3396 		return std::numeric_limits<long long>::is_integer;
3397 	}
3398 
isSigned()3399 	bool isSigned() const
3400 	{
3401 		return std::numeric_limits<long long>::is_signed;
3402 	}
3403 
isNumeric()3404 	bool isNumeric() const
3405 	{
3406 		return std::numeric_limits<long long>::is_specialized;
3407 	}
3408 
isBoolean()3409 	bool isBoolean() const
3410 	{
3411 		return false;
3412 	}
3413 
isString()3414 	bool isString() const
3415 	{
3416 		return false;
3417 	}
3418 
3419 private:
3420 	VarHolderImpl();
3421 	VarHolderImpl(const VarHolderImpl&);
3422 	VarHolderImpl& operator = (const VarHolderImpl&);
3423 
3424 	long long _val;
3425 };
3426 
3427 
3428 template <>
3429 class VarHolderImpl<unsigned long long>: public VarHolder
3430 {
3431 public:
VarHolderImpl(unsigned long long val)3432 	VarHolderImpl(unsigned long long val): _val(val)
3433 	{
3434 	}
3435 
~VarHolderImpl()3436 	~VarHolderImpl()
3437 	{
3438 	}
3439 
type()3440 	const std::type_info& type() const
3441 	{
3442 		return typeid(unsigned long long);
3443 	}
3444 
convert(Int8 & val)3445 	void convert(Int8& val) const
3446 	{
3447 		convertUnsignedToSigned(_val, val);
3448 	}
3449 
convert(Int16 & val)3450 	void convert(Int16& val) const
3451 	{
3452 		convertUnsignedToSigned(_val, val);
3453 	}
3454 
convert(Int32 & val)3455 	void convert(Int32& val) const
3456 	{
3457 		convertUnsignedToSigned(_val, val);
3458 	}
3459 
convert(Int64 & val)3460 	void convert(Int64& val) const
3461 	{
3462 		convertUnsignedToSigned(_val, val);
3463 	}
3464 
convert(UInt8 & val)3465 	void convert(UInt8& val) const
3466 	{
3467 		convertToSmallerUnsigned(_val, val);
3468 	}
3469 
convert(UInt16 & val)3470 	void convert(UInt16& val) const
3471 	{
3472 		convertToSmallerUnsigned(_val, val);
3473 	}
3474 
convert(UInt32 & val)3475 	void convert(UInt32& val) const
3476 	{
3477 		convertToSmallerUnsigned(_val, val);
3478 	}
3479 
convert(UInt64 & val)3480 	void convert(UInt64& val) const
3481 	{
3482 		val = static_cast<UInt64>(_val);
3483 	}
3484 
convert(long long & val)3485 	void convert(long long& val) const
3486 	{
3487 		convertUnsignedToSigned(_val, val);
3488 	}
3489 
convert(unsigned long long & val)3490 	void convert(unsigned long long& val) const
3491 	{
3492 		val = _val;
3493 	}
3494 
convert(bool & val)3495 	void convert(bool& val) const
3496 	{
3497 		val = (_val != 0);
3498 	}
3499 
convert(float & val)3500 	void convert(float& val) const
3501 	{
3502 		val = static_cast<float>(_val);
3503 	}
3504 
convert(double & val)3505 	void convert(double& val) const
3506 	{
3507 		val = static_cast<double>(_val);
3508 	}
3509 
convert(char & val)3510 	void convert(char& val) const
3511 	{
3512 		UInt8 tmp;
3513 		convert(tmp);
3514 		val = static_cast<char>(tmp);
3515 	}
3516 
convert(std::string & val)3517 	void convert(std::string& val) const
3518 	{
3519 		val = NumberFormatter::format(_val);
3520 	}
3521 
3522 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
3523 	{
3524 		return cloneHolder(pVarHolder, _val);
3525 	}
3526 
value()3527 	const unsigned long long& value() const
3528 	{
3529 		return _val;
3530 	}
3531 
isArray()3532 	bool isArray() const
3533 	{
3534 		return false;
3535 	}
3536 
isStruct()3537 	bool isStruct() const
3538 	{
3539 		return false;
3540 	}
3541 
isInteger()3542 	bool isInteger() const
3543 	{
3544 		return std::numeric_limits<unsigned long long>::is_integer;
3545 	}
3546 
isSigned()3547 	bool isSigned() const
3548 	{
3549 		return std::numeric_limits<unsigned long long>::is_signed;
3550 	}
3551 
isNumeric()3552 	bool isNumeric() const
3553 	{
3554 		return std::numeric_limits<unsigned long long>::is_specialized;
3555 	}
3556 
isBoolean()3557 	bool isBoolean() const
3558 	{
3559 		return false;
3560 	}
3561 
isString()3562 	bool isString() const
3563 	{
3564 		return false;
3565 	}
3566 
3567 private:
3568 	VarHolderImpl();
3569 	VarHolderImpl(const VarHolderImpl&);
3570 	VarHolderImpl& operator = (const VarHolderImpl&);
3571 
3572 	unsigned long long _val;
3573 };
3574 
3575 
3576 #endif // POCO_INT64_IS_LONG
3577 
3578 
3579 template <typename T>
3580 class VarHolderImpl<std::vector<T>>: public VarHolder
3581 {
3582 public:
VarHolderImpl(const std::vector<T> & val)3583 	VarHolderImpl(const std::vector<T>& val): _val(val)
3584 	{
3585 	}
3586 
~VarHolderImpl()3587 	~VarHolderImpl()
3588 	{
3589 	}
3590 
type()3591 	const std::type_info& type() const
3592 	{
3593 		return typeid(std::vector<T>);
3594 	}
3595 
convert(std::string & val)3596 	void convert(std::string& val) const
3597 	{
3598 		Impl::containerToJSON(_val, val);
3599 	}
3600 
3601 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
3602 	{
3603 		return cloneHolder(pVarHolder, _val);
3604 	}
3605 
value()3606 	const std::vector<T>& value() const
3607 	{
3608 		return _val;
3609 	}
3610 
isVector()3611 	bool isVector() const
3612 	{
3613 		return true;
3614 	}
3615 
size()3616 	std::size_t size() const
3617 	{
3618 		return _val.size();
3619 	}
3620 
3621 	T& operator[](typename std::vector<T>::size_type n)
3622 	{
3623 		if (n < size()) return _val.operator[](n);
3624 
3625 		throw RangeException("List index out of range");
3626 	}
3627 
3628 	const T& operator[](typename std::vector<T>::size_type n) const
3629 	{
3630 		if (n < size()) return _val.operator[](n);
3631 
3632 		throw RangeException("List index out of range");
3633 	}
3634 
3635 private:
3636 	VarHolderImpl();
3637 	VarHolderImpl(const VarHolderImpl&);
3638 	VarHolderImpl& operator = (const VarHolderImpl&);
3639 
3640 	std::vector<T> _val;
3641 };
3642 
3643 
3644 template <typename T>
3645 class VarHolderImpl<std::list<T>>: public VarHolder
3646 {
3647 public:
VarHolderImpl(const std::list<T> & val)3648 	VarHolderImpl(const std::list<T>& val): _val(val)
3649 	{
3650 	}
3651 
~VarHolderImpl()3652 	~VarHolderImpl()
3653 	{
3654 	}
3655 
type()3656 	const std::type_info& type() const
3657 	{
3658 		return typeid(std::list<T>);
3659 	}
3660 
convert(std::string & val)3661 	void convert(std::string& val) const
3662 	{
3663 		Impl::containerToJSON(_val, val);
3664 	}
3665 
3666 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
3667 	{
3668 		return cloneHolder(pVarHolder, _val);
3669 	}
3670 
value()3671 	const std::list<T>& value() const
3672 	{
3673 		return _val;
3674 	}
3675 
isList()3676 	bool isList() const
3677 	{
3678 		return true;
3679 	}
3680 
size()3681 	std::size_t size() const
3682 	{
3683 		return _val.size();
3684 	}
3685 
3686 	T& operator[](typename std::list<T>::size_type n)
3687 	{
3688 		if (n >= size())
3689 			throw RangeException("List index out of range");
3690 
3691 		typename std::list<T>::size_type counter = 0;
3692 		typename std::list<T>::iterator it = _val.begin();
3693 		for (; counter < n; ++counter) ++it;
3694 
3695 		return *it;
3696 	}
3697 
3698 	const T& operator[](typename std::list<T>::size_type n) const
3699 	{
3700 		if (n >= size())
3701 			throw RangeException("List index out of range");
3702 
3703 		typename std::list<T>::size_type counter = 0;
3704 		typename std::list<T>::const_iterator it = _val.begin();
3705 		for (; counter < n; ++counter) ++it;
3706 
3707 		return *it;
3708 	}
3709 
3710 private:
3711 	VarHolderImpl();
3712 	VarHolderImpl(const VarHolderImpl&);
3713 	VarHolderImpl& operator = (const VarHolderImpl&);
3714 
3715 	std::list<T> _val;
3716 };
3717 
3718 
3719 template <typename T>
3720 class VarHolderImpl<std::deque<T>>: public VarHolder
3721 {
3722 public:
VarHolderImpl(const std::deque<T> & val)3723 	VarHolderImpl(const std::deque<T>& val): _val(val)
3724 	{
3725 	}
3726 
~VarHolderImpl()3727 	~VarHolderImpl()
3728 	{
3729 	}
3730 
type()3731 	const std::type_info& type() const
3732 	{
3733 		return typeid(std::deque<T>);
3734 	}
3735 
convert(std::string & val)3736 	void convert(std::string& val) const
3737 	{
3738 		Impl::containerToJSON(_val, val);
3739 	}
3740 
3741 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
3742 	{
3743 		return cloneHolder(pVarHolder, _val);
3744 	}
3745 
value()3746 	const std::deque<T>& value() const
3747 	{
3748 		return _val;
3749 	}
3750 
isDeque()3751 	bool isDeque() const
3752 	{
3753 		return true;
3754 	}
3755 
size()3756 	std::size_t size() const
3757 	{
3758 		return _val.size();
3759 	}
3760 
3761 	T& operator[](typename std::deque<T>::size_type n)
3762 	{
3763 		if (n < size()) return _val.operator[](n);
3764 
3765 		throw RangeException("List index out of range");
3766 	}
3767 
3768 	const T& operator[](typename std::deque<T>::size_type n) const
3769 	{
3770 		if (n < size()) return _val.operator[](n);
3771 
3772 		throw RangeException("List index out of range");
3773 	}
3774 
3775 private:
3776 	VarHolderImpl();
3777 	VarHolderImpl(const VarHolderImpl&);
3778 	VarHolderImpl& operator = (const VarHolderImpl&);
3779 
3780 	std::deque<T> _val;
3781 };
3782 
3783 
3784 template <>
3785 class VarHolderImpl<DateTime>: public VarHolder
3786 {
3787 public:
VarHolderImpl(const DateTime & val)3788 	VarHolderImpl(const DateTime& val): _val(val)
3789 	{
3790 	}
3791 
~VarHolderImpl()3792 	~VarHolderImpl()
3793 	{
3794 	}
3795 
type()3796 	const std::type_info& type() const
3797 	{
3798 		return typeid(DateTime);
3799 	}
3800 
convert(Int8 &)3801 	void convert(Int8& /*val*/) const
3802 	{
3803 		throw BadCastException();
3804 	}
3805 
convert(Int16 &)3806 	void convert(Int16& /*val*/) const
3807 	{
3808 		throw BadCastException();
3809 	}
3810 
convert(Int32 &)3811 	void convert(Int32& /*val*/) const
3812 	{
3813 		throw BadCastException();
3814 	}
3815 
convert(Int64 & val)3816 	void convert(Int64& val) const
3817 	{
3818 		val = _val.timestamp().epochMicroseconds();
3819 	}
3820 
convert(UInt64 & val)3821 	void convert(UInt64& val) const
3822 	{
3823 		val = _val.timestamp().epochMicroseconds();
3824 	}
3825 
3826 #ifdef POCO_INT64_IS_LONG
3827 
convert(long long & val)3828 	void convert(long long& val) const
3829 	{
3830 		val = _val.timestamp().epochMicroseconds();
3831 	}
3832 
convert(unsigned long long & val)3833 	void convert(unsigned long long& val) const
3834 	{
3835 		val = _val.timestamp().epochMicroseconds();
3836 	}
3837 
3838 #endif
3839 
convert(std::string & val)3840 	void convert(std::string& val) const
3841 	{
3842 		val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT);
3843 	}
3844 
convert(DateTime & val)3845 	void convert(DateTime& val) const
3846 	{
3847 		val = _val;
3848 	}
3849 
convert(LocalDateTime & ldt)3850 	void convert(LocalDateTime& ldt) const
3851 	{
3852 		ldt = _val.timestamp();
3853 	}
3854 
convert(Timestamp & ts)3855 	void convert(Timestamp& ts) const
3856 	{
3857 		ts = _val.timestamp();
3858 	}
3859 
3860 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
3861 	{
3862 		return cloneHolder(pVarHolder, _val);
3863 	}
3864 
value()3865 	const DateTime& value() const
3866 	{
3867 		return _val;
3868 	}
3869 
isArray()3870 	bool isArray() const
3871 	{
3872 		return false;
3873 	}
3874 
isStruct()3875 	bool isStruct() const
3876 	{
3877 		return false;
3878 	}
3879 
isInteger()3880 	bool isInteger() const
3881 	{
3882 		return false;
3883 	}
3884 
isSigned()3885 	bool isSigned() const
3886 	{
3887 		return false;
3888 	}
3889 
isNumeric()3890 	bool isNumeric() const
3891 	{
3892 		return false;
3893 	}
3894 
isBoolean()3895 	bool isBoolean() const
3896 	{
3897 		return false;
3898 	}
3899 
isString()3900 	bool isString() const
3901 	{
3902 		return false;
3903 	}
3904 
isDate()3905 	bool isDate() const
3906 	{
3907 		return true;
3908 	}
3909 
isTime()3910 	bool isTime() const
3911 	{
3912 		return true;
3913 	}
3914 
isDateTime()3915 	bool isDateTime() const
3916 	{
3917 		return true;
3918 	}
3919 
3920 private:
3921 	VarHolderImpl();
3922 	VarHolderImpl(const VarHolderImpl&);
3923 	VarHolderImpl& operator = (const VarHolderImpl&);
3924 
3925 	DateTime _val;
3926 };
3927 
3928 
3929 template <>
3930 class VarHolderImpl<LocalDateTime>: public VarHolder
3931 {
3932 public:
VarHolderImpl(const LocalDateTime & val)3933 	VarHolderImpl(const LocalDateTime& val): _val(val)
3934 	{
3935 	}
3936 
~VarHolderImpl()3937 	~VarHolderImpl()
3938 	{
3939 	}
3940 
type()3941 	const std::type_info& type() const
3942 	{
3943 		return typeid(LocalDateTime);
3944 	}
3945 
convert(Int64 & val)3946 	void convert(Int64& val) const
3947 	{
3948 		val = _val.timestamp().epochMicroseconds();
3949 	}
3950 
convert(UInt64 & val)3951 	void convert(UInt64& val) const
3952 	{
3953 		val = _val.timestamp().epochMicroseconds();
3954 	}
3955 
3956 #ifdef POCO_INT64_IS_LONG
3957 
convert(long long & val)3958 	void convert(long long& val) const
3959 	{
3960 		val = _val.timestamp().epochMicroseconds();
3961 	}
3962 
convert(unsigned long long & val)3963 	void convert(unsigned long long& val) const
3964 	{
3965 		val = _val.timestamp().epochMicroseconds();
3966 	}
3967 
3968 #endif
3969 
convert(std::string & val)3970 	void convert(std::string& val) const
3971 	{
3972 		val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT);
3973 	}
3974 
convert(DateTime & val)3975 	void convert(DateTime& val) const
3976 	{
3977 		val = _val.timestamp();
3978 	}
3979 
convert(LocalDateTime & ldt)3980 	void convert(LocalDateTime& ldt) const
3981 	{
3982 		ldt = _val;
3983 	}
3984 
convert(Timestamp & ts)3985 	void convert(Timestamp& ts) const
3986 	{
3987 		ts = _val.timestamp();
3988 	}
3989 
3990 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
3991 	{
3992 		return cloneHolder(pVarHolder, _val);
3993 	}
3994 
value()3995 	const LocalDateTime& value() const
3996 	{
3997 		return _val;
3998 	}
3999 
isArray()4000 	bool isArray() const
4001 	{
4002 		return false;
4003 	}
4004 
isStruct()4005 	bool isStruct() const
4006 	{
4007 		return false;
4008 	}
4009 
isInteger()4010 	bool isInteger() const
4011 	{
4012 		return false;
4013 	}
4014 
isSigned()4015 	bool isSigned() const
4016 	{
4017 		return false;
4018 	}
4019 
isNumeric()4020 	bool isNumeric() const
4021 	{
4022 		return false;
4023 	}
4024 
isBoolean()4025 	bool isBoolean() const
4026 	{
4027 		return false;
4028 	}
4029 
isString()4030 	bool isString() const
4031 	{
4032 		return false;
4033 	}
4034 
isDate()4035 	bool isDate() const
4036 	{
4037 		return true;
4038 	}
4039 
isTime()4040 	bool isTime() const
4041 	{
4042 		return true;
4043 	}
4044 
isDateTime()4045 	bool isDateTime() const
4046 	{
4047 		return true;
4048 	}
4049 
4050 private:
4051 	VarHolderImpl();
4052 	VarHolderImpl(const VarHolderImpl&);
4053 	VarHolderImpl& operator = (const VarHolderImpl&);
4054 
4055 	LocalDateTime _val;
4056 };
4057 
4058 
4059 template <>
4060 class VarHolderImpl<Timestamp>: public VarHolder
4061 {
4062 public:
VarHolderImpl(const Timestamp & val)4063 	VarHolderImpl(const Timestamp& val): _val(val)
4064 	{
4065 	}
4066 
~VarHolderImpl()4067 	~VarHolderImpl()
4068 	{
4069 	}
4070 
type()4071 	const std::type_info& type() const
4072 	{
4073 		return typeid(Timestamp);
4074 	}
4075 
convert(Int64 & val)4076 	void convert(Int64& val) const
4077 	{
4078 		val = _val.epochMicroseconds();
4079 	}
4080 
convert(UInt64 & val)4081 	void convert(UInt64& val) const
4082 	{
4083 		val = _val.epochMicroseconds();
4084 	}
4085 
4086 #ifdef POCO_INT64_IS_LONG
4087 
convert(long long & val)4088 	void convert(long long& val) const
4089 	{
4090 		val = _val.epochMicroseconds();
4091 	}
4092 
convert(unsigned long long & val)4093 	void convert(unsigned long long& val) const
4094 	{
4095 		val = _val.epochMicroseconds();
4096 	}
4097 
4098 #endif
4099 
convert(std::string & val)4100 	void convert(std::string& val) const
4101 	{
4102 		val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT);
4103 	}
4104 
convert(DateTime & val)4105 	void convert(DateTime& val) const
4106 	{
4107 		val = _val;
4108 	}
4109 
convert(LocalDateTime & ldt)4110 	void convert(LocalDateTime& ldt) const
4111 	{
4112 		ldt = _val;
4113 	}
4114 
convert(Timestamp & ts)4115 	void convert(Timestamp& ts) const
4116 	{
4117 		ts = _val;
4118 	}
4119 
4120 	VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
4121 	{
4122 		return cloneHolder(pVarHolder, _val);
4123 	}
4124 
value()4125 	const Timestamp& value() const
4126 	{
4127 		return _val;
4128 	}
4129 
isArray()4130 	bool isArray() const
4131 	{
4132 		return false;
4133 	}
4134 
isStruct()4135 	bool isStruct() const
4136 	{
4137 		return false;
4138 	}
4139 
isInteger()4140 	bool isInteger() const
4141 	{
4142 		return false;
4143 	}
4144 
isSigned()4145 	bool isSigned() const
4146 	{
4147 		return false;
4148 	}
4149 
isNumeric()4150 	bool isNumeric() const
4151 	{
4152 		return false;
4153 	}
4154 
isBoolean()4155 	bool isBoolean() const
4156 	{
4157 		return false;
4158 	}
4159 
isString()4160 	bool isString() const
4161 	{
4162 		return false;
4163 	}
4164 
isDate()4165 	bool isDate() const
4166 	{
4167 		return true;
4168 	}
4169 
isTime()4170 	bool isTime() const
4171 	{
4172 		return true;
4173 	}
4174 
isDateTime()4175 	bool isDateTime() const
4176 	{
4177 		return true;
4178 	}
4179 
4180 private:
4181 	VarHolderImpl();
4182 	VarHolderImpl(const VarHolderImpl&);
4183 	VarHolderImpl& operator = (const VarHolderImpl&);
4184 
4185 	Timestamp _val;
4186 };
4187 
4188 
4189 typedef std::vector<Var> Vector;
4190 typedef std::deque<Var>  Deque;
4191 typedef std::list<Var>   List;
4192 typedef Vector           Array;
4193 
4194 
4195 } } // namespace Poco::Dynamic
4196 
4197 
4198 #endif // Foundation_VarHolder_INCLUDED
4199