1 | // |
---|
2 | // DynamicAnyHolder.h |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/Foundation/include/Poco/DynamicAnyHolder.h#5 $ |
---|
5 | // |
---|
6 | // Library: Foundation |
---|
7 | // Package: Core |
---|
8 | // Module: DynamicAnyHolder |
---|
9 | // |
---|
10 | // Definition of the DynamicAnyHolder class. |
---|
11 | // |
---|
12 | // Copyright (c) 2007, Applied Informatics Software Engineering GmbH. |
---|
13 | // and Contributors. |
---|
14 | // |
---|
15 | // Permission is hereby granted, free of charge, to any person or organization |
---|
16 | // obtaining a copy of the software and accompanying documentation covered by |
---|
17 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
18 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
19 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
20 | // do so, all subject to the following: |
---|
21 | // |
---|
22 | // The copyright notices in the Software and this entire statement, including |
---|
23 | // the above license grant, this restriction and the following disclaimer, |
---|
24 | // must be included in all copies of the Software, in whole or in part, and |
---|
25 | // all derivative works of the Software, unless such copies or derivative |
---|
26 | // works are solely in the form of machine-executable object code generated by |
---|
27 | // a source language processor. |
---|
28 | // |
---|
29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
35 | // DEALINGS IN THE SOFTWARE. |
---|
36 | // |
---|
37 | |
---|
38 | |
---|
39 | #ifndef Foundation_DynamicAnyHolder_INCLUDED |
---|
40 | #define Foundation_DynamicAnyHolder_INCLUDED |
---|
41 | |
---|
42 | |
---|
43 | #include "Poco/Foundation.h" |
---|
44 | #include "Poco/NumberFormatter.h" |
---|
45 | #include "Poco/NumberParser.h" |
---|
46 | #include "Poco/DateTime.h" |
---|
47 | #include "Poco/Timestamp.h" |
---|
48 | #include "Poco/LocalDateTime.h" |
---|
49 | #include "Poco/DateTimeFormat.h" |
---|
50 | #include "Poco/DateTimeFormatter.h" |
---|
51 | #include "Poco/DateTimeParser.h" |
---|
52 | #include "Poco/String.h" |
---|
53 | #include "Poco/Exception.h" |
---|
54 | #include <vector> |
---|
55 | #include <typeinfo> |
---|
56 | #undef min |
---|
57 | #undef max |
---|
58 | #include <limits> |
---|
59 | |
---|
60 | |
---|
61 | namespace Poco { |
---|
62 | |
---|
63 | |
---|
64 | class DynamicAny; |
---|
65 | |
---|
66 | |
---|
67 | class Foundation_API DynamicAnyHolder |
---|
68 | /// Interface for a data holder used by the DynamicAny class. |
---|
69 | /// Provides methods to convert between data types. |
---|
70 | /// Only data types for which a convert method exists are supported, which are |
---|
71 | /// all C++ built-in types with addition of std::string, DateTime, LocalDateTime, Timestamp, |
---|
72 | /// and std::vector<DynamicAny>. |
---|
73 | { |
---|
74 | public: |
---|
75 | DynamicAnyHolder(); |
---|
76 | /// Creates the DynamicAnyHolder. |
---|
77 | |
---|
78 | virtual ~DynamicAnyHolder(); |
---|
79 | /// Destroys the DynamicAnyHolder. |
---|
80 | |
---|
81 | virtual DynamicAnyHolder* clone() const = 0; |
---|
82 | /// Deep-copies the DynamicAnyHolder. |
---|
83 | |
---|
84 | virtual const std::type_info& type() const = 0; |
---|
85 | /// Returns the type information of the stored content. |
---|
86 | |
---|
87 | virtual void convert(Int8& val) const = 0; |
---|
88 | virtual void convert(Int16& val) const = 0; |
---|
89 | virtual void convert(Int32& val) const = 0; |
---|
90 | virtual void convert(Int64& val) const = 0; |
---|
91 | virtual void convert(UInt8& val) const = 0; |
---|
92 | virtual void convert(UInt16& val) const = 0; |
---|
93 | virtual void convert(UInt32& val) const = 0; |
---|
94 | virtual void convert(UInt64& val) const = 0; |
---|
95 | virtual void convert(DateTime& val) const = 0; |
---|
96 | virtual void convert(LocalDateTime& val) const = 0; |
---|
97 | virtual void convert(Timestamp& val) const = 0; |
---|
98 | virtual bool isArray() const = 0; |
---|
99 | virtual bool isInteger() const = 0; |
---|
100 | virtual bool isSigned() const = 0; |
---|
101 | virtual bool isNumeric() const = 0; |
---|
102 | virtual bool isString() const = 0; |
---|
103 | |
---|
104 | #ifndef POCO_LONG_IS_64_BIT |
---|
105 | void convert(long& val) const; |
---|
106 | void convert(unsigned long& val) const; |
---|
107 | #endif |
---|
108 | |
---|
109 | virtual void convert(bool& val) const = 0; |
---|
110 | virtual void convert(float& val) const = 0; |
---|
111 | virtual void convert(double& val) const = 0; |
---|
112 | virtual void convert(char& val) const = 0; |
---|
113 | virtual void convert(std::string& val) const = 0; |
---|
114 | |
---|
115 | protected: |
---|
116 | template <typename F, typename T> |
---|
117 | void convertToSmaller(const F& from, T& to) const |
---|
118 | /// This function is meant to convert signed numeric values from |
---|
119 | /// larger to smaller type. It checks the upper and lower bound and |
---|
120 | /// if from value is within limits of type T (i.e. check calls do not throw), |
---|
121 | /// it is converted. |
---|
122 | { |
---|
123 | poco_static_assert (std::numeric_limits<F>::is_specialized); |
---|
124 | poco_static_assert (std::numeric_limits<T>::is_specialized); |
---|
125 | poco_static_assert (std::numeric_limits<F>::is_signed); |
---|
126 | poco_static_assert (std::numeric_limits<T>::is_signed); |
---|
127 | |
---|
128 | if (std::numeric_limits<F>::is_integer) |
---|
129 | checkUpperLimit(from, to); |
---|
130 | else |
---|
131 | checkUpperLimitFloat(from, to); |
---|
132 | |
---|
133 | checkLowerLimit(from, to); |
---|
134 | to = static_cast<T>(from); |
---|
135 | } |
---|
136 | |
---|
137 | template <typename F, typename T> |
---|
138 | void convertToSmallerUnsigned(const F& from, T& to) const |
---|
139 | /// This function is meant for converting unsigned integral data types, |
---|
140 | /// from larger to smaller type. Since lower limit is always 0 for unigned types, |
---|
141 | /// only the upper limit is checked, thus saving some cycles compared to the signed |
---|
142 | /// version of the function. If the value to be converted is smaller than |
---|
143 | /// the maximum value for the target type, the conversion is performed. |
---|
144 | { |
---|
145 | poco_static_assert (std::numeric_limits<F>::is_specialized); |
---|
146 | poco_static_assert (std::numeric_limits<T>::is_specialized); |
---|
147 | poco_static_assert (!std::numeric_limits<F>::is_signed); |
---|
148 | poco_static_assert (!std::numeric_limits<T>::is_signed); |
---|
149 | |
---|
150 | checkUpperLimit(from, to); |
---|
151 | to = static_cast<T>(from); |
---|
152 | } |
---|
153 | |
---|
154 | template <typename F, typename T> |
---|
155 | void convertSignedToUnsigned(const F& from, T& to) const |
---|
156 | /// This function is meant for converting signed integral data types to |
---|
157 | /// unsigned data types. Negative values can not be converted and if one is |
---|
158 | /// encountered, RangeException is thrown. |
---|
159 | /// If upper limit is within the target data type limits, the conversion is performed. |
---|
160 | { |
---|
161 | poco_static_assert (std::numeric_limits<F>::is_specialized); |
---|
162 | poco_static_assert (std::numeric_limits<T>::is_specialized); |
---|
163 | poco_static_assert (std::numeric_limits<F>::is_signed); |
---|
164 | poco_static_assert (!std::numeric_limits<T>::is_signed); |
---|
165 | |
---|
166 | if (from < 0) |
---|
167 | throw RangeException("Value too small."); |
---|
168 | checkUpperLimit(from, to); |
---|
169 | to = static_cast<T>(from); |
---|
170 | } |
---|
171 | |
---|
172 | template <typename F, typename T> |
---|
173 | void convertSignedFloatToUnsigned(const F& from, T& to) const |
---|
174 | /// This function is meant for converting floating point data types to |
---|
175 | /// unsigned integral data types. Negative values can not be converted and if one is |
---|
176 | /// encountered, RangeException is thrown. |
---|
177 | /// If uper limit is within the target data type limits, the conversion is performed. |
---|
178 | { |
---|
179 | poco_static_assert (std::numeric_limits<F>::is_specialized); |
---|
180 | poco_static_assert (std::numeric_limits<T>::is_specialized); |
---|
181 | poco_static_assert (!std::numeric_limits<F>::is_integer); |
---|
182 | poco_static_assert (std::numeric_limits<T>::is_integer); |
---|
183 | poco_static_assert (!std::numeric_limits<T>::is_signed); |
---|
184 | |
---|
185 | if (from < 0) |
---|
186 | throw RangeException("Value too small."); |
---|
187 | checkUpperLimitFloat(from, to); |
---|
188 | to = static_cast<T>(from); |
---|
189 | } |
---|
190 | |
---|
191 | template <typename F, typename T> |
---|
192 | void convertUnsignedToSigned(const F& from, T& to) const |
---|
193 | /// This function is meant for converting unsigned integral data types to |
---|
194 | /// unsigned data types. Negative values can not be converted and if one is |
---|
195 | /// encountered, RangeException is thrown. |
---|
196 | /// If upper limit is within the target data type limits, the converiosn is performed. |
---|
197 | { |
---|
198 | poco_static_assert (std::numeric_limits<F>::is_specialized); |
---|
199 | poco_static_assert (std::numeric_limits<T>::is_specialized); |
---|
200 | poco_static_assert (!std::numeric_limits<F>::is_signed); |
---|
201 | poco_static_assert (std::numeric_limits<T>::is_signed); |
---|
202 | |
---|
203 | checkUpperLimit(from, to); |
---|
204 | to = static_cast<T>(from); |
---|
205 | } |
---|
206 | |
---|
207 | private: |
---|
208 | template <typename F, typename T> |
---|
209 | void checkUpperLimit(const F& from, T&) const |
---|
210 | { |
---|
211 | if ((sizeof(T) < sizeof(F)) && |
---|
212 | (from > static_cast<F>(std::numeric_limits<T>::max()))) |
---|
213 | { |
---|
214 | throw RangeException("Value too large."); |
---|
215 | } |
---|
216 | else |
---|
217 | if (static_cast<T>(from) > std::numeric_limits<T>::max()) |
---|
218 | { |
---|
219 | throw RangeException("Value too large."); |
---|
220 | } |
---|
221 | } |
---|
222 | |
---|
223 | template <typename F, typename T> |
---|
224 | void checkUpperLimitFloat(const F& from, T&) const |
---|
225 | { |
---|
226 | if (from > std::numeric_limits<T>::max()) |
---|
227 | throw RangeException("Value too large."); |
---|
228 | } |
---|
229 | |
---|
230 | template <typename F, typename T> |
---|
231 | void checkLowerLimit(const F& from, T&) const |
---|
232 | { |
---|
233 | if (from < std::numeric_limits<T>::min()) |
---|
234 | throw RangeException("Value too small."); |
---|
235 | } |
---|
236 | }; |
---|
237 | |
---|
238 | |
---|
239 | // |
---|
240 | // inlines |
---|
241 | // |
---|
242 | #ifndef POCO_LONG_IS_64_BIT |
---|
243 | inline void DynamicAnyHolder::convert(long& val) const |
---|
244 | { |
---|
245 | Int32 tmp; |
---|
246 | convert(tmp); |
---|
247 | val = tmp; |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | inline void DynamicAnyHolder::convert(unsigned long& val) const |
---|
252 | { |
---|
253 | UInt32 tmp; |
---|
254 | convert(tmp); |
---|
255 | val = tmp; |
---|
256 | } |
---|
257 | #endif |
---|
258 | |
---|
259 | |
---|
260 | template <typename T> |
---|
261 | class DynamicAnyHolderImpl: public DynamicAnyHolder |
---|
262 | /// Template based implementation of a DynamicAnyHolder. |
---|
263 | /// Conversion work happens in the template specializations of this class. |
---|
264 | /// |
---|
265 | /// DynamicAny can be used for any type for which a specialization for |
---|
266 | /// DynamicAnyHolderImpl is available. |
---|
267 | /// |
---|
268 | /// DynamicAnyHolderImpl throws following exceptions: |
---|
269 | /// NotImplementedException (if the specialization for a type does not exist) |
---|
270 | /// RangeException (if an attempt is made to assign a numeric value outside of the target min/max limits |
---|
271 | /// SyntaxException (if an attempt is made to convert a string containing non-numeric characters to number) |
---|
272 | /// |
---|
273 | /// All specializations must additionally implement a public member function: |
---|
274 | /// const T& value() const |
---|
275 | /// returning a const reference to the actual stored value. |
---|
276 | { |
---|
277 | public: |
---|
278 | DynamicAnyHolderImpl() |
---|
279 | { |
---|
280 | } |
---|
281 | |
---|
282 | ~DynamicAnyHolderImpl() |
---|
283 | { |
---|
284 | } |
---|
285 | |
---|
286 | const std::type_info& type() const |
---|
287 | { |
---|
288 | return typeid(T); |
---|
289 | } |
---|
290 | |
---|
291 | bool isInteger() const |
---|
292 | { |
---|
293 | return std::numeric_limits<T>::is_integer; |
---|
294 | } |
---|
295 | |
---|
296 | bool isSigned() const |
---|
297 | { |
---|
298 | return std::numeric_limits<T>::is_signed; |
---|
299 | } |
---|
300 | |
---|
301 | bool isNumeric() const |
---|
302 | { |
---|
303 | return std::numeric_limits<T>::is_specialized; |
---|
304 | } |
---|
305 | |
---|
306 | bool isString() const |
---|
307 | { |
---|
308 | return type() == typeid(std::string); |
---|
309 | } |
---|
310 | |
---|
311 | void convert(Int8&) const |
---|
312 | { |
---|
313 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
314 | } |
---|
315 | |
---|
316 | void convert(Int16&) const |
---|
317 | { |
---|
318 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
319 | } |
---|
320 | |
---|
321 | void convert(Int32&) const |
---|
322 | { |
---|
323 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
324 | } |
---|
325 | |
---|
326 | void convert(Int64&) const |
---|
327 | { |
---|
328 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
329 | } |
---|
330 | |
---|
331 | void convert(UInt8&) const |
---|
332 | { |
---|
333 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
334 | } |
---|
335 | |
---|
336 | void convert(UInt16&) const |
---|
337 | { |
---|
338 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
339 | } |
---|
340 | |
---|
341 | void convert(UInt32&) const |
---|
342 | { |
---|
343 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
344 | } |
---|
345 | |
---|
346 | void convert(UInt64&) const |
---|
347 | { |
---|
348 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
349 | } |
---|
350 | |
---|
351 | void convert(bool&) const |
---|
352 | { |
---|
353 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
354 | } |
---|
355 | |
---|
356 | void convert(float&) const |
---|
357 | { |
---|
358 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
359 | } |
---|
360 | |
---|
361 | void convert(double&) const |
---|
362 | { |
---|
363 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
364 | } |
---|
365 | |
---|
366 | void convert(char&) const |
---|
367 | { |
---|
368 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
369 | } |
---|
370 | |
---|
371 | void convert(std::string&) const |
---|
372 | { |
---|
373 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
374 | } |
---|
375 | |
---|
376 | void convert(DateTime&) const |
---|
377 | { |
---|
378 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
379 | } |
---|
380 | |
---|
381 | void convert(LocalDateTime&) const |
---|
382 | { |
---|
383 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
384 | } |
---|
385 | |
---|
386 | void convert(Timestamp&) const |
---|
387 | { |
---|
388 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
389 | } |
---|
390 | |
---|
391 | DynamicAnyHolder* clone() const |
---|
392 | { |
---|
393 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
394 | } |
---|
395 | |
---|
396 | bool isArray() const |
---|
397 | { |
---|
398 | throw NotImplementedException("No DynamicAnyHolder specialization for type", typeid(T).name()); |
---|
399 | } |
---|
400 | }; |
---|
401 | |
---|
402 | |
---|
403 | template <> |
---|
404 | class DynamicAnyHolderImpl<Int8>: public DynamicAnyHolder |
---|
405 | { |
---|
406 | public: |
---|
407 | DynamicAnyHolderImpl(Int8 val): _val(val) |
---|
408 | { |
---|
409 | } |
---|
410 | |
---|
411 | ~DynamicAnyHolderImpl() |
---|
412 | { |
---|
413 | } |
---|
414 | |
---|
415 | const std::type_info& type() const |
---|
416 | { |
---|
417 | return typeid(Int8); |
---|
418 | } |
---|
419 | |
---|
420 | void convert(Int8& val) const |
---|
421 | { |
---|
422 | val = _val; |
---|
423 | } |
---|
424 | |
---|
425 | void convert(Int16& val) const |
---|
426 | { |
---|
427 | val = _val; |
---|
428 | } |
---|
429 | |
---|
430 | void convert(Int32& val) const |
---|
431 | { |
---|
432 | val = _val; |
---|
433 | } |
---|
434 | |
---|
435 | void convert(Int64& val) const |
---|
436 | { |
---|
437 | val = _val; |
---|
438 | } |
---|
439 | |
---|
440 | void convert(UInt8& val) const |
---|
441 | { |
---|
442 | convertSignedToUnsigned(_val, val); |
---|
443 | } |
---|
444 | |
---|
445 | void convert(UInt16& val) const |
---|
446 | { |
---|
447 | convertSignedToUnsigned(_val, val); |
---|
448 | } |
---|
449 | |
---|
450 | void convert(UInt32& val) const |
---|
451 | { |
---|
452 | convertSignedToUnsigned(_val, val); |
---|
453 | } |
---|
454 | |
---|
455 | void convert(UInt64& val) const |
---|
456 | { |
---|
457 | convertSignedToUnsigned(_val, val); |
---|
458 | } |
---|
459 | |
---|
460 | void convert(bool& val) const |
---|
461 | { |
---|
462 | val = (_val != 0); |
---|
463 | } |
---|
464 | |
---|
465 | void convert(float& val) const |
---|
466 | { |
---|
467 | val = static_cast<float>(_val); |
---|
468 | } |
---|
469 | |
---|
470 | void convert(double& val) const |
---|
471 | { |
---|
472 | val = static_cast<double>(_val); |
---|
473 | } |
---|
474 | |
---|
475 | void convert(char& val) const |
---|
476 | { |
---|
477 | val = static_cast<char>(_val); |
---|
478 | } |
---|
479 | |
---|
480 | void convert(std::string& val) const |
---|
481 | { |
---|
482 | val = NumberFormatter::format(_val); |
---|
483 | } |
---|
484 | |
---|
485 | void convert(DateTime&) const |
---|
486 | { |
---|
487 | throw BadCastException("Int8 -> DateTime"); |
---|
488 | } |
---|
489 | |
---|
490 | void convert(LocalDateTime&) const |
---|
491 | { |
---|
492 | throw BadCastException("Int8 -> LocalDateTime"); |
---|
493 | } |
---|
494 | |
---|
495 | void convert(Timestamp&) const |
---|
496 | { |
---|
497 | throw BadCastException("Int8 -> Timestamp"); |
---|
498 | } |
---|
499 | |
---|
500 | DynamicAnyHolder* clone() const |
---|
501 | { |
---|
502 | return new DynamicAnyHolderImpl(_val); |
---|
503 | } |
---|
504 | |
---|
505 | const Int8& value() const |
---|
506 | { |
---|
507 | return _val; |
---|
508 | } |
---|
509 | |
---|
510 | bool isArray() const |
---|
511 | { |
---|
512 | return false; |
---|
513 | } |
---|
514 | |
---|
515 | bool isInteger() const |
---|
516 | { |
---|
517 | return std::numeric_limits<Int8>::is_integer; |
---|
518 | } |
---|
519 | |
---|
520 | bool isSigned() const |
---|
521 | { |
---|
522 | return std::numeric_limits<Int8>::is_signed; |
---|
523 | } |
---|
524 | |
---|
525 | bool isNumeric() const |
---|
526 | { |
---|
527 | return std::numeric_limits<Int8>::is_specialized; |
---|
528 | } |
---|
529 | |
---|
530 | bool isString() const |
---|
531 | { |
---|
532 | return false; |
---|
533 | } |
---|
534 | |
---|
535 | private: |
---|
536 | Int8 _val; |
---|
537 | }; |
---|
538 | |
---|
539 | |
---|
540 | template <> |
---|
541 | class DynamicAnyHolderImpl<Int16>: public DynamicAnyHolder |
---|
542 | { |
---|
543 | public: |
---|
544 | DynamicAnyHolderImpl(Int16 val): _val(val) |
---|
545 | { |
---|
546 | } |
---|
547 | |
---|
548 | ~DynamicAnyHolderImpl() |
---|
549 | { |
---|
550 | } |
---|
551 | |
---|
552 | const std::type_info& type() const |
---|
553 | { |
---|
554 | return typeid(Int16); |
---|
555 | } |
---|
556 | |
---|
557 | void convert(Int8& val) const |
---|
558 | { |
---|
559 | convertToSmaller(_val, val); |
---|
560 | } |
---|
561 | |
---|
562 | void convert(Int16& val) const |
---|
563 | { |
---|
564 | val = _val; |
---|
565 | } |
---|
566 | |
---|
567 | void convert(Int32& val) const |
---|
568 | { |
---|
569 | val = _val; |
---|
570 | } |
---|
571 | |
---|
572 | void convert(Int64& val) const |
---|
573 | { |
---|
574 | val = _val; |
---|
575 | } |
---|
576 | |
---|
577 | void convert(UInt8& val) const |
---|
578 | { |
---|
579 | convertSignedToUnsigned(_val, val); |
---|
580 | } |
---|
581 | |
---|
582 | void convert(UInt16& val) const |
---|
583 | { |
---|
584 | convertSignedToUnsigned(_val, val); |
---|
585 | } |
---|
586 | |
---|
587 | void convert(UInt32& val) const |
---|
588 | { |
---|
589 | convertSignedToUnsigned(_val, val); |
---|
590 | } |
---|
591 | |
---|
592 | void convert(UInt64& val) const |
---|
593 | { |
---|
594 | convertSignedToUnsigned(_val, val); |
---|
595 | } |
---|
596 | |
---|
597 | void convert(bool& val) const |
---|
598 | { |
---|
599 | val = (_val != 0); |
---|
600 | } |
---|
601 | |
---|
602 | void convert(float& val) const |
---|
603 | { |
---|
604 | val = static_cast<float>(_val); |
---|
605 | } |
---|
606 | |
---|
607 | void convert(double& val) const |
---|
608 | { |
---|
609 | val = static_cast<double>(_val); |
---|
610 | } |
---|
611 | |
---|
612 | void convert(char& val) const |
---|
613 | { |
---|
614 | UInt8 tmp; |
---|
615 | convert(tmp); |
---|
616 | val = static_cast<char>(tmp); |
---|
617 | } |
---|
618 | |
---|
619 | void convert(std::string& val) const |
---|
620 | { |
---|
621 | val = NumberFormatter::format(_val); |
---|
622 | } |
---|
623 | |
---|
624 | void convert(DateTime&) const |
---|
625 | { |
---|
626 | throw BadCastException("Int16 -> DateTime"); |
---|
627 | } |
---|
628 | |
---|
629 | void convert(LocalDateTime&) const |
---|
630 | { |
---|
631 | throw BadCastException("Int16 -> LocalDateTime"); |
---|
632 | } |
---|
633 | |
---|
634 | void convert(Timestamp&) const |
---|
635 | { |
---|
636 | throw BadCastException("Int16 -> Timestamp"); |
---|
637 | } |
---|
638 | |
---|
639 | DynamicAnyHolder* clone() const |
---|
640 | { |
---|
641 | return new DynamicAnyHolderImpl(_val); |
---|
642 | } |
---|
643 | |
---|
644 | const Int16& value() const |
---|
645 | { |
---|
646 | return _val; |
---|
647 | } |
---|
648 | |
---|
649 | bool isArray() const |
---|
650 | { |
---|
651 | return false; |
---|
652 | } |
---|
653 | |
---|
654 | bool isInteger() const |
---|
655 | { |
---|
656 | return std::numeric_limits<Int16>::is_integer; |
---|
657 | } |
---|
658 | |
---|
659 | bool isSigned() const |
---|
660 | { |
---|
661 | return std::numeric_limits<Int16>::is_signed; |
---|
662 | } |
---|
663 | |
---|
664 | bool isNumeric() const |
---|
665 | { |
---|
666 | return std::numeric_limits<Int16>::is_specialized; |
---|
667 | } |
---|
668 | |
---|
669 | bool isString() const |
---|
670 | { |
---|
671 | return false; |
---|
672 | } |
---|
673 | |
---|
674 | private: |
---|
675 | Int16 _val; |
---|
676 | }; |
---|
677 | |
---|
678 | |
---|
679 | template <> |
---|
680 | class DynamicAnyHolderImpl<Int32>: public DynamicAnyHolder |
---|
681 | { |
---|
682 | public: |
---|
683 | DynamicAnyHolderImpl(Int32 val): _val(val) |
---|
684 | { |
---|
685 | } |
---|
686 | |
---|
687 | ~DynamicAnyHolderImpl() |
---|
688 | { |
---|
689 | } |
---|
690 | |
---|
691 | const std::type_info& type() const |
---|
692 | { |
---|
693 | return typeid(Int32); |
---|
694 | } |
---|
695 | |
---|
696 | void convert(Int8& val) const |
---|
697 | { |
---|
698 | convertToSmaller(_val, val); |
---|
699 | } |
---|
700 | |
---|
701 | void convert(Int16& val) const |
---|
702 | { |
---|
703 | convertToSmaller(_val, val); |
---|
704 | } |
---|
705 | |
---|
706 | void convert(Int32& val) const |
---|
707 | { |
---|
708 | val = _val; |
---|
709 | } |
---|
710 | |
---|
711 | void convert(Int64& val) const |
---|
712 | { |
---|
713 | val = _val; |
---|
714 | } |
---|
715 | |
---|
716 | void convert(UInt8& val) const |
---|
717 | { |
---|
718 | convertSignedToUnsigned(_val, val); |
---|
719 | } |
---|
720 | |
---|
721 | void convert(UInt16& val) const |
---|
722 | { |
---|
723 | convertSignedToUnsigned(_val, val); |
---|
724 | } |
---|
725 | |
---|
726 | void convert(UInt32& val) const |
---|
727 | { |
---|
728 | convertSignedToUnsigned(_val, val); |
---|
729 | } |
---|
730 | |
---|
731 | void convert(UInt64& val) const |
---|
732 | { |
---|
733 | convertSignedToUnsigned(_val, val); |
---|
734 | } |
---|
735 | |
---|
736 | void convert(bool& val) const |
---|
737 | { |
---|
738 | val = (_val != 0); |
---|
739 | } |
---|
740 | |
---|
741 | void convert(float& val) const |
---|
742 | { |
---|
743 | val = static_cast<float>(_val); |
---|
744 | } |
---|
745 | |
---|
746 | void convert(double& val) const |
---|
747 | { |
---|
748 | val = static_cast<double>(_val); |
---|
749 | } |
---|
750 | |
---|
751 | void convert(char& val) const |
---|
752 | { |
---|
753 | UInt8 tmp; |
---|
754 | convert(tmp); |
---|
755 | val = static_cast<char>(tmp); |
---|
756 | } |
---|
757 | |
---|
758 | void convert(std::string& val) const |
---|
759 | { |
---|
760 | val = NumberFormatter::format(_val); |
---|
761 | } |
---|
762 | |
---|
763 | void convert(DateTime&) const |
---|
764 | { |
---|
765 | throw BadCastException("Int32 -> DateTime"); |
---|
766 | } |
---|
767 | |
---|
768 | void convert(LocalDateTime&) const |
---|
769 | { |
---|
770 | throw BadCastException("Int32 -> LocalDateTime"); |
---|
771 | } |
---|
772 | |
---|
773 | void convert(Timestamp&) const |
---|
774 | { |
---|
775 | throw BadCastException("Int32 -> Timestamp"); |
---|
776 | } |
---|
777 | |
---|
778 | DynamicAnyHolder* clone() const |
---|
779 | { |
---|
780 | return new DynamicAnyHolderImpl(_val); |
---|
781 | } |
---|
782 | |
---|
783 | const Int32& value() const |
---|
784 | { |
---|
785 | return _val; |
---|
786 | } |
---|
787 | |
---|
788 | bool isArray() const |
---|
789 | { |
---|
790 | return false; |
---|
791 | } |
---|
792 | |
---|
793 | bool isInteger() const |
---|
794 | { |
---|
795 | return std::numeric_limits<Int32>::is_integer; |
---|
796 | } |
---|
797 | |
---|
798 | bool isSigned() const |
---|
799 | { |
---|
800 | return std::numeric_limits<Int32>::is_signed; |
---|
801 | } |
---|
802 | |
---|
803 | bool isNumeric() const |
---|
804 | { |
---|
805 | return std::numeric_limits<Int32>::is_specialized; |
---|
806 | } |
---|
807 | |
---|
808 | bool isString() const |
---|
809 | { |
---|
810 | return false; |
---|
811 | } |
---|
812 | |
---|
813 | private: |
---|
814 | Int32 _val; |
---|
815 | }; |
---|
816 | |
---|
817 | |
---|
818 | template <> |
---|
819 | class DynamicAnyHolderImpl<Int64>: public DynamicAnyHolder |
---|
820 | { |
---|
821 | public: |
---|
822 | DynamicAnyHolderImpl(Int64 val): _val(val) |
---|
823 | { |
---|
824 | } |
---|
825 | |
---|
826 | ~DynamicAnyHolderImpl() |
---|
827 | { |
---|
828 | } |
---|
829 | |
---|
830 | const std::type_info& type() const |
---|
831 | { |
---|
832 | return typeid(Int64); |
---|
833 | } |
---|
834 | |
---|
835 | void convert(Int8& val) const |
---|
836 | { |
---|
837 | convertToSmaller(_val, val); |
---|
838 | } |
---|
839 | |
---|
840 | void convert(Int16& val) const |
---|
841 | { |
---|
842 | convertToSmaller(_val, val); |
---|
843 | } |
---|
844 | |
---|
845 | void convert(Int32& val) const |
---|
846 | { |
---|
847 | convertToSmaller(_val, val); |
---|
848 | } |
---|
849 | |
---|
850 | void convert(Int64& val) const |
---|
851 | { |
---|
852 | val = _val; |
---|
853 | } |
---|
854 | |
---|
855 | void convert(UInt8& val) const |
---|
856 | { |
---|
857 | convertSignedToUnsigned(_val, val); |
---|
858 | } |
---|
859 | |
---|
860 | void convert(UInt16& val) const |
---|
861 | { |
---|
862 | convertSignedToUnsigned(_val, val); |
---|
863 | } |
---|
864 | |
---|
865 | void convert(UInt32& val) const |
---|
866 | { |
---|
867 | convertSignedToUnsigned(_val, val); |
---|
868 | } |
---|
869 | |
---|
870 | void convert(UInt64& val) const |
---|
871 | { |
---|
872 | convertSignedToUnsigned(_val, val); |
---|
873 | } |
---|
874 | |
---|
875 | void convert(bool& val) const |
---|
876 | { |
---|
877 | val = (_val != 0); |
---|
878 | } |
---|
879 | |
---|
880 | void convert(float& val) const |
---|
881 | { |
---|
882 | val = static_cast<float>(_val); |
---|
883 | } |
---|
884 | |
---|
885 | void convert(double& val) const |
---|
886 | { |
---|
887 | val = static_cast<double>(_val); |
---|
888 | } |
---|
889 | |
---|
890 | void convert(char& val) const |
---|
891 | { |
---|
892 | UInt8 tmp; |
---|
893 | convert(tmp); |
---|
894 | val = static_cast<char>(tmp); |
---|
895 | } |
---|
896 | |
---|
897 | void convert(std::string& val) const |
---|
898 | { |
---|
899 | val = NumberFormatter::format(_val); |
---|
900 | } |
---|
901 | |
---|
902 | void convert(DateTime& dt) const |
---|
903 | { |
---|
904 | dt = Timestamp(_val); |
---|
905 | } |
---|
906 | |
---|
907 | void convert(LocalDateTime& ldt) const |
---|
908 | { |
---|
909 | ldt = Timestamp(_val); |
---|
910 | } |
---|
911 | |
---|
912 | void convert(Timestamp& val) const |
---|
913 | { |
---|
914 | val = Timestamp(_val); |
---|
915 | } |
---|
916 | |
---|
917 | DynamicAnyHolder* clone() const |
---|
918 | { |
---|
919 | return new DynamicAnyHolderImpl(_val); |
---|
920 | } |
---|
921 | |
---|
922 | const Int64& value() const |
---|
923 | { |
---|
924 | return _val; |
---|
925 | } |
---|
926 | |
---|
927 | bool isArray() const |
---|
928 | { |
---|
929 | return false; |
---|
930 | } |
---|
931 | |
---|
932 | bool isInteger() const |
---|
933 | { |
---|
934 | return std::numeric_limits<Int64>::is_integer; |
---|
935 | } |
---|
936 | |
---|
937 | bool isSigned() const |
---|
938 | { |
---|
939 | return std::numeric_limits<Int64>::is_signed; |
---|
940 | } |
---|
941 | |
---|
942 | bool isNumeric() const |
---|
943 | { |
---|
944 | return std::numeric_limits<Int64>::is_specialized; |
---|
945 | } |
---|
946 | |
---|
947 | bool isString() const |
---|
948 | { |
---|
949 | return false; |
---|
950 | } |
---|
951 | |
---|
952 | private: |
---|
953 | Int64 _val; |
---|
954 | }; |
---|
955 | |
---|
956 | |
---|
957 | template <> |
---|
958 | class DynamicAnyHolderImpl<UInt8>: public DynamicAnyHolder |
---|
959 | { |
---|
960 | public: |
---|
961 | DynamicAnyHolderImpl(UInt8 val): _val(val) |
---|
962 | { |
---|
963 | } |
---|
964 | |
---|
965 | ~DynamicAnyHolderImpl() |
---|
966 | { |
---|
967 | } |
---|
968 | |
---|
969 | const std::type_info& type() const |
---|
970 | { |
---|
971 | return typeid(UInt8); |
---|
972 | } |
---|
973 | |
---|
974 | void convert(Int8& val) const |
---|
975 | { |
---|
976 | convertUnsignedToSigned(_val, val); |
---|
977 | } |
---|
978 | |
---|
979 | void convert(Int16& val) const |
---|
980 | { |
---|
981 | convertUnsignedToSigned(_val, val); |
---|
982 | } |
---|
983 | |
---|
984 | void convert(Int32& val) const |
---|
985 | { |
---|
986 | val = static_cast<Int32>(_val); |
---|
987 | } |
---|
988 | |
---|
989 | void convert(Int64& val) const |
---|
990 | { |
---|
991 | val = static_cast<Int64>(_val); |
---|
992 | } |
---|
993 | |
---|
994 | void convert(UInt8& val) const |
---|
995 | { |
---|
996 | val = _val; |
---|
997 | } |
---|
998 | |
---|
999 | void convert(UInt16& val) const |
---|
1000 | { |
---|
1001 | val = _val; |
---|
1002 | } |
---|
1003 | |
---|
1004 | void convert(UInt32& val) const |
---|
1005 | { |
---|
1006 | val = _val; |
---|
1007 | } |
---|
1008 | |
---|
1009 | void convert(UInt64& val) const |
---|
1010 | { |
---|
1011 | val = _val; |
---|
1012 | } |
---|
1013 | |
---|
1014 | void convert(bool& val) const |
---|
1015 | { |
---|
1016 | val = (_val != 0); |
---|
1017 | } |
---|
1018 | |
---|
1019 | void convert(float& val) const |
---|
1020 | { |
---|
1021 | val = static_cast<float>(_val); |
---|
1022 | } |
---|
1023 | |
---|
1024 | void convert(double& val) const |
---|
1025 | { |
---|
1026 | val = static_cast<double>(_val); |
---|
1027 | } |
---|
1028 | |
---|
1029 | void convert(char& val) const |
---|
1030 | { |
---|
1031 | UInt8 tmp; |
---|
1032 | convert(tmp); |
---|
1033 | val = static_cast<char>(tmp); |
---|
1034 | } |
---|
1035 | |
---|
1036 | void convert(std::string& val) const |
---|
1037 | { |
---|
1038 | val = NumberFormatter::format(_val); |
---|
1039 | } |
---|
1040 | |
---|
1041 | void convert(DateTime&) const |
---|
1042 | { |
---|
1043 | throw BadCastException("UInt8 -> DateTime"); |
---|
1044 | } |
---|
1045 | |
---|
1046 | void convert(LocalDateTime&) const |
---|
1047 | { |
---|
1048 | throw BadCastException("Unt8 -> LocalDateTime"); |
---|
1049 | } |
---|
1050 | |
---|
1051 | void convert(Timestamp&) const |
---|
1052 | { |
---|
1053 | throw BadCastException("UInt8 -> Timestamp"); |
---|
1054 | } |
---|
1055 | |
---|
1056 | DynamicAnyHolder* clone() const |
---|
1057 | { |
---|
1058 | return new DynamicAnyHolderImpl(_val); |
---|
1059 | } |
---|
1060 | |
---|
1061 | const UInt8& value() const |
---|
1062 | { |
---|
1063 | return _val; |
---|
1064 | } |
---|
1065 | |
---|
1066 | bool isArray() const |
---|
1067 | { |
---|
1068 | return false; |
---|
1069 | } |
---|
1070 | |
---|
1071 | bool isInteger() const |
---|
1072 | { |
---|
1073 | return std::numeric_limits<UInt8>::is_integer; |
---|
1074 | } |
---|
1075 | |
---|
1076 | bool isSigned() const |
---|
1077 | { |
---|
1078 | return std::numeric_limits<UInt8>::is_signed; |
---|
1079 | } |
---|
1080 | |
---|
1081 | bool isNumeric() const |
---|
1082 | { |
---|
1083 | return std::numeric_limits<UInt8>::is_specialized; |
---|
1084 | } |
---|
1085 | |
---|
1086 | bool isString() const |
---|
1087 | { |
---|
1088 | return false; |
---|
1089 | } |
---|
1090 | |
---|
1091 | private: |
---|
1092 | UInt8 _val; |
---|
1093 | }; |
---|
1094 | |
---|
1095 | |
---|
1096 | template <> |
---|
1097 | class DynamicAnyHolderImpl<UInt16>: public DynamicAnyHolder |
---|
1098 | { |
---|
1099 | public: |
---|
1100 | DynamicAnyHolderImpl(UInt16 val): _val(val) |
---|
1101 | { |
---|
1102 | } |
---|
1103 | |
---|
1104 | ~DynamicAnyHolderImpl() |
---|
1105 | { |
---|
1106 | } |
---|
1107 | |
---|
1108 | const std::type_info& type() const |
---|
1109 | { |
---|
1110 | return typeid(UInt16); |
---|
1111 | } |
---|
1112 | |
---|
1113 | void convert(Int8& val) const |
---|
1114 | { |
---|
1115 | convertUnsignedToSigned(_val, val); |
---|
1116 | } |
---|
1117 | |
---|
1118 | void convert(Int16& val) const |
---|
1119 | { |
---|
1120 | convertUnsignedToSigned(_val, val); |
---|
1121 | } |
---|
1122 | |
---|
1123 | void convert(Int32& val) const |
---|
1124 | { |
---|
1125 | convertUnsignedToSigned(_val, val); |
---|
1126 | } |
---|
1127 | |
---|
1128 | void convert(Int64& val) const |
---|
1129 | { |
---|
1130 | val = static_cast<Int64>(_val); |
---|
1131 | } |
---|
1132 | |
---|
1133 | void convert(UInt8& val) const |
---|
1134 | { |
---|
1135 | convertToSmallerUnsigned(_val, val); |
---|
1136 | } |
---|
1137 | |
---|
1138 | void convert(UInt16& val) const |
---|
1139 | { |
---|
1140 | val = _val; |
---|
1141 | } |
---|
1142 | |
---|
1143 | void convert(UInt32& val) const |
---|
1144 | { |
---|
1145 | val = _val; |
---|
1146 | } |
---|
1147 | |
---|
1148 | void convert(UInt64& val) const |
---|
1149 | { |
---|
1150 | val = _val; |
---|
1151 | } |
---|
1152 | |
---|
1153 | void convert(bool& val) const |
---|
1154 | { |
---|
1155 | val = (_val != 0); |
---|
1156 | } |
---|
1157 | |
---|
1158 | void convert(float& val) const |
---|
1159 | { |
---|
1160 | val = static_cast<float>(_val); |
---|
1161 | } |
---|
1162 | |
---|
1163 | void convert(double& val) const |
---|
1164 | { |
---|
1165 | val = static_cast<double>(_val); |
---|
1166 | } |
---|
1167 | |
---|
1168 | void convert(char& val) const |
---|
1169 | { |
---|
1170 | UInt8 tmp; |
---|
1171 | convert(tmp); |
---|
1172 | val = static_cast<char>(tmp); |
---|
1173 | } |
---|
1174 | |
---|
1175 | void convert(std::string& val) const |
---|
1176 | { |
---|
1177 | val = NumberFormatter::format(_val); |
---|
1178 | } |
---|
1179 | |
---|
1180 | void convert(DateTime&) const |
---|
1181 | { |
---|
1182 | throw BadCastException("UInt16 -> DateTime"); |
---|
1183 | } |
---|
1184 | |
---|
1185 | void convert(LocalDateTime&) const |
---|
1186 | { |
---|
1187 | throw BadCastException("UInt16 -> LocalDateTime"); |
---|
1188 | } |
---|
1189 | |
---|
1190 | void convert(Timestamp&) const |
---|
1191 | { |
---|
1192 | throw BadCastException("UInt16 -> Timestamp"); |
---|
1193 | } |
---|
1194 | |
---|
1195 | DynamicAnyHolder* clone() const |
---|
1196 | { |
---|
1197 | return new DynamicAnyHolderImpl(_val); |
---|
1198 | } |
---|
1199 | |
---|
1200 | const UInt16& value() const |
---|
1201 | { |
---|
1202 | return _val; |
---|
1203 | } |
---|
1204 | |
---|
1205 | bool isArray() const |
---|
1206 | { |
---|
1207 | return false; |
---|
1208 | } |
---|
1209 | |
---|
1210 | bool isInteger() const |
---|
1211 | { |
---|
1212 | return std::numeric_limits<UInt16>::is_integer; |
---|
1213 | } |
---|
1214 | |
---|
1215 | bool isSigned() const |
---|
1216 | { |
---|
1217 | return std::numeric_limits<UInt16>::is_signed; |
---|
1218 | } |
---|
1219 | |
---|
1220 | bool isNumeric() const |
---|
1221 | { |
---|
1222 | return std::numeric_limits<UInt16>::is_specialized; |
---|
1223 | } |
---|
1224 | |
---|
1225 | bool isString() const |
---|
1226 | { |
---|
1227 | return false; |
---|
1228 | } |
---|
1229 | |
---|
1230 | private: |
---|
1231 | UInt16 _val; |
---|
1232 | }; |
---|
1233 | |
---|
1234 | |
---|
1235 | template <> |
---|
1236 | class DynamicAnyHolderImpl<UInt32>: public DynamicAnyHolder |
---|
1237 | { |
---|
1238 | public: |
---|
1239 | DynamicAnyHolderImpl(UInt32 val): _val(val) |
---|
1240 | { |
---|
1241 | } |
---|
1242 | |
---|
1243 | ~DynamicAnyHolderImpl() |
---|
1244 | { |
---|
1245 | } |
---|
1246 | |
---|
1247 | const std::type_info& type() const |
---|
1248 | { |
---|
1249 | return typeid(UInt32); |
---|
1250 | } |
---|
1251 | |
---|
1252 | void convert(Int8& val) const |
---|
1253 | { |
---|
1254 | convertUnsignedToSigned(_val, val); |
---|
1255 | } |
---|
1256 | |
---|
1257 | void convert(Int16& val) const |
---|
1258 | { |
---|
1259 | convertUnsignedToSigned(_val, val); |
---|
1260 | } |
---|
1261 | |
---|
1262 | void convert(Int32& val) const |
---|
1263 | { |
---|
1264 | convertUnsignedToSigned(_val, val); |
---|
1265 | } |
---|
1266 | |
---|
1267 | void convert(Int64& val) const |
---|
1268 | { |
---|
1269 | convertUnsignedToSigned(_val, val); |
---|
1270 | } |
---|
1271 | |
---|
1272 | void convert(UInt8& val) const |
---|
1273 | { |
---|
1274 | convertToSmallerUnsigned(_val, val); |
---|
1275 | } |
---|
1276 | |
---|
1277 | void convert(UInt16& val) const |
---|
1278 | { |
---|
1279 | convertToSmallerUnsigned(_val, val); |
---|
1280 | } |
---|
1281 | |
---|
1282 | void convert(UInt32& val) const |
---|
1283 | { |
---|
1284 | val = _val; |
---|
1285 | } |
---|
1286 | |
---|
1287 | void convert(UInt64& val) const |
---|
1288 | { |
---|
1289 | val = _val; |
---|
1290 | } |
---|
1291 | |
---|
1292 | void convert(bool& val) const |
---|
1293 | { |
---|
1294 | val = (_val != 0); |
---|
1295 | } |
---|
1296 | |
---|
1297 | void convert(float& val) const |
---|
1298 | { |
---|
1299 | val = static_cast<float>(_val); |
---|
1300 | } |
---|
1301 | |
---|
1302 | void convert(double& val) const |
---|
1303 | { |
---|
1304 | val = static_cast<double>(_val); |
---|
1305 | } |
---|
1306 | |
---|
1307 | void convert(char& val) const |
---|
1308 | { |
---|
1309 | UInt8 tmp; |
---|
1310 | convert(tmp); |
---|
1311 | val = static_cast<char>(tmp); |
---|
1312 | } |
---|
1313 | |
---|
1314 | void convert(std::string& val) const |
---|
1315 | { |
---|
1316 | val = NumberFormatter::format(_val); |
---|
1317 | } |
---|
1318 | |
---|
1319 | void convert(DateTime&) const |
---|
1320 | { |
---|
1321 | throw BadCastException("UInt32 -> DateTime"); |
---|
1322 | } |
---|
1323 | |
---|
1324 | void convert(LocalDateTime&) const |
---|
1325 | { |
---|
1326 | throw BadCastException("UInt32 -> LocalDateTime"); |
---|
1327 | } |
---|
1328 | |
---|
1329 | void convert(Timestamp&) const |
---|
1330 | { |
---|
1331 | throw BadCastException("UInt32 -> Timestamp"); |
---|
1332 | } |
---|
1333 | |
---|
1334 | DynamicAnyHolder* clone() const |
---|
1335 | { |
---|
1336 | return new DynamicAnyHolderImpl(_val); |
---|
1337 | } |
---|
1338 | |
---|
1339 | const UInt32& value() const |
---|
1340 | { |
---|
1341 | return _val; |
---|
1342 | } |
---|
1343 | |
---|
1344 | bool isArray() const |
---|
1345 | { |
---|
1346 | return false; |
---|
1347 | } |
---|
1348 | |
---|
1349 | bool isInteger() const |
---|
1350 | { |
---|
1351 | return std::numeric_limits<UInt32>::is_integer; |
---|
1352 | } |
---|
1353 | |
---|
1354 | bool isSigned() const |
---|
1355 | { |
---|
1356 | return std::numeric_limits<UInt32>::is_signed; |
---|
1357 | } |
---|
1358 | |
---|
1359 | bool isNumeric() const |
---|
1360 | { |
---|
1361 | return std::numeric_limits<UInt32>::is_specialized; |
---|
1362 | } |
---|
1363 | |
---|
1364 | bool isString() const |
---|
1365 | { |
---|
1366 | return false; |
---|
1367 | } |
---|
1368 | |
---|
1369 | private: |
---|
1370 | UInt32 _val; |
---|
1371 | }; |
---|
1372 | |
---|
1373 | |
---|
1374 | template <> |
---|
1375 | class DynamicAnyHolderImpl<UInt64>: public DynamicAnyHolder |
---|
1376 | { |
---|
1377 | public: |
---|
1378 | DynamicAnyHolderImpl(UInt64 val): _val(val) |
---|
1379 | { |
---|
1380 | } |
---|
1381 | |
---|
1382 | ~DynamicAnyHolderImpl() |
---|
1383 | { |
---|
1384 | } |
---|
1385 | |
---|
1386 | const std::type_info& type() const |
---|
1387 | { |
---|
1388 | return typeid(UInt64); |
---|
1389 | } |
---|
1390 | |
---|
1391 | void convert(Int8& val) const |
---|
1392 | { |
---|
1393 | convertUnsignedToSigned(_val, val); |
---|
1394 | } |
---|
1395 | |
---|
1396 | void convert(Int16& val) const |
---|
1397 | { |
---|
1398 | convertUnsignedToSigned(_val, val); |
---|
1399 | } |
---|
1400 | |
---|
1401 | void convert(Int32& val) const |
---|
1402 | { |
---|
1403 | convertUnsignedToSigned(_val, val); |
---|
1404 | } |
---|
1405 | |
---|
1406 | void convert(Int64& val) const |
---|
1407 | { |
---|
1408 | convertUnsignedToSigned(_val, val); |
---|
1409 | } |
---|
1410 | |
---|
1411 | void convert(UInt8& val) const |
---|
1412 | { |
---|
1413 | convertToSmallerUnsigned(_val, val); |
---|
1414 | } |
---|
1415 | |
---|
1416 | void convert(UInt16& val) const |
---|
1417 | { |
---|
1418 | convertToSmallerUnsigned(_val, val); |
---|
1419 | } |
---|
1420 | |
---|
1421 | void convert(UInt32& val) const |
---|
1422 | { |
---|
1423 | convertToSmallerUnsigned(_val, val); |
---|
1424 | } |
---|
1425 | |
---|
1426 | void convert(UInt64& val) const |
---|
1427 | { |
---|
1428 | val = _val; |
---|
1429 | } |
---|
1430 | |
---|
1431 | void convert(bool& val) const |
---|
1432 | { |
---|
1433 | val = (_val != 0); |
---|
1434 | } |
---|
1435 | |
---|
1436 | void convert(float& val) const |
---|
1437 | { |
---|
1438 | val = static_cast<float>(_val); |
---|
1439 | } |
---|
1440 | |
---|
1441 | void convert(double& val) const |
---|
1442 | { |
---|
1443 | val = static_cast<double>(_val); |
---|
1444 | } |
---|
1445 | |
---|
1446 | void convert(char& val) const |
---|
1447 | { |
---|
1448 | UInt8 tmp; |
---|
1449 | convert(tmp); |
---|
1450 | val = static_cast<char>(tmp); |
---|
1451 | } |
---|
1452 | |
---|
1453 | void convert(std::string& val) const |
---|
1454 | { |
---|
1455 | val = NumberFormatter::format(_val); |
---|
1456 | } |
---|
1457 | |
---|
1458 | void convert(DateTime& dt) const |
---|
1459 | { |
---|
1460 | Int64 val; |
---|
1461 | convertUnsignedToSigned(_val, val); |
---|
1462 | dt = Timestamp(val); |
---|
1463 | } |
---|
1464 | |
---|
1465 | void convert(LocalDateTime& ldt) const |
---|
1466 | { |
---|
1467 | Int64 val; |
---|
1468 | convertUnsignedToSigned(_val, val); |
---|
1469 | ldt = Timestamp(val); |
---|
1470 | } |
---|
1471 | |
---|
1472 | void convert(Timestamp& val) const |
---|
1473 | { |
---|
1474 | Int64 tmp; |
---|
1475 | convertUnsignedToSigned(_val, tmp); |
---|
1476 | val = Timestamp(tmp); |
---|
1477 | } |
---|
1478 | |
---|
1479 | DynamicAnyHolder* clone() const |
---|
1480 | { |
---|
1481 | return new DynamicAnyHolderImpl(_val); |
---|
1482 | } |
---|
1483 | |
---|
1484 | const UInt64& value() const |
---|
1485 | { |
---|
1486 | return _val; |
---|
1487 | } |
---|
1488 | |
---|
1489 | bool isArray() const |
---|
1490 | { |
---|
1491 | return false; |
---|
1492 | } |
---|
1493 | |
---|
1494 | bool isInteger() const |
---|
1495 | { |
---|
1496 | return std::numeric_limits<UInt64>::is_integer; |
---|
1497 | } |
---|
1498 | |
---|
1499 | bool isSigned() const |
---|
1500 | { |
---|
1501 | return std::numeric_limits<UInt64>::is_signed; |
---|
1502 | } |
---|
1503 | |
---|
1504 | bool isNumeric() const |
---|
1505 | { |
---|
1506 | return std::numeric_limits<UInt64>::is_specialized; |
---|
1507 | } |
---|
1508 | |
---|
1509 | bool isString() const |
---|
1510 | { |
---|
1511 | return false; |
---|
1512 | } |
---|
1513 | |
---|
1514 | private: |
---|
1515 | UInt64 _val; |
---|
1516 | }; |
---|
1517 | |
---|
1518 | |
---|
1519 | template <> |
---|
1520 | class DynamicAnyHolderImpl<bool>: public DynamicAnyHolder |
---|
1521 | { |
---|
1522 | public: |
---|
1523 | DynamicAnyHolderImpl(bool val): _val(val) |
---|
1524 | { |
---|
1525 | } |
---|
1526 | |
---|
1527 | ~DynamicAnyHolderImpl() |
---|
1528 | { |
---|
1529 | } |
---|
1530 | |
---|
1531 | const std::type_info& type() const |
---|
1532 | { |
---|
1533 | return typeid(bool); |
---|
1534 | } |
---|
1535 | |
---|
1536 | void convert(Int8& val) const |
---|
1537 | { |
---|
1538 | val = static_cast<Int8>(_val ? 1 : 0); |
---|
1539 | } |
---|
1540 | |
---|
1541 | void convert(Int16& val) const |
---|
1542 | { |
---|
1543 | val = static_cast<Int16>(_val ? 1 : 0); |
---|
1544 | } |
---|
1545 | |
---|
1546 | void convert(Int32& val) const |
---|
1547 | { |
---|
1548 | val = static_cast<Int32>(_val ? 1 : 0); |
---|
1549 | } |
---|
1550 | |
---|
1551 | void convert(Int64& val) const |
---|
1552 | { |
---|
1553 | val = static_cast<Int64>(_val ? 1 : 0); |
---|
1554 | } |
---|
1555 | |
---|
1556 | void convert(UInt8& val) const |
---|
1557 | { |
---|
1558 | val = static_cast<UInt8>(_val ? 1 : 0); |
---|
1559 | } |
---|
1560 | |
---|
1561 | void convert(UInt16& val) const |
---|
1562 | { |
---|
1563 | val = static_cast<UInt16>(_val ? 1 : 0); |
---|
1564 | } |
---|
1565 | |
---|
1566 | void convert(UInt32& val) const |
---|
1567 | { |
---|
1568 | val = static_cast<UInt32>(_val ? 1 : 0); |
---|
1569 | } |
---|
1570 | |
---|
1571 | void convert(UInt64& val) const |
---|
1572 | { |
---|
1573 | val = static_cast<UInt64>(_val ? 1 : 0); |
---|
1574 | } |
---|
1575 | |
---|
1576 | void convert(bool& val) const |
---|
1577 | { |
---|
1578 | val = _val; |
---|
1579 | } |
---|
1580 | |
---|
1581 | void convert(float& val) const |
---|
1582 | { |
---|
1583 | val = (_val ? 1.0f : 0.0f); |
---|
1584 | } |
---|
1585 | |
---|
1586 | void convert(double& val) const |
---|
1587 | { |
---|
1588 | val = (_val ? 1.0 : 0.0); |
---|
1589 | } |
---|
1590 | |
---|
1591 | void convert(char& val) const |
---|
1592 | { |
---|
1593 | val = static_cast<char>(_val ? 1 : 0); |
---|
1594 | } |
---|
1595 | |
---|
1596 | void convert(std::string& val) const |
---|
1597 | { |
---|
1598 | val = (_val ? "true" : "false"); |
---|
1599 | } |
---|
1600 | |
---|
1601 | void convert(DateTime&) const |
---|
1602 | { |
---|
1603 | throw BadCastException("bool -> DateTime"); |
---|
1604 | } |
---|
1605 | |
---|
1606 | void convert(LocalDateTime&) const |
---|
1607 | { |
---|
1608 | throw BadCastException("bool -> LocalDateTime"); |
---|
1609 | } |
---|
1610 | |
---|
1611 | void convert(Timestamp&) const |
---|
1612 | { |
---|
1613 | throw BadCastException("bool -> Timestamp"); |
---|
1614 | } |
---|
1615 | |
---|
1616 | DynamicAnyHolder* clone() const |
---|
1617 | { |
---|
1618 | return new DynamicAnyHolderImpl(_val); |
---|
1619 | } |
---|
1620 | |
---|
1621 | const bool& value() const |
---|
1622 | { |
---|
1623 | return _val; |
---|
1624 | } |
---|
1625 | |
---|
1626 | bool isArray() const |
---|
1627 | { |
---|
1628 | return false; |
---|
1629 | } |
---|
1630 | |
---|
1631 | bool isInteger() const |
---|
1632 | { |
---|
1633 | return std::numeric_limits<bool>::is_integer; |
---|
1634 | } |
---|
1635 | |
---|
1636 | bool isSigned() const |
---|
1637 | { |
---|
1638 | return std::numeric_limits<bool>::is_signed; |
---|
1639 | } |
---|
1640 | |
---|
1641 | bool isNumeric() const |
---|
1642 | { |
---|
1643 | return std::numeric_limits<bool>::is_specialized; |
---|
1644 | } |
---|
1645 | |
---|
1646 | bool isString() const |
---|
1647 | { |
---|
1648 | return false; |
---|
1649 | } |
---|
1650 | |
---|
1651 | private: |
---|
1652 | bool _val; |
---|
1653 | }; |
---|
1654 | |
---|
1655 | |
---|
1656 | template <> |
---|
1657 | class DynamicAnyHolderImpl<float>: public DynamicAnyHolder |
---|
1658 | { |
---|
1659 | public: |
---|
1660 | DynamicAnyHolderImpl(float val): _val(val) |
---|
1661 | { |
---|
1662 | } |
---|
1663 | |
---|
1664 | ~DynamicAnyHolderImpl() |
---|
1665 | { |
---|
1666 | } |
---|
1667 | |
---|
1668 | const std::type_info& type() const |
---|
1669 | { |
---|
1670 | return typeid(float); |
---|
1671 | } |
---|
1672 | |
---|
1673 | void convert(Int8& val) const |
---|
1674 | { |
---|
1675 | convertToSmaller(_val, val); |
---|
1676 | } |
---|
1677 | |
---|
1678 | void convert(Int16& val) const |
---|
1679 | { |
---|
1680 | convertToSmaller(_val, val); |
---|
1681 | } |
---|
1682 | |
---|
1683 | void convert(Int32& val) const |
---|
1684 | { |
---|
1685 | convertToSmaller(_val, val); |
---|
1686 | } |
---|
1687 | |
---|
1688 | void convert(Int64& val) const |
---|
1689 | { |
---|
1690 | convertToSmaller(_val, val); |
---|
1691 | } |
---|
1692 | |
---|
1693 | void convert(UInt8& val) const |
---|
1694 | { |
---|
1695 | convertSignedFloatToUnsigned(_val, val); |
---|
1696 | } |
---|
1697 | |
---|
1698 | void convert(UInt16& val) const |
---|
1699 | { |
---|
1700 | convertSignedFloatToUnsigned(_val, val); |
---|
1701 | } |
---|
1702 | |
---|
1703 | void convert(UInt32& val) const |
---|
1704 | { |
---|
1705 | convertSignedFloatToUnsigned(_val, val); |
---|
1706 | } |
---|
1707 | |
---|
1708 | void convert(UInt64& val) const |
---|
1709 | { |
---|
1710 | convertSignedFloatToUnsigned(_val, val); |
---|
1711 | } |
---|
1712 | |
---|
1713 | void convert(bool& val) const |
---|
1714 | { |
---|
1715 | val = !(_val <= std::numeric_limits<float>::min() && |
---|
1716 | _val >= -1 * std::numeric_limits<float>::min()); |
---|
1717 | } |
---|
1718 | |
---|
1719 | void convert(float& val) const |
---|
1720 | { |
---|
1721 | val = _val; |
---|
1722 | } |
---|
1723 | |
---|
1724 | void convert(double& val) const |
---|
1725 | { |
---|
1726 | val = _val; |
---|
1727 | } |
---|
1728 | |
---|
1729 | void convert(char& val) const |
---|
1730 | { |
---|
1731 | UInt8 tmp; |
---|
1732 | convert(tmp); |
---|
1733 | val = static_cast<char>(tmp); |
---|
1734 | } |
---|
1735 | |
---|
1736 | void convert(std::string& val) const |
---|
1737 | { |
---|
1738 | val = NumberFormatter::format(_val); |
---|
1739 | } |
---|
1740 | |
---|
1741 | void convert(DateTime&) const |
---|
1742 | { |
---|
1743 | throw BadCastException("float -> DateTime"); |
---|
1744 | } |
---|
1745 | |
---|
1746 | void convert(LocalDateTime&) const |
---|
1747 | { |
---|
1748 | throw BadCastException("float -> LocalDateTime"); |
---|
1749 | } |
---|
1750 | |
---|
1751 | void convert(Timestamp&) const |
---|
1752 | { |
---|
1753 | throw BadCastException("float -> Timestamp"); |
---|
1754 | } |
---|
1755 | |
---|
1756 | DynamicAnyHolder* clone() const |
---|
1757 | { |
---|
1758 | return new DynamicAnyHolderImpl(_val); |
---|
1759 | } |
---|
1760 | |
---|
1761 | const float& value() const |
---|
1762 | { |
---|
1763 | return _val; |
---|
1764 | } |
---|
1765 | |
---|
1766 | bool isArray() const |
---|
1767 | { |
---|
1768 | return false; |
---|
1769 | } |
---|
1770 | |
---|
1771 | bool isInteger() const |
---|
1772 | { |
---|
1773 | return std::numeric_limits<float>::is_integer; |
---|
1774 | } |
---|
1775 | |
---|
1776 | bool isSigned() const |
---|
1777 | { |
---|
1778 | return std::numeric_limits<float>::is_signed; |
---|
1779 | } |
---|
1780 | |
---|
1781 | bool isNumeric() const |
---|
1782 | { |
---|
1783 | return std::numeric_limits<float>::is_specialized; |
---|
1784 | } |
---|
1785 | |
---|
1786 | bool isString() const |
---|
1787 | { |
---|
1788 | return false; |
---|
1789 | } |
---|
1790 | |
---|
1791 | private: |
---|
1792 | float _val; |
---|
1793 | }; |
---|
1794 | |
---|
1795 | |
---|
1796 | template <> |
---|
1797 | class DynamicAnyHolderImpl<double>: public DynamicAnyHolder |
---|
1798 | { |
---|
1799 | public: |
---|
1800 | DynamicAnyHolderImpl(double val): _val(val) |
---|
1801 | { |
---|
1802 | } |
---|
1803 | |
---|
1804 | ~DynamicAnyHolderImpl() |
---|
1805 | { |
---|
1806 | } |
---|
1807 | |
---|
1808 | const std::type_info& type() const |
---|
1809 | { |
---|
1810 | return typeid(double); |
---|
1811 | } |
---|
1812 | |
---|
1813 | void convert(Int8& val) const |
---|
1814 | { |
---|
1815 | convertToSmaller(_val, val); |
---|
1816 | } |
---|
1817 | |
---|
1818 | void convert(Int16& val) const |
---|
1819 | { |
---|
1820 | convertToSmaller(_val, val); |
---|
1821 | } |
---|
1822 | |
---|
1823 | void convert(Int32& val) const |
---|
1824 | { |
---|
1825 | convertToSmaller(_val, val); |
---|
1826 | } |
---|
1827 | |
---|
1828 | void convert(Int64& val) const |
---|
1829 | { |
---|
1830 | convertToSmaller(_val, val); |
---|
1831 | } |
---|
1832 | |
---|
1833 | void convert(UInt8& val) const |
---|
1834 | { |
---|
1835 | convertSignedFloatToUnsigned(_val, val); |
---|
1836 | } |
---|
1837 | |
---|
1838 | void convert(UInt16& val) const |
---|
1839 | { |
---|
1840 | convertSignedFloatToUnsigned(_val, val); |
---|
1841 | } |
---|
1842 | |
---|
1843 | void convert(UInt32& val) const |
---|
1844 | { |
---|
1845 | convertSignedFloatToUnsigned(_val, val); |
---|
1846 | } |
---|
1847 | |
---|
1848 | void convert(UInt64& val) const |
---|
1849 | { |
---|
1850 | convertSignedFloatToUnsigned(_val, val); |
---|
1851 | } |
---|
1852 | |
---|
1853 | void convert(bool& val) const |
---|
1854 | { |
---|
1855 | val = !(_val <= std::numeric_limits<double>::min() && |
---|
1856 | _val >= -1 * std::numeric_limits<double>::min()); |
---|
1857 | } |
---|
1858 | |
---|
1859 | void convert(float& val) const |
---|
1860 | { |
---|
1861 | double fMin = -1 * std::numeric_limits<float>::max(); |
---|
1862 | double fMax = std::numeric_limits<float>::max(); |
---|
1863 | |
---|
1864 | if (_val < fMin) throw RangeException("Value too small."); |
---|
1865 | if (_val > fMax) throw RangeException("Value too large."); |
---|
1866 | |
---|
1867 | val = static_cast<float>(_val); |
---|
1868 | } |
---|
1869 | |
---|
1870 | void convert(double& val) const |
---|
1871 | { |
---|
1872 | val = _val; |
---|
1873 | } |
---|
1874 | |
---|
1875 | void convert(char& val) const |
---|
1876 | { |
---|
1877 | UInt8 tmp; |
---|
1878 | convert(tmp); |
---|
1879 | val = static_cast<char>(tmp); |
---|
1880 | } |
---|
1881 | |
---|
1882 | void convert(std::string& val) const |
---|
1883 | { |
---|
1884 | val = NumberFormatter::format(_val); |
---|
1885 | } |
---|
1886 | |
---|
1887 | void convert(DateTime&) const |
---|
1888 | { |
---|
1889 | throw BadCastException("double -> DateTime"); |
---|
1890 | } |
---|
1891 | |
---|
1892 | void convert(LocalDateTime&) const |
---|
1893 | { |
---|
1894 | throw BadCastException("double -> LocalDateTime"); |
---|
1895 | } |
---|
1896 | |
---|
1897 | void convert(Timestamp&) const |
---|
1898 | { |
---|
1899 | throw BadCastException("double -> Timestamp"); |
---|
1900 | } |
---|
1901 | |
---|
1902 | DynamicAnyHolder* clone() const |
---|
1903 | { |
---|
1904 | return new DynamicAnyHolderImpl(_val); |
---|
1905 | } |
---|
1906 | |
---|
1907 | const double& value() const |
---|
1908 | { |
---|
1909 | return _val; |
---|
1910 | } |
---|
1911 | |
---|
1912 | bool isArray() const |
---|
1913 | { |
---|
1914 | return false; |
---|
1915 | } |
---|
1916 | |
---|
1917 | bool isInteger() const |
---|
1918 | { |
---|
1919 | return std::numeric_limits<double>::is_integer; |
---|
1920 | } |
---|
1921 | |
---|
1922 | bool isSigned() const |
---|
1923 | { |
---|
1924 | return std::numeric_limits<double>::is_signed; |
---|
1925 | } |
---|
1926 | |
---|
1927 | bool isNumeric() const |
---|
1928 | { |
---|
1929 | return std::numeric_limits<double>::is_specialized; |
---|
1930 | } |
---|
1931 | |
---|
1932 | bool isString() const |
---|
1933 | { |
---|
1934 | return false; |
---|
1935 | } |
---|
1936 | |
---|
1937 | private: |
---|
1938 | double _val; |
---|
1939 | }; |
---|
1940 | |
---|
1941 | |
---|
1942 | template <> |
---|
1943 | class DynamicAnyHolderImpl<char>: public DynamicAnyHolder |
---|
1944 | { |
---|
1945 | public: |
---|
1946 | DynamicAnyHolderImpl(char val): _val(val) |
---|
1947 | { |
---|
1948 | } |
---|
1949 | |
---|
1950 | ~DynamicAnyHolderImpl() |
---|
1951 | { |
---|
1952 | } |
---|
1953 | |
---|
1954 | const std::type_info& type() const |
---|
1955 | { |
---|
1956 | return typeid(char); |
---|
1957 | } |
---|
1958 | |
---|
1959 | void convert(Int8& val) const |
---|
1960 | { |
---|
1961 | val = static_cast<Int8>(_val); |
---|
1962 | } |
---|
1963 | |
---|
1964 | void convert(Int16& val) const |
---|
1965 | { |
---|
1966 | val = static_cast<UInt8>(_val); |
---|
1967 | } |
---|
1968 | |
---|
1969 | void convert(Int32& val) const |
---|
1970 | { |
---|
1971 | val = static_cast<UInt8>(_val); |
---|
1972 | } |
---|
1973 | |
---|
1974 | void convert(Int64& val) const |
---|
1975 | { |
---|
1976 | val = static_cast<UInt8>(_val); |
---|
1977 | } |
---|
1978 | |
---|
1979 | void convert(UInt8& val) const |
---|
1980 | { |
---|
1981 | val = static_cast<UInt8>(_val); |
---|
1982 | } |
---|
1983 | |
---|
1984 | void convert(UInt16& val) const |
---|
1985 | { |
---|
1986 | val = static_cast<UInt8>(_val); |
---|
1987 | } |
---|
1988 | |
---|
1989 | void convert(UInt32& val) const |
---|
1990 | { |
---|
1991 | val = static_cast<UInt8>(_val); |
---|
1992 | } |
---|
1993 | |
---|
1994 | void convert(UInt64& val) const |
---|
1995 | { |
---|
1996 | val = static_cast<UInt8>(_val); |
---|
1997 | } |
---|
1998 | |
---|
1999 | void convert(bool& val) const |
---|
2000 | { |
---|
2001 | val = (_val != '\0'); |
---|
2002 | } |
---|
2003 | |
---|
2004 | void convert(float& val) const |
---|
2005 | { |
---|
2006 | val = static_cast<float>(_val); |
---|
2007 | } |
---|
2008 | |
---|
2009 | void convert(double& val) const |
---|
2010 | { |
---|
2011 | val = static_cast<double>(_val); |
---|
2012 | } |
---|
2013 | |
---|
2014 | void convert(char& val) const |
---|
2015 | { |
---|
2016 | val = _val; |
---|
2017 | } |
---|
2018 | |
---|
2019 | void convert(std::string& val) const |
---|
2020 | { |
---|
2021 | val = std::string(1, _val); |
---|
2022 | } |
---|
2023 | |
---|
2024 | void convert(DateTime&) const |
---|
2025 | { |
---|
2026 | throw BadCastException("char -> DateTime"); |
---|
2027 | } |
---|
2028 | |
---|
2029 | void convert(LocalDateTime&) const |
---|
2030 | { |
---|
2031 | throw BadCastException("char -> LocalDateTime"); |
---|
2032 | } |
---|
2033 | |
---|
2034 | void convert(Timestamp&) const |
---|
2035 | { |
---|
2036 | throw BadCastException("char -> Timestamp"); |
---|
2037 | } |
---|
2038 | |
---|
2039 | DynamicAnyHolder* clone() const |
---|
2040 | { |
---|
2041 | return new DynamicAnyHolderImpl(_val); |
---|
2042 | } |
---|
2043 | |
---|
2044 | const char& value() const |
---|
2045 | { |
---|
2046 | return _val; |
---|
2047 | } |
---|
2048 | |
---|
2049 | bool isArray() const |
---|
2050 | { |
---|
2051 | return false; |
---|
2052 | } |
---|
2053 | |
---|
2054 | bool isInteger() const |
---|
2055 | { |
---|
2056 | return std::numeric_limits<char>::is_integer; |
---|
2057 | } |
---|
2058 | |
---|
2059 | bool isSigned() const |
---|
2060 | { |
---|
2061 | return std::numeric_limits<char>::is_signed; |
---|
2062 | } |
---|
2063 | |
---|
2064 | bool isNumeric() const |
---|
2065 | { |
---|
2066 | return std::numeric_limits<char>::is_specialized; |
---|
2067 | } |
---|
2068 | |
---|
2069 | bool isString() const |
---|
2070 | { |
---|
2071 | return false; |
---|
2072 | } |
---|
2073 | |
---|
2074 | private: |
---|
2075 | char _val; |
---|
2076 | }; |
---|
2077 | |
---|
2078 | |
---|
2079 | template <> |
---|
2080 | class DynamicAnyHolderImpl<std::string>: public DynamicAnyHolder |
---|
2081 | { |
---|
2082 | public: |
---|
2083 | DynamicAnyHolderImpl(const char* pVal): _val(pVal) |
---|
2084 | { |
---|
2085 | } |
---|
2086 | |
---|
2087 | DynamicAnyHolderImpl(const std::string& val): _val(val) |
---|
2088 | { |
---|
2089 | } |
---|
2090 | |
---|
2091 | ~DynamicAnyHolderImpl() |
---|
2092 | { |
---|
2093 | } |
---|
2094 | |
---|
2095 | const std::type_info& type() const |
---|
2096 | { |
---|
2097 | return typeid(std::string); |
---|
2098 | } |
---|
2099 | |
---|
2100 | void convert(Int8& val) const |
---|
2101 | { |
---|
2102 | int v = NumberParser::parse(_val); |
---|
2103 | convertToSmaller(v, val); |
---|
2104 | } |
---|
2105 | |
---|
2106 | void convert(Int16& val) const |
---|
2107 | { |
---|
2108 | int v = NumberParser::parse(_val); |
---|
2109 | convertToSmaller(v, val); |
---|
2110 | } |
---|
2111 | |
---|
2112 | void convert(Int32& val) const |
---|
2113 | { |
---|
2114 | val = NumberParser::parse(_val); |
---|
2115 | } |
---|
2116 | |
---|
2117 | void convert(Int64& val) const |
---|
2118 | { |
---|
2119 | val = NumberParser::parse64(_val); |
---|
2120 | } |
---|
2121 | |
---|
2122 | void convert(UInt8& val) const |
---|
2123 | { |
---|
2124 | unsigned int v = NumberParser::parseUnsigned(_val); |
---|
2125 | convertToSmallerUnsigned(v, val); |
---|
2126 | } |
---|
2127 | |
---|
2128 | void convert(UInt16& val) const |
---|
2129 | { |
---|
2130 | unsigned int v = NumberParser::parseUnsigned(_val); |
---|
2131 | convertToSmallerUnsigned(v, val); |
---|
2132 | } |
---|
2133 | |
---|
2134 | void convert(UInt32& val) const |
---|
2135 | { |
---|
2136 | val = NumberParser::parseUnsigned(_val); |
---|
2137 | } |
---|
2138 | |
---|
2139 | void convert(UInt64& val) const |
---|
2140 | { |
---|
2141 | val = NumberParser::parseUnsigned64(_val); |
---|
2142 | } |
---|
2143 | |
---|
2144 | void convert(bool& val) const |
---|
2145 | { |
---|
2146 | static const std::string VAL_FALSE("false"); |
---|
2147 | static const std::string VAL_INTFALSE("0"); |
---|
2148 | |
---|
2149 | if (_val == VAL_INTFALSE || (icompare(_val, VAL_FALSE) == 0)) |
---|
2150 | val = false; |
---|
2151 | else |
---|
2152 | val = true; |
---|
2153 | } |
---|
2154 | |
---|
2155 | void convert(float& val) const |
---|
2156 | { |
---|
2157 | double v = NumberParser::parseFloat(_val); |
---|
2158 | convertToSmaller(v, val); |
---|
2159 | } |
---|
2160 | |
---|
2161 | void convert(double& val) const |
---|
2162 | { |
---|
2163 | val = NumberParser::parseFloat(_val); |
---|
2164 | } |
---|
2165 | |
---|
2166 | void convert(char& val) const |
---|
2167 | { |
---|
2168 | if (_val.empty()) |
---|
2169 | val = '\0'; |
---|
2170 | else |
---|
2171 | val = _val[0]; |
---|
2172 | } |
---|
2173 | |
---|
2174 | void convert(std::string& val) const |
---|
2175 | { |
---|
2176 | val = _val; |
---|
2177 | } |
---|
2178 | |
---|
2179 | void convert(DateTime& val) const |
---|
2180 | { |
---|
2181 | int tzd = 0; |
---|
2182 | if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, val, tzd)) |
---|
2183 | throw BadCastException("string -> DateTime"); |
---|
2184 | } |
---|
2185 | |
---|
2186 | void convert(LocalDateTime& ldt) const |
---|
2187 | { |
---|
2188 | int tzd = 0; |
---|
2189 | DateTime tmp; |
---|
2190 | if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, tmp, tzd)) |
---|
2191 | throw BadCastException("string -> LocalDateTime"); |
---|
2192 | |
---|
2193 | ldt = LocalDateTime(tzd, tmp, false); |
---|
2194 | } |
---|
2195 | |
---|
2196 | void convert(Timestamp& ts) const |
---|
2197 | { |
---|
2198 | int tzd = 0; |
---|
2199 | DateTime tmp; |
---|
2200 | if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, tmp, tzd)) |
---|
2201 | throw BadCastException("string -> Timestamp"); |
---|
2202 | |
---|
2203 | ts = tmp.timestamp(); |
---|
2204 | } |
---|
2205 | |
---|
2206 | DynamicAnyHolder* clone() const |
---|
2207 | { |
---|
2208 | return new DynamicAnyHolderImpl(_val); |
---|
2209 | } |
---|
2210 | |
---|
2211 | const std::string& value() const |
---|
2212 | { |
---|
2213 | return _val; |
---|
2214 | } |
---|
2215 | |
---|
2216 | bool isArray() const |
---|
2217 | { |
---|
2218 | return false; |
---|
2219 | } |
---|
2220 | |
---|
2221 | bool isInteger() const |
---|
2222 | { |
---|
2223 | return false; |
---|
2224 | } |
---|
2225 | |
---|
2226 | bool isSigned() const |
---|
2227 | { |
---|
2228 | return false; |
---|
2229 | } |
---|
2230 | |
---|
2231 | bool isNumeric() const |
---|
2232 | { |
---|
2233 | return false; |
---|
2234 | } |
---|
2235 | |
---|
2236 | bool isString() const |
---|
2237 | { |
---|
2238 | return true; |
---|
2239 | } |
---|
2240 | |
---|
2241 | private: |
---|
2242 | std::string _val; |
---|
2243 | }; |
---|
2244 | |
---|
2245 | |
---|
2246 | #ifndef POCO_LONG_IS_64_BIT |
---|
2247 | |
---|
2248 | |
---|
2249 | template <> |
---|
2250 | class DynamicAnyHolderImpl<long>: public DynamicAnyHolder |
---|
2251 | { |
---|
2252 | public: |
---|
2253 | DynamicAnyHolderImpl(long val): _val(val) |
---|
2254 | { |
---|
2255 | } |
---|
2256 | |
---|
2257 | ~DynamicAnyHolderImpl() |
---|
2258 | { |
---|
2259 | } |
---|
2260 | |
---|
2261 | const std::type_info& type() const |
---|
2262 | { |
---|
2263 | return typeid(long); |
---|
2264 | } |
---|
2265 | |
---|
2266 | void convert(Int8& val) const |
---|
2267 | { |
---|
2268 | convertToSmaller(_val, val); |
---|
2269 | } |
---|
2270 | |
---|
2271 | void convert(Int16& val) const |
---|
2272 | { |
---|
2273 | convertToSmaller(_val, val); |
---|
2274 | } |
---|
2275 | |
---|
2276 | void convert(Int32& val) const |
---|
2277 | { |
---|
2278 | val = static_cast<Int32>(_val); |
---|
2279 | } |
---|
2280 | |
---|
2281 | void convert(Int64& val) const |
---|
2282 | { |
---|
2283 | val = static_cast<Int64>(_val); |
---|
2284 | } |
---|
2285 | |
---|
2286 | void convert(UInt8& val) const |
---|
2287 | { |
---|
2288 | convertSignedToUnsigned(_val, val); |
---|
2289 | } |
---|
2290 | |
---|
2291 | void convert(UInt16& val) const |
---|
2292 | { |
---|
2293 | convertSignedToUnsigned(_val, val); |
---|
2294 | } |
---|
2295 | |
---|
2296 | void convert(UInt32& val) const |
---|
2297 | { |
---|
2298 | convertSignedToUnsigned(_val, val); |
---|
2299 | } |
---|
2300 | |
---|
2301 | void convert(UInt64& val) const |
---|
2302 | { |
---|
2303 | convertSignedToUnsigned(_val, val); |
---|
2304 | } |
---|
2305 | |
---|
2306 | void convert(bool& val) const |
---|
2307 | { |
---|
2308 | val = (_val != 0); |
---|
2309 | } |
---|
2310 | |
---|
2311 | void convert(float& val) const |
---|
2312 | { |
---|
2313 | val = static_cast<float>(_val); |
---|
2314 | } |
---|
2315 | |
---|
2316 | void convert(double& val) const |
---|
2317 | { |
---|
2318 | val = static_cast<double>(_val); |
---|
2319 | } |
---|
2320 | |
---|
2321 | void convert(char& val) const |
---|
2322 | { |
---|
2323 | UInt8 tmp; |
---|
2324 | convert(tmp); |
---|
2325 | val = static_cast<char>(tmp); |
---|
2326 | } |
---|
2327 | |
---|
2328 | void convert(std::string& val) const |
---|
2329 | { |
---|
2330 | val = NumberFormatter::format(_val); |
---|
2331 | } |
---|
2332 | |
---|
2333 | void convert(DateTime&) const |
---|
2334 | { |
---|
2335 | throw BadCastException("long -> DateTime"); |
---|
2336 | } |
---|
2337 | |
---|
2338 | void convert(LocalDateTime&) const |
---|
2339 | { |
---|
2340 | throw BadCastException("long -> LocalDateTime"); |
---|
2341 | } |
---|
2342 | |
---|
2343 | void convert(Timestamp&) const |
---|
2344 | { |
---|
2345 | throw BadCastException("long -> Timestamp"); |
---|
2346 | } |
---|
2347 | |
---|
2348 | DynamicAnyHolder* clone() const |
---|
2349 | { |
---|
2350 | return new DynamicAnyHolderImpl(_val); |
---|
2351 | } |
---|
2352 | |
---|
2353 | const long& value() const |
---|
2354 | { |
---|
2355 | return _val; |
---|
2356 | } |
---|
2357 | |
---|
2358 | bool isArray() const |
---|
2359 | { |
---|
2360 | return false; |
---|
2361 | } |
---|
2362 | |
---|
2363 | bool isInteger() const |
---|
2364 | { |
---|
2365 | return std::numeric_limits<long>::is_integer; |
---|
2366 | } |
---|
2367 | |
---|
2368 | bool isSigned() const |
---|
2369 | { |
---|
2370 | return std::numeric_limits<long>::is_signed; |
---|
2371 | } |
---|
2372 | |
---|
2373 | bool isNumeric() const |
---|
2374 | { |
---|
2375 | return std::numeric_limits<long>::is_specialized; |
---|
2376 | } |
---|
2377 | |
---|
2378 | bool isString() const |
---|
2379 | { |
---|
2380 | return false; |
---|
2381 | } |
---|
2382 | |
---|
2383 | private: |
---|
2384 | long _val; |
---|
2385 | }; |
---|
2386 | |
---|
2387 | |
---|
2388 | template <> |
---|
2389 | class DynamicAnyHolderImpl<unsigned long>: public DynamicAnyHolder |
---|
2390 | { |
---|
2391 | public: |
---|
2392 | DynamicAnyHolderImpl(unsigned long val): _val(val) |
---|
2393 | { |
---|
2394 | } |
---|
2395 | |
---|
2396 | ~DynamicAnyHolderImpl() |
---|
2397 | { |
---|
2398 | } |
---|
2399 | |
---|
2400 | const std::type_info& type() const |
---|
2401 | { |
---|
2402 | return typeid(unsigned long); |
---|
2403 | } |
---|
2404 | |
---|
2405 | void convert(Int8& val) const |
---|
2406 | { |
---|
2407 | convertUnsignedToSigned(_val, val); |
---|
2408 | } |
---|
2409 | |
---|
2410 | void convert(Int16& val) const |
---|
2411 | { |
---|
2412 | convertUnsignedToSigned(_val, val); |
---|
2413 | } |
---|
2414 | |
---|
2415 | void convert(Int32& val) const |
---|
2416 | { |
---|
2417 | convertUnsignedToSigned(_val, val); |
---|
2418 | } |
---|
2419 | |
---|
2420 | void convert(Int64& val) const |
---|
2421 | { |
---|
2422 | convertUnsignedToSigned(_val, val); |
---|
2423 | } |
---|
2424 | |
---|
2425 | void convert(UInt8& val) const |
---|
2426 | { |
---|
2427 | convertToSmallerUnsigned(_val, val); |
---|
2428 | } |
---|
2429 | |
---|
2430 | void convert(UInt16& val) const |
---|
2431 | { |
---|
2432 | convertToSmallerUnsigned(_val, val); |
---|
2433 | } |
---|
2434 | |
---|
2435 | void convert(UInt32& val) const |
---|
2436 | { |
---|
2437 | convertToSmallerUnsigned(_val, val); |
---|
2438 | } |
---|
2439 | |
---|
2440 | void convert(UInt64& val) const |
---|
2441 | { |
---|
2442 | val = static_cast<UInt64>(_val); |
---|
2443 | } |
---|
2444 | |
---|
2445 | void convert(bool& val) const |
---|
2446 | { |
---|
2447 | val = (_val != 0); |
---|
2448 | } |
---|
2449 | |
---|
2450 | void convert(float& val) const |
---|
2451 | { |
---|
2452 | val = static_cast<float>(_val); |
---|
2453 | } |
---|
2454 | |
---|
2455 | void convert(double& val) const |
---|
2456 | { |
---|
2457 | val = static_cast<double>(_val); |
---|
2458 | } |
---|
2459 | |
---|
2460 | void convert(char& val) const |
---|
2461 | { |
---|
2462 | UInt8 tmp; |
---|
2463 | convert(tmp); |
---|
2464 | val = static_cast<char>(tmp); |
---|
2465 | } |
---|
2466 | |
---|
2467 | void convert(std::string& val) const |
---|
2468 | { |
---|
2469 | val = NumberFormatter::format(_val); |
---|
2470 | } |
---|
2471 | |
---|
2472 | void convert(DateTime&) const |
---|
2473 | { |
---|
2474 | throw BadCastException("unsigned long -> DateTime"); |
---|
2475 | } |
---|
2476 | |
---|
2477 | void convert(LocalDateTime&) const |
---|
2478 | { |
---|
2479 | throw BadCastException("unsigned long -> LocalDateTime"); |
---|
2480 | } |
---|
2481 | |
---|
2482 | void convert(Timestamp&) const |
---|
2483 | { |
---|
2484 | throw BadCastException("unsigned long -> Timestamp"); |
---|
2485 | } |
---|
2486 | |
---|
2487 | DynamicAnyHolder* clone() const |
---|
2488 | { |
---|
2489 | return new DynamicAnyHolderImpl(_val); |
---|
2490 | } |
---|
2491 | |
---|
2492 | const unsigned long& value() const |
---|
2493 | { |
---|
2494 | return _val; |
---|
2495 | } |
---|
2496 | |
---|
2497 | bool isArray() const |
---|
2498 | { |
---|
2499 | return false; |
---|
2500 | } |
---|
2501 | |
---|
2502 | bool isInteger() const |
---|
2503 | { |
---|
2504 | return std::numeric_limits<unsigned long>::is_integer; |
---|
2505 | } |
---|
2506 | |
---|
2507 | bool isSigned() const |
---|
2508 | { |
---|
2509 | return std::numeric_limits<unsigned long>::is_signed; |
---|
2510 | } |
---|
2511 | |
---|
2512 | bool isNumeric() const |
---|
2513 | { |
---|
2514 | return std::numeric_limits<unsigned long>::is_specialized; |
---|
2515 | } |
---|
2516 | |
---|
2517 | bool isString() const |
---|
2518 | { |
---|
2519 | return false; |
---|
2520 | } |
---|
2521 | |
---|
2522 | private: |
---|
2523 | unsigned long _val; |
---|
2524 | }; |
---|
2525 | |
---|
2526 | |
---|
2527 | #endif // 64bit |
---|
2528 | |
---|
2529 | |
---|
2530 | template <typename T> |
---|
2531 | class DynamicAnyHolderImpl<std::vector<T> >: public DynamicAnyHolder |
---|
2532 | { |
---|
2533 | public: |
---|
2534 | DynamicAnyHolderImpl(const std::vector<T>& val): _val(val) |
---|
2535 | { |
---|
2536 | } |
---|
2537 | |
---|
2538 | ~DynamicAnyHolderImpl() |
---|
2539 | { |
---|
2540 | } |
---|
2541 | |
---|
2542 | const std::type_info& type() const |
---|
2543 | { |
---|
2544 | return typeid(std::vector<T>); |
---|
2545 | } |
---|
2546 | |
---|
2547 | void convert(Int8& val) const |
---|
2548 | { |
---|
2549 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2550 | } |
---|
2551 | |
---|
2552 | void convert(Int16& val) const |
---|
2553 | { |
---|
2554 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2555 | } |
---|
2556 | |
---|
2557 | void convert(Int32& val) const |
---|
2558 | { |
---|
2559 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2560 | } |
---|
2561 | |
---|
2562 | void convert(Int64& val) const |
---|
2563 | { |
---|
2564 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2565 | } |
---|
2566 | |
---|
2567 | void convert(UInt8& val) const |
---|
2568 | { |
---|
2569 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2570 | } |
---|
2571 | |
---|
2572 | void convert(UInt16& val) const |
---|
2573 | { |
---|
2574 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2575 | } |
---|
2576 | |
---|
2577 | void convert(UInt32& val) const |
---|
2578 | { |
---|
2579 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2580 | } |
---|
2581 | |
---|
2582 | void convert(UInt64& val) const |
---|
2583 | { |
---|
2584 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2585 | } |
---|
2586 | |
---|
2587 | void convert(bool& val) const |
---|
2588 | { |
---|
2589 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2590 | } |
---|
2591 | |
---|
2592 | void convert(float& val) const |
---|
2593 | { |
---|
2594 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2595 | } |
---|
2596 | |
---|
2597 | void convert(double& val) const |
---|
2598 | { |
---|
2599 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2600 | } |
---|
2601 | |
---|
2602 | void convert(char& val) const |
---|
2603 | { |
---|
2604 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2605 | } |
---|
2606 | |
---|
2607 | void convert(std::string& val) const |
---|
2608 | { |
---|
2609 | throw BadCastException("Cannot cast collection type to non-collection type"); |
---|
2610 | } |
---|
2611 | |
---|
2612 | void convert(DateTime&) const |
---|
2613 | { |
---|
2614 | throw BadCastException("vector -> DateTime"); |
---|
2615 | } |
---|
2616 | |
---|
2617 | void convert(LocalDateTime&) const |
---|
2618 | { |
---|
2619 | throw BadCastException("vector -> LocalDateTime"); |
---|
2620 | } |
---|
2621 | |
---|
2622 | void convert(Timestamp&) const |
---|
2623 | { |
---|
2624 | throw BadCastException("vector -> Timestamp"); |
---|
2625 | } |
---|
2626 | |
---|
2627 | DynamicAnyHolder* clone() const |
---|
2628 | { |
---|
2629 | return new DynamicAnyHolderImpl(_val); |
---|
2630 | } |
---|
2631 | |
---|
2632 | const std::vector<T>& value() const |
---|
2633 | { |
---|
2634 | return _val; |
---|
2635 | } |
---|
2636 | |
---|
2637 | bool isArray() const |
---|
2638 | { |
---|
2639 | return true; |
---|
2640 | } |
---|
2641 | |
---|
2642 | bool isInteger() const |
---|
2643 | { |
---|
2644 | return false; |
---|
2645 | } |
---|
2646 | |
---|
2647 | bool isSigned() const |
---|
2648 | { |
---|
2649 | return false; |
---|
2650 | } |
---|
2651 | |
---|
2652 | bool isNumeric() const |
---|
2653 | { |
---|
2654 | return false; |
---|
2655 | } |
---|
2656 | |
---|
2657 | bool isString() const |
---|
2658 | { |
---|
2659 | return false; |
---|
2660 | } |
---|
2661 | |
---|
2662 | T& operator[](typename std::vector<T>::size_type n) |
---|
2663 | { |
---|
2664 | return _val.operator[](n); |
---|
2665 | } |
---|
2666 | |
---|
2667 | const T& operator[](typename std::vector<T>::size_type n) const |
---|
2668 | { |
---|
2669 | return _val.operator[](n); |
---|
2670 | } |
---|
2671 | |
---|
2672 | private: |
---|
2673 | std::vector<T> _val; |
---|
2674 | }; |
---|
2675 | |
---|
2676 | |
---|
2677 | template <> |
---|
2678 | class DynamicAnyHolderImpl<DateTime>: public DynamicAnyHolder |
---|
2679 | { |
---|
2680 | public: |
---|
2681 | DynamicAnyHolderImpl(const DateTime& val): _val(val) |
---|
2682 | { |
---|
2683 | } |
---|
2684 | |
---|
2685 | ~DynamicAnyHolderImpl() |
---|
2686 | { |
---|
2687 | } |
---|
2688 | |
---|
2689 | const std::type_info& type() const |
---|
2690 | { |
---|
2691 | return typeid(DateTime); |
---|
2692 | } |
---|
2693 | |
---|
2694 | void convert(Int8&) const |
---|
2695 | { |
---|
2696 | throw BadCastException(); |
---|
2697 | } |
---|
2698 | |
---|
2699 | void convert(Int16&) const |
---|
2700 | { |
---|
2701 | throw BadCastException(); |
---|
2702 | } |
---|
2703 | |
---|
2704 | void convert(Int32&) const |
---|
2705 | { |
---|
2706 | throw BadCastException(); |
---|
2707 | } |
---|
2708 | |
---|
2709 | void convert(Int64& val) const |
---|
2710 | { |
---|
2711 | val = _val.timestamp().epochMicroseconds(); |
---|
2712 | } |
---|
2713 | |
---|
2714 | void convert(UInt8&) const |
---|
2715 | { |
---|
2716 | throw BadCastException(); |
---|
2717 | } |
---|
2718 | |
---|
2719 | void convert(UInt16&) const |
---|
2720 | { |
---|
2721 | throw BadCastException(); |
---|
2722 | } |
---|
2723 | |
---|
2724 | void convert(UInt32&) const |
---|
2725 | { |
---|
2726 | throw BadCastException(); |
---|
2727 | } |
---|
2728 | |
---|
2729 | void convert(UInt64& val) const |
---|
2730 | { |
---|
2731 | val = _val.timestamp().epochMicroseconds(); |
---|
2732 | } |
---|
2733 | |
---|
2734 | void convert(bool&) const |
---|
2735 | { |
---|
2736 | throw BadCastException(); |
---|
2737 | } |
---|
2738 | |
---|
2739 | void convert(float&) const |
---|
2740 | { |
---|
2741 | throw BadCastException(); |
---|
2742 | } |
---|
2743 | |
---|
2744 | void convert(double&) const |
---|
2745 | { |
---|
2746 | throw BadCastException(); |
---|
2747 | } |
---|
2748 | |
---|
2749 | void convert(char&) const |
---|
2750 | { |
---|
2751 | throw BadCastException(); |
---|
2752 | } |
---|
2753 | |
---|
2754 | void convert(std::string& val) const |
---|
2755 | { |
---|
2756 | val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT); |
---|
2757 | } |
---|
2758 | |
---|
2759 | void convert(DateTime& val) const |
---|
2760 | { |
---|
2761 | val = _val; |
---|
2762 | } |
---|
2763 | |
---|
2764 | void convert(LocalDateTime& ldt) const |
---|
2765 | { |
---|
2766 | ldt = _val.timestamp(); |
---|
2767 | } |
---|
2768 | |
---|
2769 | void convert(Timestamp& ts) const |
---|
2770 | { |
---|
2771 | ts = _val.timestamp(); |
---|
2772 | } |
---|
2773 | |
---|
2774 | DynamicAnyHolder* clone() const |
---|
2775 | { |
---|
2776 | return new DynamicAnyHolderImpl(_val); |
---|
2777 | } |
---|
2778 | |
---|
2779 | const DateTime& value() const |
---|
2780 | { |
---|
2781 | return _val; |
---|
2782 | } |
---|
2783 | |
---|
2784 | bool isArray() const |
---|
2785 | { |
---|
2786 | return false; |
---|
2787 | } |
---|
2788 | |
---|
2789 | bool isInteger() const |
---|
2790 | { |
---|
2791 | return false; |
---|
2792 | } |
---|
2793 | |
---|
2794 | bool isSigned() const |
---|
2795 | { |
---|
2796 | return false; |
---|
2797 | } |
---|
2798 | |
---|
2799 | bool isNumeric() const |
---|
2800 | { |
---|
2801 | return false; |
---|
2802 | } |
---|
2803 | |
---|
2804 | bool isString() const |
---|
2805 | { |
---|
2806 | return false; |
---|
2807 | } |
---|
2808 | |
---|
2809 | private: |
---|
2810 | DateTime _val; |
---|
2811 | }; |
---|
2812 | |
---|
2813 | |
---|
2814 | template <> |
---|
2815 | class DynamicAnyHolderImpl<LocalDateTime>: public DynamicAnyHolder |
---|
2816 | { |
---|
2817 | public: |
---|
2818 | DynamicAnyHolderImpl(const LocalDateTime& val): _val(val) |
---|
2819 | { |
---|
2820 | } |
---|
2821 | |
---|
2822 | ~DynamicAnyHolderImpl() |
---|
2823 | { |
---|
2824 | } |
---|
2825 | |
---|
2826 | const std::type_info& type() const |
---|
2827 | { |
---|
2828 | return typeid(LocalDateTime); |
---|
2829 | } |
---|
2830 | |
---|
2831 | void convert(Int8&) const |
---|
2832 | { |
---|
2833 | throw BadCastException(); |
---|
2834 | } |
---|
2835 | |
---|
2836 | void convert(Int16&) const |
---|
2837 | { |
---|
2838 | throw BadCastException(); |
---|
2839 | } |
---|
2840 | |
---|
2841 | void convert(Int32&) const |
---|
2842 | { |
---|
2843 | throw BadCastException(); |
---|
2844 | } |
---|
2845 | |
---|
2846 | void convert(Int64& val) const |
---|
2847 | { |
---|
2848 | val = _val.timestamp().epochMicroseconds(); |
---|
2849 | } |
---|
2850 | |
---|
2851 | void convert(UInt8&) const |
---|
2852 | { |
---|
2853 | throw BadCastException(); |
---|
2854 | } |
---|
2855 | |
---|
2856 | void convert(UInt16&) const |
---|
2857 | { |
---|
2858 | throw BadCastException(); |
---|
2859 | } |
---|
2860 | |
---|
2861 | void convert(UInt32&) const |
---|
2862 | { |
---|
2863 | throw BadCastException(); |
---|
2864 | } |
---|
2865 | |
---|
2866 | void convert(UInt64& val) const |
---|
2867 | { |
---|
2868 | val = _val.timestamp().epochMicroseconds(); |
---|
2869 | } |
---|
2870 | |
---|
2871 | void convert(bool&) const |
---|
2872 | { |
---|
2873 | throw BadCastException(); |
---|
2874 | } |
---|
2875 | |
---|
2876 | void convert(float&) const |
---|
2877 | { |
---|
2878 | throw BadCastException(); |
---|
2879 | } |
---|
2880 | |
---|
2881 | void convert(double&) const |
---|
2882 | { |
---|
2883 | throw BadCastException(); |
---|
2884 | } |
---|
2885 | |
---|
2886 | void convert(char&) const |
---|
2887 | { |
---|
2888 | throw BadCastException(); |
---|
2889 | } |
---|
2890 | |
---|
2891 | void convert(std::string& val) const |
---|
2892 | { |
---|
2893 | val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT); |
---|
2894 | } |
---|
2895 | |
---|
2896 | void convert(DateTime& val) const |
---|
2897 | { |
---|
2898 | val = _val.timestamp(); |
---|
2899 | } |
---|
2900 | |
---|
2901 | void convert(LocalDateTime& ldt) const |
---|
2902 | { |
---|
2903 | ldt = _val; |
---|
2904 | } |
---|
2905 | |
---|
2906 | void convert(Timestamp& ts) const |
---|
2907 | { |
---|
2908 | ts = _val.timestamp(); |
---|
2909 | } |
---|
2910 | |
---|
2911 | DynamicAnyHolder* clone() const |
---|
2912 | { |
---|
2913 | return new DynamicAnyHolderImpl(_val); |
---|
2914 | } |
---|
2915 | |
---|
2916 | const LocalDateTime& value() const |
---|
2917 | { |
---|
2918 | return _val; |
---|
2919 | } |
---|
2920 | |
---|
2921 | bool isArray() const |
---|
2922 | { |
---|
2923 | return false; |
---|
2924 | } |
---|
2925 | |
---|
2926 | bool isInteger() const |
---|
2927 | { |
---|
2928 | return false; |
---|
2929 | } |
---|
2930 | |
---|
2931 | bool isSigned() const |
---|
2932 | { |
---|
2933 | return false; |
---|
2934 | } |
---|
2935 | |
---|
2936 | bool isNumeric() const |
---|
2937 | { |
---|
2938 | return false; |
---|
2939 | } |
---|
2940 | |
---|
2941 | bool isString() const |
---|
2942 | { |
---|
2943 | return false; |
---|
2944 | } |
---|
2945 | |
---|
2946 | private: |
---|
2947 | LocalDateTime _val; |
---|
2948 | }; |
---|
2949 | |
---|
2950 | |
---|
2951 | template <> |
---|
2952 | class DynamicAnyHolderImpl<Timestamp>: public DynamicAnyHolder |
---|
2953 | { |
---|
2954 | public: |
---|
2955 | DynamicAnyHolderImpl(const Timestamp& val): _val(val) |
---|
2956 | { |
---|
2957 | } |
---|
2958 | |
---|
2959 | ~DynamicAnyHolderImpl() |
---|
2960 | { |
---|
2961 | } |
---|
2962 | |
---|
2963 | const std::type_info& type() const |
---|
2964 | { |
---|
2965 | return typeid(Timestamp); |
---|
2966 | } |
---|
2967 | |
---|
2968 | void convert(Int8&) const |
---|
2969 | { |
---|
2970 | throw BadCastException(); |
---|
2971 | } |
---|
2972 | |
---|
2973 | void convert(Int16&) const |
---|
2974 | { |
---|
2975 | throw BadCastException(); |
---|
2976 | } |
---|
2977 | |
---|
2978 | void convert(Int32&) const |
---|
2979 | { |
---|
2980 | throw BadCastException(); |
---|
2981 | } |
---|
2982 | |
---|
2983 | void convert(Int64& val) const |
---|
2984 | { |
---|
2985 | val = _val.epochMicroseconds(); |
---|
2986 | } |
---|
2987 | |
---|
2988 | void convert(UInt8&) const |
---|
2989 | { |
---|
2990 | throw BadCastException(); |
---|
2991 | } |
---|
2992 | |
---|
2993 | void convert(UInt16&) const |
---|
2994 | { |
---|
2995 | throw BadCastException(); |
---|
2996 | } |
---|
2997 | |
---|
2998 | void convert(UInt32&) const |
---|
2999 | { |
---|
3000 | throw BadCastException(); |
---|
3001 | } |
---|
3002 | |
---|
3003 | void convert(UInt64& val) const |
---|
3004 | { |
---|
3005 | val = _val.epochMicroseconds(); |
---|
3006 | } |
---|
3007 | |
---|
3008 | void convert(bool&) const |
---|
3009 | { |
---|
3010 | throw BadCastException(); |
---|
3011 | } |
---|
3012 | |
---|
3013 | void convert(float&) const |
---|
3014 | { |
---|
3015 | throw BadCastException(); |
---|
3016 | } |
---|
3017 | |
---|
3018 | void convert(double&) const |
---|
3019 | { |
---|
3020 | throw BadCastException(); |
---|
3021 | } |
---|
3022 | |
---|
3023 | void convert(char&) const |
---|
3024 | { |
---|
3025 | throw BadCastException(); |
---|
3026 | } |
---|
3027 | |
---|
3028 | void convert(std::string& val) const |
---|
3029 | { |
---|
3030 | val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT); |
---|
3031 | } |
---|
3032 | |
---|
3033 | void convert(DateTime& val) const |
---|
3034 | { |
---|
3035 | val = _val; |
---|
3036 | } |
---|
3037 | |
---|
3038 | void convert(LocalDateTime& ldt) const |
---|
3039 | { |
---|
3040 | ldt = _val; |
---|
3041 | } |
---|
3042 | |
---|
3043 | void convert(Timestamp& ts) const |
---|
3044 | { |
---|
3045 | ts = _val; |
---|
3046 | } |
---|
3047 | |
---|
3048 | DynamicAnyHolder* clone() const |
---|
3049 | { |
---|
3050 | return new DynamicAnyHolderImpl(_val); |
---|
3051 | } |
---|
3052 | |
---|
3053 | const Timestamp& value() const |
---|
3054 | { |
---|
3055 | return _val; |
---|
3056 | } |
---|
3057 | |
---|
3058 | bool isArray() const |
---|
3059 | { |
---|
3060 | return false; |
---|
3061 | } |
---|
3062 | |
---|
3063 | bool isInteger() const |
---|
3064 | { |
---|
3065 | return false; |
---|
3066 | } |
---|
3067 | |
---|
3068 | bool isSigned() const |
---|
3069 | { |
---|
3070 | return false; |
---|
3071 | } |
---|
3072 | |
---|
3073 | bool isNumeric() const |
---|
3074 | { |
---|
3075 | return false; |
---|
3076 | } |
---|
3077 | |
---|
3078 | bool isString() const |
---|
3079 | { |
---|
3080 | return false; |
---|
3081 | } |
---|
3082 | |
---|
3083 | private: |
---|
3084 | Timestamp _val; |
---|
3085 | }; |
---|
3086 | |
---|
3087 | |
---|
3088 | } // namespace Poco |
---|
3089 | |
---|
3090 | |
---|
3091 | #endif // Foundation_DynamicAnyHolder_INCLUDED |
---|