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