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