diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/poco/Foundation/include/Poco/Dynamic | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/poco/Foundation/include/Poco/Dynamic')
5 files changed, 7552 insertions, 7552 deletions
diff --git a/contrib/libs/poco/Foundation/include/Poco/Dynamic/Pair.h b/contrib/libs/poco/Foundation/include/Poco/Dynamic/Pair.h index 18b283a501..c64eececeb 100644 --- a/contrib/libs/poco/Foundation/include/Poco/Dynamic/Pair.h +++ b/contrib/libs/poco/Foundation/include/Poco/Dynamic/Pair.h @@ -1,412 +1,412 @@ -// -// Pair.h -// -// Library: Foundation -// Package: Dynamic -// Module: Pair -// -// Definition of the Pair class. -// -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Foundation_Pair_INCLUDED -#define Foundation_Pair_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/Dynamic/Var.h" -#include "Poco/Dynamic/VarHolder.h" -#include <utility> - - -namespace Poco { -namespace Dynamic { - - -template <typename K> -class Pair - /// Pair allows to define a pair of values. -{ -public: - typedef typename std::pair<K, Var> Data; - - Pair(): _data() - /// Creates an empty Pair - { - } - - Pair(const Pair& other): _data(other._data) - /// Creates the Pair from another pair. - { - } - - Pair(const Data& val): _data(val) - /// Creates the Pair from the given value. - { - } - - template <typename T> - Pair(const std::pair<K, T>& val): _data(std::make_pair(val.first, val.second)) - /// Creates Pair form standard pair. - { - } - - template <typename T> - Pair(const K& first, const T& second): _data(std::make_pair(first, second)) - /// Creates pair from two values. - { - } - - virtual ~Pair() - /// Destroys the Pair. - { - } - - Pair& swap(Pair& other) - /// Swaps the content of the two Pairs. - { - std::swap(_data, other._data); - return *this; - } - - Pair& operator = (const Pair& other) - /// Copy constructs Pair from another pair. - { - Pair(other).swap(*this); - return *this; - } - - inline const K& first() const - /// Returns the first member of the pair. - { - return _data.first; - } - - inline const Var& second() const - /// Returns the second member of the pair. - { - return _data.second; - } - - std::string toString() - { - std::string str; - Var(*this).convert<std::string>(str); - return str; - } - -private: - Data _data; -}; - - -template <> -class VarHolderImpl<Pair<std::string> >: public VarHolder -{ -public: - VarHolderImpl(const Pair<std::string>& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Pair<std::string>); - } - - void convert(Int8& val) const - { - throw BadCastException("Cannot cast Pair type to Int8"); - } - - void convert(Int16& val) const - { - throw BadCastException("Cannot cast Pair type to Int16"); - } - - void convert(Int32& val) const - { - throw BadCastException("Cannot cast Pair type to Int32"); - } - - void convert(Int64& val) const - { - throw BadCastException("Cannot cast Pair type to Int64"); - } - - void convert(UInt8& val) const - { - throw BadCastException("Cannot cast Pair type to UInt8"); - } - - void convert(UInt16& val) const - { - throw BadCastException("Cannot cast Pair type to UInt16"); - } - - void convert(UInt32& val) const - { - throw BadCastException("Cannot cast Pair type to UInt32"); - } - - void convert(UInt64& val) const - { - throw BadCastException("Cannot cast Pair type to UInt64"); - } - - void convert(bool& val) const - { - throw BadCastException("Cannot cast Pair type to bool"); - } - - void convert(float& val) const - { - throw BadCastException("Cannot cast Pair type to float"); - } - - void convert(double& val) const - { - throw BadCastException("Cannot cast Pair type to double"); - } - - void convert(char& val) const - { - throw BadCastException("Cannot cast Pair type to char"); - } - - void convert(std::string& val) const - { - // Serialize in JSON format: equals an object - // JSON format definition: { string ':' value } string:value pair n-times, sep. by ',' - val.append("{ "); - Var key(_val.first()); - Impl::appendJSONKey(val, key); - val.append(" : "); - Impl::appendJSONValue(val, _val.second()); - val.append(" }"); - } - - void convert(Poco::DateTime&) const - { - throw BadCastException("Pair -> Poco::DateTime"); - } - - void convert(Poco::LocalDateTime&) const - { - throw BadCastException("Pair -> Poco::LocalDateTime"); - } - - void convert(Poco::Timestamp&) const - { - throw BadCastException("Pair -> Poco::Timestamp"); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const Pair<std::string>& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - Pair<std::string> _val; -}; - - -template <> -class VarHolderImpl<Pair<int> >: public VarHolder -{ -public: - VarHolderImpl(const Pair<int>& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Pair<int>); - } - - void convert(Int8& val) const - { - throw BadCastException("Cannot cast Pair type to Int8"); - } - - void convert(Int16& val) const - { - throw BadCastException("Cannot cast Pair type to Int16"); - } - - void convert(Int32& val) const - { - throw BadCastException("Cannot cast Pair type to Int32"); - } - - void convert(Int64& val) const - { - throw BadCastException("Cannot cast Pair type to Int64"); - } - - void convert(UInt8& val) const - { - throw BadCastException("Cannot cast Pair type to UInt8"); - } - - void convert(UInt16& val) const - { - throw BadCastException("Cannot cast Pair type to UInt16"); - } - - void convert(UInt32& val) const - { - throw BadCastException("Cannot cast Pair type to UInt32"); - } - - void convert(UInt64& val) const - { - throw BadCastException("Cannot cast Pair type to UInt64"); - } - - void convert(bool& val) const - { - throw BadCastException("Cannot cast Pair type to bool"); - } - - void convert(float& val) const - { - throw BadCastException("Cannot cast Pair type to float"); - } - - void convert(double& val) const - { - throw BadCastException("Cannot cast Pair type to double"); - } - - void convert(char& val) const - { - throw BadCastException("Cannot cast Pair type to char"); - } - - void convert(std::string& val) const - { - // Serialize in JSON format: equals an object - // JSON format definition: { string ':' value } string:value pair n-times, sep. by ',' - val.append("{ "); - Var key(_val.first()); - Impl::appendJSONKey(val, key); - val.append(" : "); - Impl::appendJSONValue(val, _val.second()); - val.append(" }"); - } - - void convert(Poco::DateTime&) const - { - throw BadCastException("Pair -> Poco::DateTime"); - } - - void convert(Poco::LocalDateTime&) const - { - throw BadCastException("Pair -> Poco::LocalDateTime"); - } - - void convert(Poco::Timestamp&) const - { - throw BadCastException("Pair -> Poco::Timestamp"); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const Pair<int>& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - Pair<int> _val; -}; - - -} // namespace Dynamic - - -} // namespace Poco - - -#endif // Foundation_Pair_INCLUDED +// +// Pair.h +// +// Library: Foundation +// Package: Dynamic +// Module: Pair +// +// Definition of the Pair class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#ifndef Foundation_Pair_INCLUDED +#define Foundation_Pair_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Dynamic/Var.h" +#include "Poco/Dynamic/VarHolder.h" +#include <utility> + + +namespace Poco { +namespace Dynamic { + + +template <typename K> +class Pair + /// Pair allows to define a pair of values. +{ +public: + typedef typename std::pair<K, Var> Data; + + Pair(): _data() + /// Creates an empty Pair + { + } + + Pair(const Pair& other): _data(other._data) + /// Creates the Pair from another pair. + { + } + + Pair(const Data& val): _data(val) + /// Creates the Pair from the given value. + { + } + + template <typename T> + Pair(const std::pair<K, T>& val): _data(std::make_pair(val.first, val.second)) + /// Creates Pair form standard pair. + { + } + + template <typename T> + Pair(const K& first, const T& second): _data(std::make_pair(first, second)) + /// Creates pair from two values. + { + } + + virtual ~Pair() + /// Destroys the Pair. + { + } + + Pair& swap(Pair& other) + /// Swaps the content of the two Pairs. + { + std::swap(_data, other._data); + return *this; + } + + Pair& operator = (const Pair& other) + /// Copy constructs Pair from another pair. + { + Pair(other).swap(*this); + return *this; + } + + inline const K& first() const + /// Returns the first member of the pair. + { + return _data.first; + } + + inline const Var& second() const + /// Returns the second member of the pair. + { + return _data.second; + } + + std::string toString() + { + std::string str; + Var(*this).convert<std::string>(str); + return str; + } + +private: + Data _data; +}; + + +template <> +class VarHolderImpl<Pair<std::string> >: public VarHolder +{ +public: + VarHolderImpl(const Pair<std::string>& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Pair<std::string>); + } + + void convert(Int8& val) const + { + throw BadCastException("Cannot cast Pair type to Int8"); + } + + void convert(Int16& val) const + { + throw BadCastException("Cannot cast Pair type to Int16"); + } + + void convert(Int32& val) const + { + throw BadCastException("Cannot cast Pair type to Int32"); + } + + void convert(Int64& val) const + { + throw BadCastException("Cannot cast Pair type to Int64"); + } + + void convert(UInt8& val) const + { + throw BadCastException("Cannot cast Pair type to UInt8"); + } + + void convert(UInt16& val) const + { + throw BadCastException("Cannot cast Pair type to UInt16"); + } + + void convert(UInt32& val) const + { + throw BadCastException("Cannot cast Pair type to UInt32"); + } + + void convert(UInt64& val) const + { + throw BadCastException("Cannot cast Pair type to UInt64"); + } + + void convert(bool& val) const + { + throw BadCastException("Cannot cast Pair type to bool"); + } + + void convert(float& val) const + { + throw BadCastException("Cannot cast Pair type to float"); + } + + void convert(double& val) const + { + throw BadCastException("Cannot cast Pair type to double"); + } + + void convert(char& val) const + { + throw BadCastException("Cannot cast Pair type to char"); + } + + void convert(std::string& val) const + { + // Serialize in JSON format: equals an object + // JSON format definition: { string ':' value } string:value pair n-times, sep. by ',' + val.append("{ "); + Var key(_val.first()); + Impl::appendJSONKey(val, key); + val.append(" : "); + Impl::appendJSONValue(val, _val.second()); + val.append(" }"); + } + + void convert(Poco::DateTime&) const + { + throw BadCastException("Pair -> Poco::DateTime"); + } + + void convert(Poco::LocalDateTime&) const + { + throw BadCastException("Pair -> Poco::LocalDateTime"); + } + + void convert(Poco::Timestamp&) const + { + throw BadCastException("Pair -> Poco::Timestamp"); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const Pair<std::string>& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + Pair<std::string> _val; +}; + + +template <> +class VarHolderImpl<Pair<int> >: public VarHolder +{ +public: + VarHolderImpl(const Pair<int>& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Pair<int>); + } + + void convert(Int8& val) const + { + throw BadCastException("Cannot cast Pair type to Int8"); + } + + void convert(Int16& val) const + { + throw BadCastException("Cannot cast Pair type to Int16"); + } + + void convert(Int32& val) const + { + throw BadCastException("Cannot cast Pair type to Int32"); + } + + void convert(Int64& val) const + { + throw BadCastException("Cannot cast Pair type to Int64"); + } + + void convert(UInt8& val) const + { + throw BadCastException("Cannot cast Pair type to UInt8"); + } + + void convert(UInt16& val) const + { + throw BadCastException("Cannot cast Pair type to UInt16"); + } + + void convert(UInt32& val) const + { + throw BadCastException("Cannot cast Pair type to UInt32"); + } + + void convert(UInt64& val) const + { + throw BadCastException("Cannot cast Pair type to UInt64"); + } + + void convert(bool& val) const + { + throw BadCastException("Cannot cast Pair type to bool"); + } + + void convert(float& val) const + { + throw BadCastException("Cannot cast Pair type to float"); + } + + void convert(double& val) const + { + throw BadCastException("Cannot cast Pair type to double"); + } + + void convert(char& val) const + { + throw BadCastException("Cannot cast Pair type to char"); + } + + void convert(std::string& val) const + { + // Serialize in JSON format: equals an object + // JSON format definition: { string ':' value } string:value pair n-times, sep. by ',' + val.append("{ "); + Var key(_val.first()); + Impl::appendJSONKey(val, key); + val.append(" : "); + Impl::appendJSONValue(val, _val.second()); + val.append(" }"); + } + + void convert(Poco::DateTime&) const + { + throw BadCastException("Pair -> Poco::DateTime"); + } + + void convert(Poco::LocalDateTime&) const + { + throw BadCastException("Pair -> Poco::LocalDateTime"); + } + + void convert(Poco::Timestamp&) const + { + throw BadCastException("Pair -> Poco::Timestamp"); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const Pair<int>& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + Pair<int> _val; +}; + + +} // namespace Dynamic + + +} // namespace Poco + + +#endif // Foundation_Pair_INCLUDED diff --git a/contrib/libs/poco/Foundation/include/Poco/Dynamic/Struct.h b/contrib/libs/poco/Foundation/include/Poco/Dynamic/Struct.h index 6cd3e3cd65..fc9d57d55e 100644 --- a/contrib/libs/poco/Foundation/include/Poco/Dynamic/Struct.h +++ b/contrib/libs/poco/Foundation/include/Poco/Dynamic/Struct.h @@ -1,567 +1,567 @@ -// -// Struct.h -// -// Library: Foundation -// Package: Dynamic -// Module: Struct -// -// Definition of the Struct class. -// -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Foundation_Struct_INCLUDED -#define Foundation_Struct_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/Dynamic/Var.h" -#include "Poco/Dynamic/VarHolder.h" -#include "Poco/SharedPtr.h" -#include <map> -#include <set> - - -namespace Poco { -namespace Dynamic { - - -template <typename K> -class Struct - /// Struct allows to define a named collection of Var objects. -{ -public: - typedef typename std::map<K, Var> Data; - typedef typename std::set<K> NameSet; - typedef typename Data::iterator Iterator; - typedef typename Data::const_iterator ConstIterator; - typedef typename Struct<K>::Data::value_type ValueType; - typedef typename Struct<K>::Data::size_type SizeType; - typedef typename std::pair<typename Struct<K>::Iterator, bool> InsRetVal; - typedef typename Poco::SharedPtr<Struct<K> > Ptr; - - Struct(): _data() - /// Creates an empty Struct - { - } - - Struct(const Data& val): _data(val) - /// Creates the Struct from the given value. - { - } - - template <typename T> - Struct(const std::map<K, T>& val) - { - typedef typename std::map<K, T>::const_iterator MapConstIterator; - - MapConstIterator it = val.begin(); - MapConstIterator itEnd = val.end(); - for (; it != itEnd; ++it) _data.insert(ValueType(it->first, Var(it->second))); - } - - virtual ~Struct() - /// Destroys the Struct. - { - } - - inline Var& operator [] (const K& name) - /// Returns the Var with the given name, creates an entry if not found. - { - return _data[name]; - } - - const Var& operator [] (const K& name) const - /// Returns the Var with the given name, throws a - /// NotFoundException if the data member is not found. - { - ConstIterator it = find(name); - if (it == end()) throw NotFoundException(name); - return it->second; - } - - inline bool contains(const K& name) const - /// Returns true if the Struct contains a member with the given name - { - return find(name) != end(); - } - - inline Iterator find(const K& name) - /// Returns an iterator, pointing to the <name,Var> pair containing - /// the element, or it returns end() if the member was not found - { - return _data.find(name); - } - - inline ConstIterator find(const K& name) const - /// Returns a const iterator, pointing to the <name,Var> pair containing - /// the element, or it returns end() if the member was not found - { - return _data.find(name); - } - - inline Iterator end() - /// Returns the end iterator for the Struct - { - return _data.end(); - } - - inline ConstIterator end() const - /// Returns the end const iterator for the Struct - { - return _data.end(); - } - - inline Iterator begin() - /// Returns the begin iterator for the Struct - { - return _data.begin(); - } - - inline ConstIterator begin() const - /// Returns the begin const iterator for the Struct - { - return _data.begin(); - } - - template <typename T> - inline InsRetVal insert(const K& key, const T& value) - /// Inserts a <name, Var> pair into the Struct, - /// returns a pair containing the iterator and a boolean which - /// indicates success or not (is true, when insert succeeded, false, - /// when already another element was present, in this case Iterator - /// points to that other element) - { - // fix: SunPro C++ is silly ... - ValueType valueType(key, value); - return insert(valueType); - } - - inline InsRetVal insert(const ValueType& aPair) - /// Inserts a <name, Var> pair into the Struct, - /// returns a pair containing the iterator and a boolean which - /// indicates success or not (is true, when insert succeeded, false, - /// when already another element was present, in this case Iterator - /// points to that other element) - { - return _data.insert(aPair); - } - - inline SizeType erase(const K& key) - /// Erases the element if found, returns number of elements deleted - { - return _data.erase(key); - } - - inline void erase(Iterator& it) - /// Erases the element at the given position - { - _data.erase(it); - } - - inline bool empty() const - /// Returns true if the Struct doesn't contain any members - { - return _data.empty(); - } - - inline void clear() - /// Clears the Struct contents - { - _data.clear(); - } - - SizeType size() const - /// Returns the number of members the Struct contains - { - return _data.size(); - } - - inline NameSet members() const - /// Returns a sorted collection containing all member names - { - NameSet keys; - ConstIterator it = begin(); - ConstIterator itEnd = end(); - for (; it != itEnd; ++it) keys.insert(it->first); - return keys; - } - - std::string toString() - { - std::string str; - Var(*this).convert<std::string>(str); - return str; - } - -private: - Data _data; -}; - - -template <> -class VarHolderImpl<Struct<std::string> >: public VarHolder -{ -public: - VarHolderImpl(const Struct<std::string>& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Struct<std::string>); - } - - void convert(Int8&) const - { - throw BadCastException("Cannot cast Struct type to Int8"); - } - - void convert(Int16&) const - { - throw BadCastException("Cannot cast Struct type to Int16"); - } - - void convert(Int32&) const - { - throw BadCastException("Cannot cast Struct type to Int32"); - } - - void convert(Int64&) const - { - throw BadCastException("Cannot cast Struct type to Int64"); - } - - void convert(UInt8&) const - { - throw BadCastException("Cannot cast Struct type to UInt8"); - } - - void convert(UInt16&) const - { - throw BadCastException("Cannot cast Struct type to UInt16"); - } - - void convert(UInt32&) const - { - throw BadCastException("Cannot cast Struct type to UInt32"); - } - - void convert(UInt64&) const - { - throw BadCastException("Cannot cast Struct type to UInt64"); - } - - void convert(bool&) const - { - throw BadCastException("Cannot cast Struct type to bool"); - } - - void convert(float&) const - { - throw BadCastException("Cannot cast Struct type to float"); - } - - void convert(double&) const - { - throw BadCastException("Cannot cast Struct type to double"); - } - - void convert(char&) const - { - throw BadCastException("Cannot cast Struct type to char"); - } - - void convert(std::string& val) const - { - val.append("{ "); - Struct<std::string>::ConstIterator it = _val.begin(); - Struct<std::string>::ConstIterator itEnd = _val.end(); - if (!_val.empty()) - { - Var key(it->first); - Impl::appendJSONKey(val, key); - val.append(" : "); - Impl::appendJSONValue(val, it->second); - ++it; - } - for (; it != itEnd; ++it) - { - val.append(", "); - Var key(it->first); - Impl::appendJSONKey(val, key); - val.append(" : "); - Impl::appendJSONValue(val, it->second); - } - val.append(" }"); - } - - void convert(Poco::DateTime&) const - { - throw BadCastException("Struct -> Poco::DateTime"); - } - - void convert(Poco::LocalDateTime&) const - { - throw BadCastException("Struct -> Poco::LocalDateTime"); - } - - void convert(Poco::Timestamp&) const - { - throw BadCastException("Struct -> Poco::Timestamp"); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const Struct<std::string>& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return true; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isString() const - { - return false; - } - - std::size_t size() const - { - return _val.size(); - } - - Var& operator [] (const std::string& name) - { - return _val[name]; - } - - const Var& operator [] (const std::string& name) const - { - return _val[name]; - } - -private: - Struct<std::string> _val; -}; - - -template <> -class VarHolderImpl<Struct<int> >: public VarHolder -{ -public: - VarHolderImpl(const Struct<int>& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Struct<int>); - } - - void convert(Int8&) const - { - throw BadCastException("Cannot cast Struct type to Int8"); - } - - void convert(Int16&) const - { - throw BadCastException("Cannot cast Struct type to Int16"); - } - - void convert(Int32&) const - { - throw BadCastException("Cannot cast Struct type to Int32"); - } - - void convert(Int64&) const - { - throw BadCastException("Cannot cast Struct type to Int64"); - } - - void convert(UInt8&) const - { - throw BadCastException("Cannot cast Struct type to UInt8"); - } - - void convert(UInt16&) const - { - throw BadCastException("Cannot cast Struct type to UInt16"); - } - - void convert(UInt32&) const - { - throw BadCastException("Cannot cast Struct type to UInt32"); - } - - void convert(UInt64&) const - { - throw BadCastException("Cannot cast Struct type to UInt64"); - } - - void convert(bool&) const - { - throw BadCastException("Cannot cast Struct type to bool"); - } - - void convert(float&) const - { - throw BadCastException("Cannot cast Struct type to float"); - } - - void convert(double&) const - { - throw BadCastException("Cannot cast Struct type to double"); - } - - void convert(char&) const - { - throw BadCastException("Cannot cast Struct type to char"); - } - - void convert(std::string& val) const - { - val.append("{ "); - Struct<int>::ConstIterator it = _val.begin(); - Struct<int>::ConstIterator itEnd = _val.end(); - if (!_val.empty()) - { - Var key(it->first); - Impl::appendJSONKey(val, key); - val.append(" : "); - Impl::appendJSONValue(val, it->second); - ++it; - } - for (; it != itEnd; ++it) - { - val.append(", "); - Var key(it->first); - Impl::appendJSONKey(val, key); - val.append(" : "); - Impl::appendJSONValue(val, it->second); - } - val.append(" }"); - } - - void convert(Poco::DateTime&) const - { - throw BadCastException("Struct -> Poco::DateTime"); - } - - void convert(Poco::LocalDateTime&) const - { - throw BadCastException("Struct -> Poco::LocalDateTime"); - } - - void convert(Poco::Timestamp&) const - { - throw BadCastException("Struct -> Poco::Timestamp"); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const Struct<int>& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return true; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isString() const - { - return false; - } - - std::size_t size() const - { - return _val.size(); - } - - Var& operator [] (int name) - { - return _val[name]; - } - - const Var& operator [] (int name) const - { - return _val[name]; - } - -private: - Struct<int> _val; -}; - - -} // namespace Dynamic - - -typedef Dynamic::Struct<std::string> DynamicStruct; - - -} // namespace Poco - - -#endif // Foundation_Struct_INCLUDED +// +// Struct.h +// +// Library: Foundation +// Package: Dynamic +// Module: Struct +// +// Definition of the Struct class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#ifndef Foundation_Struct_INCLUDED +#define Foundation_Struct_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Dynamic/Var.h" +#include "Poco/Dynamic/VarHolder.h" +#include "Poco/SharedPtr.h" +#include <map> +#include <set> + + +namespace Poco { +namespace Dynamic { + + +template <typename K> +class Struct + /// Struct allows to define a named collection of Var objects. +{ +public: + typedef typename std::map<K, Var> Data; + typedef typename std::set<K> NameSet; + typedef typename Data::iterator Iterator; + typedef typename Data::const_iterator ConstIterator; + typedef typename Struct<K>::Data::value_type ValueType; + typedef typename Struct<K>::Data::size_type SizeType; + typedef typename std::pair<typename Struct<K>::Iterator, bool> InsRetVal; + typedef typename Poco::SharedPtr<Struct<K> > Ptr; + + Struct(): _data() + /// Creates an empty Struct + { + } + + Struct(const Data& val): _data(val) + /// Creates the Struct from the given value. + { + } + + template <typename T> + Struct(const std::map<K, T>& val) + { + typedef typename std::map<K, T>::const_iterator MapConstIterator; + + MapConstIterator it = val.begin(); + MapConstIterator itEnd = val.end(); + for (; it != itEnd; ++it) _data.insert(ValueType(it->first, Var(it->second))); + } + + virtual ~Struct() + /// Destroys the Struct. + { + } + + inline Var& operator [] (const K& name) + /// Returns the Var with the given name, creates an entry if not found. + { + return _data[name]; + } + + const Var& operator [] (const K& name) const + /// Returns the Var with the given name, throws a + /// NotFoundException if the data member is not found. + { + ConstIterator it = find(name); + if (it == end()) throw NotFoundException(name); + return it->second; + } + + inline bool contains(const K& name) const + /// Returns true if the Struct contains a member with the given name + { + return find(name) != end(); + } + + inline Iterator find(const K& name) + /// Returns an iterator, pointing to the <name,Var> pair containing + /// the element, or it returns end() if the member was not found + { + return _data.find(name); + } + + inline ConstIterator find(const K& name) const + /// Returns a const iterator, pointing to the <name,Var> pair containing + /// the element, or it returns end() if the member was not found + { + return _data.find(name); + } + + inline Iterator end() + /// Returns the end iterator for the Struct + { + return _data.end(); + } + + inline ConstIterator end() const + /// Returns the end const iterator for the Struct + { + return _data.end(); + } + + inline Iterator begin() + /// Returns the begin iterator for the Struct + { + return _data.begin(); + } + + inline ConstIterator begin() const + /// Returns the begin const iterator for the Struct + { + return _data.begin(); + } + + template <typename T> + inline InsRetVal insert(const K& key, const T& value) + /// Inserts a <name, Var> pair into the Struct, + /// returns a pair containing the iterator and a boolean which + /// indicates success or not (is true, when insert succeeded, false, + /// when already another element was present, in this case Iterator + /// points to that other element) + { + // fix: SunPro C++ is silly ... + ValueType valueType(key, value); + return insert(valueType); + } + + inline InsRetVal insert(const ValueType& aPair) + /// Inserts a <name, Var> pair into the Struct, + /// returns a pair containing the iterator and a boolean which + /// indicates success or not (is true, when insert succeeded, false, + /// when already another element was present, in this case Iterator + /// points to that other element) + { + return _data.insert(aPair); + } + + inline SizeType erase(const K& key) + /// Erases the element if found, returns number of elements deleted + { + return _data.erase(key); + } + + inline void erase(Iterator& it) + /// Erases the element at the given position + { + _data.erase(it); + } + + inline bool empty() const + /// Returns true if the Struct doesn't contain any members + { + return _data.empty(); + } + + inline void clear() + /// Clears the Struct contents + { + _data.clear(); + } + + SizeType size() const + /// Returns the number of members the Struct contains + { + return _data.size(); + } + + inline NameSet members() const + /// Returns a sorted collection containing all member names + { + NameSet keys; + ConstIterator it = begin(); + ConstIterator itEnd = end(); + for (; it != itEnd; ++it) keys.insert(it->first); + return keys; + } + + std::string toString() + { + std::string str; + Var(*this).convert<std::string>(str); + return str; + } + +private: + Data _data; +}; + + +template <> +class VarHolderImpl<Struct<std::string> >: public VarHolder +{ +public: + VarHolderImpl(const Struct<std::string>& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Struct<std::string>); + } + + void convert(Int8&) const + { + throw BadCastException("Cannot cast Struct type to Int8"); + } + + void convert(Int16&) const + { + throw BadCastException("Cannot cast Struct type to Int16"); + } + + void convert(Int32&) const + { + throw BadCastException("Cannot cast Struct type to Int32"); + } + + void convert(Int64&) const + { + throw BadCastException("Cannot cast Struct type to Int64"); + } + + void convert(UInt8&) const + { + throw BadCastException("Cannot cast Struct type to UInt8"); + } + + void convert(UInt16&) const + { + throw BadCastException("Cannot cast Struct type to UInt16"); + } + + void convert(UInt32&) const + { + throw BadCastException("Cannot cast Struct type to UInt32"); + } + + void convert(UInt64&) const + { + throw BadCastException("Cannot cast Struct type to UInt64"); + } + + void convert(bool&) const + { + throw BadCastException("Cannot cast Struct type to bool"); + } + + void convert(float&) const + { + throw BadCastException("Cannot cast Struct type to float"); + } + + void convert(double&) const + { + throw BadCastException("Cannot cast Struct type to double"); + } + + void convert(char&) const + { + throw BadCastException("Cannot cast Struct type to char"); + } + + void convert(std::string& val) const + { + val.append("{ "); + Struct<std::string>::ConstIterator it = _val.begin(); + Struct<std::string>::ConstIterator itEnd = _val.end(); + if (!_val.empty()) + { + Var key(it->first); + Impl::appendJSONKey(val, key); + val.append(" : "); + Impl::appendJSONValue(val, it->second); + ++it; + } + for (; it != itEnd; ++it) + { + val.append(", "); + Var key(it->first); + Impl::appendJSONKey(val, key); + val.append(" : "); + Impl::appendJSONValue(val, it->second); + } + val.append(" }"); + } + + void convert(Poco::DateTime&) const + { + throw BadCastException("Struct -> Poco::DateTime"); + } + + void convert(Poco::LocalDateTime&) const + { + throw BadCastException("Struct -> Poco::LocalDateTime"); + } + + void convert(Poco::Timestamp&) const + { + throw BadCastException("Struct -> Poco::Timestamp"); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const Struct<std::string>& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return true; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isString() const + { + return false; + } + + std::size_t size() const + { + return _val.size(); + } + + Var& operator [] (const std::string& name) + { + return _val[name]; + } + + const Var& operator [] (const std::string& name) const + { + return _val[name]; + } + +private: + Struct<std::string> _val; +}; + + +template <> +class VarHolderImpl<Struct<int> >: public VarHolder +{ +public: + VarHolderImpl(const Struct<int>& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Struct<int>); + } + + void convert(Int8&) const + { + throw BadCastException("Cannot cast Struct type to Int8"); + } + + void convert(Int16&) const + { + throw BadCastException("Cannot cast Struct type to Int16"); + } + + void convert(Int32&) const + { + throw BadCastException("Cannot cast Struct type to Int32"); + } + + void convert(Int64&) const + { + throw BadCastException("Cannot cast Struct type to Int64"); + } + + void convert(UInt8&) const + { + throw BadCastException("Cannot cast Struct type to UInt8"); + } + + void convert(UInt16&) const + { + throw BadCastException("Cannot cast Struct type to UInt16"); + } + + void convert(UInt32&) const + { + throw BadCastException("Cannot cast Struct type to UInt32"); + } + + void convert(UInt64&) const + { + throw BadCastException("Cannot cast Struct type to UInt64"); + } + + void convert(bool&) const + { + throw BadCastException("Cannot cast Struct type to bool"); + } + + void convert(float&) const + { + throw BadCastException("Cannot cast Struct type to float"); + } + + void convert(double&) const + { + throw BadCastException("Cannot cast Struct type to double"); + } + + void convert(char&) const + { + throw BadCastException("Cannot cast Struct type to char"); + } + + void convert(std::string& val) const + { + val.append("{ "); + Struct<int>::ConstIterator it = _val.begin(); + Struct<int>::ConstIterator itEnd = _val.end(); + if (!_val.empty()) + { + Var key(it->first); + Impl::appendJSONKey(val, key); + val.append(" : "); + Impl::appendJSONValue(val, it->second); + ++it; + } + for (; it != itEnd; ++it) + { + val.append(", "); + Var key(it->first); + Impl::appendJSONKey(val, key); + val.append(" : "); + Impl::appendJSONValue(val, it->second); + } + val.append(" }"); + } + + void convert(Poco::DateTime&) const + { + throw BadCastException("Struct -> Poco::DateTime"); + } + + void convert(Poco::LocalDateTime&) const + { + throw BadCastException("Struct -> Poco::LocalDateTime"); + } + + void convert(Poco::Timestamp&) const + { + throw BadCastException("Struct -> Poco::Timestamp"); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const Struct<int>& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return true; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isString() const + { + return false; + } + + std::size_t size() const + { + return _val.size(); + } + + Var& operator [] (int name) + { + return _val[name]; + } + + const Var& operator [] (int name) const + { + return _val[name]; + } + +private: + Struct<int> _val; +}; + + +} // namespace Dynamic + + +typedef Dynamic::Struct<std::string> DynamicStruct; + + +} // namespace Poco + + +#endif // Foundation_Struct_INCLUDED diff --git a/contrib/libs/poco/Foundation/include/Poco/Dynamic/Var.h b/contrib/libs/poco/Foundation/include/Poco/Dynamic/Var.h index 674041c87b..bd06afe54b 100644 --- a/contrib/libs/poco/Foundation/include/Poco/Dynamic/Var.h +++ b/contrib/libs/poco/Foundation/include/Poco/Dynamic/Var.h @@ -1,2228 +1,2228 @@ -// -// Var.h -// -// Library: Foundation -// Package: Dynamic -// Module: Var -// -// Definition of the Var class. -// -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Foundation_Var_INCLUDED -#define Foundation_Var_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/Format.h" -#include "Poco/SharedPtr.h" -#include "Poco/Dynamic/VarHolder.h" -#include "Poco/Dynamic/VarIterator.h" -#include <typeinfo> - - -namespace Poco { -namespace Dynamic { - - -template <typename T> -class Struct; - - -class Foundation_API Var - /// Var allows to store data of different types and to convert between these types transparently. - /// Var puts forth the best effort to provide intuitive and reasonable conversion semantics and prevent - /// unexpected data loss, particularly when performing narrowing or signedness conversions of numeric data types. +// +// Var.h +// +// Library: Foundation +// Package: Dynamic +// Module: Var +// +// Definition of the Var class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#ifndef Foundation_Var_INCLUDED +#define Foundation_Var_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/Format.h" +#include "Poco/SharedPtr.h" +#include "Poco/Dynamic/VarHolder.h" +#include "Poco/Dynamic/VarIterator.h" +#include <typeinfo> + + +namespace Poco { +namespace Dynamic { + + +template <typename T> +class Struct; + + +class Foundation_API Var + /// Var allows to store data of different types and to convert between these types transparently. + /// Var puts forth the best effort to provide intuitive and reasonable conversion semantics and prevent + /// unexpected data loss, particularly when performing narrowing or signedness conversions of numeric data types. + /// + /// An attempt to convert or extract from a non-initialized ("empty") Var variable shall result + /// in an exception being thrown. + /// + /// Loss of signedness is not allowed for numeric values. This means that if an attempt is made to convert + /// the internal value which is a negative signed integer to an unsigned integer type storage, a RangeException is thrown. + /// Overflow is not allowed, so if the internal value is a larger number than the target numeric type size can accommodate, + /// a RangeException is thrown. + /// + /// Precision loss, such as in conversion from floating-point types to integers or from double to float on platforms + /// where they differ in size (provided internal actual value fits in float min/max range), is allowed. /// - /// An attempt to convert or extract from a non-initialized ("empty") Var variable shall result - /// in an exception being thrown. + /// String truncation is allowed -- it is possible to convert between string and character when string length is + /// greater than 1. An empty string gets converted to the char '\0', a non-empty string is truncated to the first character. + /// + /// Boolean conversion is performed as follows: + /// + /// A string value "false" (not case sensitive), "0" or "" (empty string) can be converted to a boolean value false, + /// any other string not being false by the above criteria evaluates to true (e.g: "hi" -> true). + /// Integer 0 values are false, everything else is true. + /// Floating point values equal to the minimal FP representation on a given platform are false, everything else is true. + /// + /// Arithmetic operations with POD types as well as between Var's are supported, subject to following + /// limitations: /// - /// Loss of signedness is not allowed for numeric values. This means that if an attempt is made to convert - /// the internal value which is a negative signed integer to an unsigned integer type storage, a RangeException is thrown. - /// Overflow is not allowed, so if the internal value is a larger number than the target numeric type size can accommodate, - /// a RangeException is thrown. + /// - for std::string and const char* values, only '+' and '+=' operations are supported /// - /// Precision loss, such as in conversion from floating-point types to integers or from double to float on platforms - /// where they differ in size (provided internal actual value fits in float min/max range), is allowed. - /// - /// String truncation is allowed -- it is possible to convert between string and character when string length is - /// greater than 1. An empty string gets converted to the char '\0', a non-empty string is truncated to the first character. + /// - for integral and floating point numeric values, following operations are supported: + /// '+', '+=', '-', '-=', '*', '*=' , '/' and '/=' + /// + /// - for integral values, following operations are supported: + /// prefix and postfix increment (++) and decrement (--) /// - /// Boolean conversion is performed as follows: + /// - for all other types, InvalidArgumentException is thrown upon attempt of an arithmetic operation /// - /// A string value "false" (not case sensitive), "0" or "" (empty string) can be converted to a boolean value false, - /// any other string not being false by the above criteria evaluates to true (e.g: "hi" -> true). - /// Integer 0 values are false, everything else is true. - /// Floating point values equal to the minimal FP representation on a given platform are false, everything else is true. - /// - /// Arithmetic operations with POD types as well as between Var's are supported, subject to following - /// limitations: - /// - /// - for std::string and const char* values, only '+' and '+=' operations are supported - /// - /// - for integral and floating point numeric values, following operations are supported: - /// '+', '+=', '-', '-=', '*', '*=' , '/' and '/=' - /// - /// - for integral values, following operations are supported: - /// prefix and postfix increment (++) and decrement (--) - /// - /// - for all other types, InvalidArgumentException is thrown upon attempt of an arithmetic operation - /// - /// A Var can be created from and converted to a value of any type for which a specialization of - /// VarHolderImpl is available. For supported types, see VarHolder documentation. -{ -public: - typedef SharedPtr<Var> Ptr; - typedef Poco::Dynamic::VarIterator Iterator; - typedef const VarIterator ConstIterator; - - Var(); - /// Creates an empty Var. - - template <typename T> - Var(const T& val) - /// Creates the Var from the given value. -#ifdef POCO_NO_SOO - : _pHolder(new VarHolderImpl<T>(val)) - { - } -#else - { - construct(val); - } -#endif - - Var(const char* pVal); - // Convenience constructor for const char* which gets mapped to a std::string internally, i.e. pVal is deep-copied. - - Var(const Var& other); - /// Copy constructor. - - ~Var(); - /// Destroys the Var. - - void swap(Var& other); - /// Swaps the content of the this Var with the other Var. - - ConstIterator begin() const; - /// Returns the const Var iterator. - - ConstIterator end() const; - /// Returns the const Var iterator. - - Iterator begin(); - /// Returns the Var iterator. - - Iterator end(); - /// Returns the Var iterator. - - template <typename T> - void convert(T& val) const - /// Invoke this method to perform a safe conversion. - /// - /// Example usage: - /// Var any("42"); - /// int i; - /// any.convert(i); - /// - /// Throws a RangeException if the value does not fit - /// into the result variable. - /// Throws a NotImplementedException if conversion is - /// not available for the given type. - /// Throws InvalidAccessException if Var is empty. - { - VarHolder* pHolder = content(); - - if (!pHolder) - throw InvalidAccessException("Can not convert empty value."); - - pHolder->convert(val); - } - - template <typename T> - T convert() const - /// Invoke this method to perform a safe conversion. - /// - /// Example usage: - /// Var any("42"); - /// int i = any.convert<int>(); - /// - /// Throws a RangeException if the value does not fit - /// into the result variable. - /// Throws a NotImplementedException if conversion is - /// not available for the given type. - /// Throws InvalidAccessException if Var is empty. - { - VarHolder* pHolder = content(); - - if (!pHolder) - throw InvalidAccessException("Can not convert empty value."); - - if (typeid(T) == pHolder->type()) return extract<T>(); - - T result; - pHolder->convert(result); - return result; - } - + /// A Var can be created from and converted to a value of any type for which a specialization of + /// VarHolderImpl is available. For supported types, see VarHolder documentation. +{ +public: + typedef SharedPtr<Var> Ptr; + typedef Poco::Dynamic::VarIterator Iterator; + typedef const VarIterator ConstIterator; + + Var(); + /// Creates an empty Var. + + template <typename T> + Var(const T& val) + /// Creates the Var from the given value. +#ifdef POCO_NO_SOO + : _pHolder(new VarHolderImpl<T>(val)) + { + } +#else + { + construct(val); + } +#endif + + Var(const char* pVal); + // Convenience constructor for const char* which gets mapped to a std::string internally, i.e. pVal is deep-copied. + + Var(const Var& other); + /// Copy constructor. + + ~Var(); + /// Destroys the Var. + + void swap(Var& other); + /// Swaps the content of the this Var with the other Var. + + ConstIterator begin() const; + /// Returns the const Var iterator. + + ConstIterator end() const; + /// Returns the const Var iterator. + + Iterator begin(); + /// Returns the Var iterator. + + Iterator end(); + /// Returns the Var iterator. + + template <typename T> + void convert(T& val) const + /// Invoke this method to perform a safe conversion. + /// + /// Example usage: + /// Var any("42"); + /// int i; + /// any.convert(i); + /// + /// Throws a RangeException if the value does not fit + /// into the result variable. + /// Throws a NotImplementedException if conversion is + /// not available for the given type. + /// Throws InvalidAccessException if Var is empty. + { + VarHolder* pHolder = content(); + + if (!pHolder) + throw InvalidAccessException("Can not convert empty value."); + + pHolder->convert(val); + } + + template <typename T> + T convert() const + /// Invoke this method to perform a safe conversion. + /// + /// Example usage: + /// Var any("42"); + /// int i = any.convert<int>(); + /// + /// Throws a RangeException if the value does not fit + /// into the result variable. + /// Throws a NotImplementedException if conversion is + /// not available for the given type. + /// Throws InvalidAccessException if Var is empty. + { + VarHolder* pHolder = content(); + + if (!pHolder) + throw InvalidAccessException("Can not convert empty value."); + + if (typeid(T) == pHolder->type()) return extract<T>(); + + T result; + pHolder->convert(result); + return result; + } + + template <typename T> + operator T () const + /// Safe conversion operator for implicit type + /// conversions. If the requested type T is same as the + /// type being held, the operation performed is direct + /// extraction, otherwise it is the conversion of the value + /// from type currently held to the one requested. + /// + /// Throws a RangeException if the value does not fit + /// into the result variable. + /// Throws a NotImplementedException if conversion is + /// not available for the given type. + /// Throws InvalidAccessException if Var is empty. + { + VarHolder* pHolder = content(); + + if (!pHolder) + throw InvalidAccessException("Can not convert empty value."); + + if (typeid(T) == pHolder->type()) + return extract<T>(); + else + { + T result; + pHolder->convert(result); + return result; + } + } + + template <typename T> + const T& extract() const + /// Returns a const reference to the actual value. + /// + /// Must be instantiated with the exact type of + /// the stored value, otherwise a BadCastException + /// is thrown. + /// Throws InvalidAccessException if Var is empty. + { + VarHolder* pHolder = content(); + + if (pHolder && pHolder->type() == typeid(T)) + { + VarHolderImpl<T>* pHolderImpl = static_cast<VarHolderImpl<T>*>(pHolder); + return pHolderImpl->value(); + } + else if (!pHolder) + throw InvalidAccessException("Can not extract empty value."); + else + throw BadCastException(format("Can not convert %s to %s.", + std::string(pHolder->type().name()), + std::string(typeid(T).name()))); + } + + template <typename T> + Var& operator = (const T& other) + /// Assignment operator for assigning POD to Var + { +#ifdef POCO_NO_SOO + Var tmp(other); + swap(tmp); +#else + construct(other); +#endif + return *this; + } + + bool operator ! () const; + /// Logical NOT operator. + + Var& operator = (const Var& other); + /// Assignment operator specialization for Var + + template <typename T> + const Var operator + (const T& other) const + /// Addition operator for adding POD to Var + { + return convert<T>() + other; + } + + const Var operator + (const Var& other) const; + /// Addition operator specialization for Var + + const Var operator + (const char* other) const; + /// Addition operator specialization for adding const char* to Var + + Var& operator ++ (); + /// Pre-increment operator + + const Var operator ++ (int); + /// Post-increment operator + + Var& operator -- (); + /// Pre-decrement operator + + const Var operator -- (int); + /// Post-decrement operator + + template <typename T> + Var& operator += (const T& other) + /// Addition assignment operator for addition/assignment of POD to Var. + { + return *this = convert<T>() + other; + } + + Var& operator += (const Var& other); + /// Addition assignment operator overload for Var + + Var& operator += (const char* other); + /// Addition assignment operator overload for const char* + + template <typename T> + const Var operator - (const T& other) const + /// Subtraction operator for subtracting POD from Var + { + return convert<T>() - other; + } + + const Var operator - (const Var& other) const; + /// Subtraction operator overload for Var + template <typename T> - operator T () const - /// Safe conversion operator for implicit type - /// conversions. If the requested type T is same as the - /// type being held, the operation performed is direct - /// extraction, otherwise it is the conversion of the value - /// from type currently held to the one requested. - /// - /// Throws a RangeException if the value does not fit - /// into the result variable. - /// Throws a NotImplementedException if conversion is - /// not available for the given type. - /// Throws InvalidAccessException if Var is empty. - { - VarHolder* pHolder = content(); - - if (!pHolder) - throw InvalidAccessException("Can not convert empty value."); - - if (typeid(T) == pHolder->type()) - return extract<T>(); - else - { - T result; - pHolder->convert(result); - return result; - } - } - + Var& operator -= (const T& other) + /// Subtraction assignment operator + { + return *this = convert<T>() - other; + } + + Var& operator -= (const Var& other); + /// Subtraction assignment operator overload for Var + template <typename T> - const T& extract() const - /// Returns a const reference to the actual value. - /// - /// Must be instantiated with the exact type of - /// the stored value, otherwise a BadCastException - /// is thrown. - /// Throws InvalidAccessException if Var is empty. - { - VarHolder* pHolder = content(); - - if (pHolder && pHolder->type() == typeid(T)) - { - VarHolderImpl<T>* pHolderImpl = static_cast<VarHolderImpl<T>*>(pHolder); - return pHolderImpl->value(); - } - else if (!pHolder) - throw InvalidAccessException("Can not extract empty value."); - else - throw BadCastException(format("Can not convert %s to %s.", - std::string(pHolder->type().name()), - std::string(typeid(T).name()))); - } - - template <typename T> - Var& operator = (const T& other) - /// Assignment operator for assigning POD to Var - { -#ifdef POCO_NO_SOO - Var tmp(other); - swap(tmp); -#else - construct(other); -#endif - return *this; - } - - bool operator ! () const; - /// Logical NOT operator. - - Var& operator = (const Var& other); - /// Assignment operator specialization for Var - + const Var operator * (const T& other) const + /// Multiplication operator for multiplying Var with POD + { + return convert<T>() * other; + } + + const Var operator * (const Var& other) const; + /// Multiplication operator overload for Var + template <typename T> - const Var operator + (const T& other) const - /// Addition operator for adding POD to Var - { - return convert<T>() + other; - } - - const Var operator + (const Var& other) const; - /// Addition operator specialization for Var - - const Var operator + (const char* other) const; - /// Addition operator specialization for adding const char* to Var - - Var& operator ++ (); - /// Pre-increment operator - - const Var operator ++ (int); - /// Post-increment operator - - Var& operator -- (); - /// Pre-decrement operator - - const Var operator -- (int); - /// Post-decrement operator - - template <typename T> - Var& operator += (const T& other) - /// Addition assignment operator for addition/assignment of POD to Var. - { - return *this = convert<T>() + other; - } - - Var& operator += (const Var& other); - /// Addition assignment operator overload for Var - - Var& operator += (const char* other); - /// Addition assignment operator overload for const char* - - template <typename T> - const Var operator - (const T& other) const - /// Subtraction operator for subtracting POD from Var - { - return convert<T>() - other; - } - - const Var operator - (const Var& other) const; - /// Subtraction operator overload for Var - - template <typename T> - Var& operator -= (const T& other) - /// Subtraction assignment operator - { - return *this = convert<T>() - other; - } - - Var& operator -= (const Var& other); - /// Subtraction assignment operator overload for Var - - template <typename T> - const Var operator * (const T& other) const - /// Multiplication operator for multiplying Var with POD - { - return convert<T>() * other; - } - - const Var operator * (const Var& other) const; - /// Multiplication operator overload for Var - - template <typename T> - Var& operator *= (const T& other) - /// Multiplication assignment operator - { - return *this = convert<T>() * other; - } - - Var& operator *= (const Var& other); - /// Multiplication assignment operator overload for Var - - template <typename T> - const Var operator / (const T& other) const - /// Division operator for dividing Var with POD - { - return convert<T>() / other; - } - - const Var operator / (const Var& other) const; - /// Division operator overload for Var - - template <typename T> - Var& operator /= (const T& other) - /// Division assignment operator - { - return *this = convert<T>() / other; - } - - Var& operator /= (const Var& other); - /// Division assignment operator specialization for Var - - template <typename T> - bool operator == (const T& other) const - /// Equality operator - { - if (isEmpty()) return false; - return convert<T>() == other; - } - - bool operator == (const char* other) const; - /// Equality operator overload for const char* - - bool operator == (const Var& other) const; - /// Equality operator overload for Var - - template <typename T> - bool operator != (const T& other) const - /// Inequality operator - { - if (isEmpty()) return true; - return convert<T>() != other; - } - - bool operator != (const Var& other) const; - /// Inequality operator overload for Var - - bool operator != (const char* other) const; - /// Inequality operator overload for const char* - - template <typename T> - bool operator < (const T& other) const - /// Less than operator - { - if (isEmpty()) return false; - return convert<T>() < other; - } - - bool operator < (const Var& other) const; - /// Less than operator overload for Var - - template <typename T> - bool operator <= (const T& other) const - /// Less than or equal operator - { - if (isEmpty()) return false; - return convert<T>() <= other; - } - - bool operator <= (const Var& other) const; - /// Less than or equal operator overload for Var - - template <typename T> - bool operator > (const T& other) const - /// Greater than operator - { - if (isEmpty()) return false; - return convert<T>() > other; - } - - bool operator > (const Var& other) const; - /// Greater than operator overload for Var - - template <typename T> - bool operator >= (const T& other) const - /// Greater than or equal operator - { - if (isEmpty()) return false; - return convert<T>() >= other; - } - - bool operator >= (const Var& other) const; - /// Greater than or equal operator overload for Var - + Var& operator *= (const T& other) + /// Multiplication assignment operator + { + return *this = convert<T>() * other; + } + + Var& operator *= (const Var& other); + /// Multiplication assignment operator overload for Var + template <typename T> - bool operator || (const T& other) const - /// Logical OR operator - { - if (isEmpty()) return false; - return convert<bool>() || other; - } - - bool operator || (const Var& other) const; - /// Logical OR operator operator overload for Var - + const Var operator / (const T& other) const + /// Division operator for dividing Var with POD + { + return convert<T>() / other; + } + + const Var operator / (const Var& other) const; + /// Division operator overload for Var + template <typename T> - bool operator && (const T& other) const - /// Logical AND operator. - { - if (isEmpty()) return false; - return convert<bool>() && other; - } - - bool operator && (const Var& other) const; - /// Logical AND operator operator overload for Var. - - bool isArray() const; - /// Returns true if Var is an array. - - bool isVector() const; - /// Returns true if Var represents a vector. - - bool isList() const; - /// Returns true if Var represents a list. - - bool isDeque() const; - /// Returns true if Var represents a deque. - - bool isStruct() const; - /// Returns true if Var represents a struct. - - char& at(std::size_t n); - /// Returns character at position n. This function only works with - /// Var containing a std::string. - - + Var& operator /= (const T& other) + /// Division assignment operator + { + return *this = convert<T>() / other; + } + + Var& operator /= (const Var& other); + /// Division assignment operator specialization for Var + template <typename T> - Var& operator [] (const T& n) - { - return getAt(n); - } - + bool operator == (const T& other) const + /// Equality operator + { + if (isEmpty()) return false; + return convert<T>() == other; + } + + bool operator == (const char* other) const; + /// Equality operator overload for const char* + + bool operator == (const Var& other) const; + /// Equality operator overload for Var + template <typename T> - const Var& operator [] (const T& n) const - { - return const_cast<Var*>(this)->getAt(n); - } - - Var& operator [] (const std::string& name); - /// Index operator by name, only use on Vars where isStruct - /// returns true! In all other cases InvalidAccessException is thrown. - - const Var& operator [] (const std::string& name) const; - /// Index operator by name, only use on Vars where isStruct - /// returns true! In all other cases InvalidAccessException is thrown. - - const std::type_info& type() const; - /// Returns the type information of the stored content. - - //@ deprecated - void empty(); - /// Empties Var. - /// This function is deprecated and will be removed. - /// Please use clear(). - - void clear(); - /// Empties Var. - - bool isEmpty() const; - /// Returns true if empty. - - bool isInteger() const; - /// Returns true if stored value is integer. - - bool isSigned() const; - /// Returns true if stored value is signed. - - bool isNumeric() const; - /// Returns true if stored value is numeric. - /// Returns false for numeric strings (e.g. "123" is string, not number) - - bool isBoolean() const; - /// Returns true if stored value is boolean. - /// Returns false for boolean strings (e.g. "true" is string, not number) - - bool isString() const; - /// Returns true if stored value is std::string. - - bool isDate() const; - /// Returns true if stored value represents a date. - - bool isTime() const; - /// Returns true if stored value represents time or date/time. - - bool isDateTime() const; - /// Returns true if stored value represents a date/time. - - std::size_t size() const; - /// Returns the size of this Var. - /// This function returns 0 when Var is empty, 1 for POD or the size (i.e. length) - /// for held container. - - std::string toString() const - /// Returns the stored value as string. - { - VarHolder* pHolder = content(); - - if (!pHolder) - throw InvalidAccessException("Can not convert empty value."); - - if (typeid(std::string) == pHolder->type()) - return extract<std::string>(); - else - { - std::string result; - pHolder->convert(result); - return result; - } - } - - static Var parse(const std::string& val); - /// Parses the string which must be in JSON format - - static std::string toString(const Var& var); - /// Converts the Var to a string in JSON format. Note that toString(const Var&) will return - /// a different result than Var::convert<std::string>() and Var::toString()! - -private: - Var& getAt(std::size_t n); - Var& getAt(const std::string& n); - - static Var parse(const std::string& val, std::string::size_type& offset); - /// Parses the string which must be in JSON format - - static Var parseObject(const std::string& val, std::string::size_type& pos); - static Var parseArray(const std::string& val, std::string::size_type& pos); - static std::string parseString(const std::string& val, std::string::size_type& pos); - static std::string parseJSONString(const std::string& val, std::string::size_type& pos); - static void skipWhiteSpace(const std::string& val, std::string::size_type& pos); - + bool operator != (const T& other) const + /// Inequality operator + { + if (isEmpty()) return true; + return convert<T>() != other; + } + + bool operator != (const Var& other) const; + /// Inequality operator overload for Var + + bool operator != (const char* other) const; + /// Inequality operator overload for const char* + template <typename T> - T add(const Var& other) const - { - return convert<T>() + other.convert<T>(); - } - + bool operator < (const T& other) const + /// Less than operator + { + if (isEmpty()) return false; + return convert<T>() < other; + } + + bool operator < (const Var& other) const; + /// Less than operator overload for Var + template <typename T> - T subtract(const Var& other) const - { - return convert<T>() - other.convert<T>(); - } - + bool operator <= (const T& other) const + /// Less than or equal operator + { + if (isEmpty()) return false; + return convert<T>() <= other; + } + + bool operator <= (const Var& other) const; + /// Less than or equal operator overload for Var + template <typename T> - T multiply(const Var& other) const - { - return convert<T>() * other.convert<T>(); - } - + bool operator > (const T& other) const + /// Greater than operator + { + if (isEmpty()) return false; + return convert<T>() > other; + } + + bool operator > (const Var& other) const; + /// Greater than operator overload for Var + template <typename T> - T divide(const Var& other) const - { - return convert<T>() / other.convert<T>(); - } - - template <typename T, typename E> - VarHolderImpl<T>* holderImpl(const std::string errorMessage = "") const - { - VarHolder* pHolder = content(); - - if (pHolder && pHolder->type() == typeid(T)) - return static_cast<VarHolderImpl<T>*>(pHolder); - else if (!pHolder) - throw InvalidAccessException("Can not access empty value."); - else - throw E(errorMessage); - } - - Var& structIndexOperator(VarHolderImpl<Struct<int> >* pStr, int n) const; - -#ifdef POCO_NO_SOO - - VarHolder* content() const - { - return _pHolder; - } - - void destruct() - { - if (!isEmpty()) delete content(); - } - - VarHolder* _pHolder; - -#else - - VarHolder* content() const - { - return _placeholder.content(); - } - - template<typename ValueType> - void construct(const ValueType& value) - { - if (sizeof(VarHolderImpl<ValueType>) <= Placeholder<ValueType>::Size::value) - { - new (reinterpret_cast<VarHolder*>(_placeholder.holder)) VarHolderImpl<ValueType>(value); - _placeholder.setLocal(true); - } - else - { - _placeholder.pHolder = new VarHolderImpl<ValueType>(value); - _placeholder.setLocal(false); - } - } - - void construct(const char* value) - { - std::string val(value); - if (sizeof(VarHolderImpl<std::string>) <= Placeholder<std::string>::Size::value) - { - new (reinterpret_cast<VarHolder*>(_placeholder.holder)) VarHolderImpl<std::string>(val); - _placeholder.setLocal(true); - } - else - { - _placeholder.pHolder = new VarHolderImpl<std::string>(val); - _placeholder.setLocal(false); - } - } - - void construct(const Var& other) - { - if (!other.isEmpty()) - other.content()->clone(&_placeholder); - else - _placeholder.erase(); - } - - void destruct() - { - if (!isEmpty()) - { - if (_placeholder.isLocal()) - content()->~VarHolder(); - else - delete content(); - } - } - - Placeholder<VarHolder> _placeholder; - -#endif // POCO_NO_SOO -}; - - -/// -/// inlines -/// - - -/// -/// Var members -/// - -inline void Var::swap(Var& other) -{ -#ifdef POCO_NO_SOO - - std::swap(_pHolder, other._pHolder); - -#else - - if (this == &other) return; - - if (!_placeholder.isLocal() && !other._placeholder.isLocal()) - { - std::swap(_placeholder.pHolder, other._placeholder.pHolder); - } - else - { - Var tmp(*this); - try - { - if (_placeholder.isLocal()) destruct(); - construct(other); - other = tmp; - } - catch (...) - { - construct(tmp); - throw; - } - } - -#endif -} - - -inline const std::type_info& Var::type() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->type() : typeid(void); -} - - -inline Var::ConstIterator Var::begin() const -{ - if (isEmpty()) return ConstIterator(const_cast<Var*>(this), true); - - return ConstIterator(const_cast<Var*>(this), false); -} - -inline Var::ConstIterator Var::end() const -{ - return ConstIterator(const_cast<Var*>(this), true); -} - -inline Var::Iterator Var::begin() -{ - if (isEmpty()) return Iterator(const_cast<Var*>(this), true); - - return Iterator(const_cast<Var*>(this), false); -} - -inline Var::Iterator Var::end() -{ - return Iterator(this, true); -} - - -inline Var& Var::operator [] (const std::string& name) -{ - return getAt(name); -} - - -inline const Var& Var::operator [] (const std::string& name) const -{ - return const_cast<Var*>(this)->getAt(name); -} - - -inline const Var Var::operator + (const char* other) const -{ - return convert<std::string>() + other; -} - - -inline Var& Var::operator += (const char*other) -{ - return *this = convert<std::string>() + other; -} - - -inline bool Var::operator ! () const -{ - return !convert<bool>(); -} - - -inline bool Var::isEmpty() const -{ - return 0 == content(); -} - - -inline bool Var::isArray() const -{ - if (isEmpty() || - isString()) return false; - - VarHolder* pHolder = content(); - return pHolder ? pHolder->isArray() : false; -} - - -inline bool Var::isVector() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isVector() : false; -} - - -inline bool Var::isList() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isList() : false; -} - - -inline bool Var::isDeque() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isDeque() : false; -} - - -inline bool Var::isStruct() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isStruct() : false; -} - - -inline bool Var::isInteger() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isInteger() : false; -} - - -inline bool Var::isSigned() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isSigned() : false; -} - - -inline bool Var::isNumeric() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isNumeric() : false; -} - - -inline bool Var::isBoolean() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isBoolean() : false; -} - - -inline bool Var::isString() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isString() : false; -} - - -inline bool Var::isDate() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isDate() : false; -} - - -inline bool Var::isTime() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isTime() : false; -} - - -inline bool Var::isDateTime() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->isDateTime() : false; -} - - -inline std::size_t Var::size() const -{ - VarHolder* pHolder = content(); - return pHolder ? pHolder->size() : 0; -} - - -/// -/// Var non-member functions -/// - -inline const Var operator + (const char* other, const Var& da) - /// Addition operator for adding Var to const char* -{ - std::string tmp = other; - return tmp + da.convert<std::string>(); -} - - -inline char operator + (const char& other, const Var& da) - /// Addition operator for adding Var to char -{ - return other + da.convert<char>(); -} - - -inline char operator - (const char& other, const Var& da) - /// Subtraction operator for subtracting Var from char -{ - return other - da.convert<char>(); -} - - -inline char operator * (const char& other, const Var& da) - /// Multiplication operator for multiplying Var with char -{ - return other * da.convert<char>(); -} - - -inline char operator / (const char& other, const Var& da) - /// Division operator for dividing Var with char -{ - return other / da.convert<char>(); -} - - -inline char operator += (char& other, const Var& da) - /// Addition assignment operator for adding Var to char -{ - return other += da.convert<char>(); -} - - -inline char operator -= (char& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from char -{ - return other -= da.convert<char>(); -} - - -inline char operator *= (char& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with char -{ - return other *= da.convert<char>(); -} - - -inline char operator /= (char& other, const Var& da) - /// Division assignment operator for dividing Var with char -{ - return other /= da.convert<char>(); -} - - -inline bool operator == (const char& other, const Var& da) - /// Equality operator for comparing Var with char -{ - if (da.isEmpty()) return false; - return other == da.convert<char>(); -} - - -inline bool operator != (const char& other, const Var& da) - /// Inequality operator for comparing Var with char -{ - if (da.isEmpty()) return true; - return other != da.convert<char>(); -} - - -inline bool operator < (const char& other, const Var& da) - /// Less than operator for comparing Var with char -{ - if (da.isEmpty()) return false; - return other < da.convert<char>(); -} - - -inline bool operator <= (const char& other, const Var& da) - /// Less than or equal operator for comparing Var with char -{ - if (da.isEmpty()) return false; - return other <= da.convert<char>(); -} - - -inline bool operator > (const char& other, const Var& da) - /// Greater than operator for comparing Var with char -{ - if (da.isEmpty())return false; - return other > da.convert<char>(); -} - - -inline bool operator >= (const char& other, const Var& da) - /// Greater than or equal operator for comparing Var with char -{ - if (da.isEmpty())return false; - return other >= da.convert<char>(); -} - - -inline Poco::Int8 operator + (const Poco::Int8& other, const Var& da) - /// Addition operator for adding Var to Poco::Int8 -{ - return other + da.convert<Poco::Int8>(); -} - - -inline Poco::Int8 operator - (const Poco::Int8& other, const Var& da) - /// Subtraction operator for subtracting Var from Poco::Int8 -{ - return other - da.convert<Poco::Int8>(); -} - - -inline Poco::Int8 operator * (const Poco::Int8& other, const Var& da) - /// Multiplication operator for multiplying Var with Poco::Int8 -{ - return other * da.convert<Poco::Int8>(); -} - - -inline Poco::Int8 operator / (const Poco::Int8& other, const Var& da) - /// Division operator for dividing Var with Poco::Int8 -{ - return other / da.convert<Poco::Int8>(); -} - - -inline Poco::Int8 operator += (Poco::Int8& other, const Var& da) - /// Addition assignment operator for adding Var to Poco::Int8 -{ - return other += da.convert<Poco::Int8>(); -} - - -inline Poco::Int8 operator -= (Poco::Int8& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from Poco::Int8 -{ - return other -= da.convert<Poco::Int8>(); -} - - -inline Poco::Int8 operator *= (Poco::Int8& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with Poco::Int8 -{ - return other *= da.convert<Poco::Int8>(); -} - - -inline Poco::Int8 operator /= (Poco::Int8& other, const Var& da) - /// Division assignment operator for dividing Var with Poco::Int8 -{ - return other /= da.convert<Poco::Int8>(); -} - - -inline bool operator == (const Poco::Int8& other, const Var& da) - /// Equality operator for comparing Var with Poco::Int8 -{ - if (da.isEmpty()) return false; - return other == da.convert<Poco::Int8>(); -} - - -inline bool operator != (const Poco::Int8& other, const Var& da) - /// Inequality operator for comparing Var with Poco::Int8 -{ - if (da.isEmpty()) return true; - return other != da.convert<Poco::Int8>(); -} - - -inline bool operator < (const Poco::Int8& other, const Var& da) - /// Less than operator for comparing Var with Poco::Int8 -{ - if (da.isEmpty()) return false; - return other < da.convert<Poco::Int8>(); -} - - -inline bool operator <= (const Poco::Int8& other, const Var& da) - /// Less than or equal operator for comparing Var with Poco::Int8 -{ - if (da.isEmpty()) return false; - return other <= da.convert<Poco::Int8>(); -} - - -inline bool operator > (const Poco::Int8& other, const Var& da) - /// Greater than operator for comparing Var with Poco::Int8 -{ - if (da.isEmpty()) return false; - return other > da.convert<Poco::Int8>(); -} - - -inline bool operator >= (const Poco::Int8& other, const Var& da) - /// Greater than or equal operator for comparing Var with Poco::Int8 -{ - if (da.isEmpty()) return false; - return other >= da.convert<Poco::Int8>(); -} - - -inline Poco::UInt8 operator + (const Poco::UInt8& other, const Var& da) - /// Addition operator for adding Var to Poco::UInt8 -{ - return other + da.convert<Poco::UInt8>(); -} - - -inline Poco::UInt8 operator - (const Poco::UInt8& other, const Var& da) - /// Subtraction operator for subtracting Var from Poco::UInt8 -{ - return other - da.convert<Poco::UInt8>(); -} - - -inline Poco::UInt8 operator * (const Poco::UInt8& other, const Var& da) - /// Multiplication operator for multiplying Var with Poco::UInt8 -{ - return other * da.convert<Poco::UInt8>(); -} - - -inline Poco::UInt8 operator / (const Poco::UInt8& other, const Var& da) - /// Division operator for dividing Var with Poco::UInt8 -{ - return other / da.convert<Poco::UInt8>(); -} - - -inline Poco::UInt8 operator += (Poco::UInt8& other, const Var& da) - /// Addition assignment operator for adding Var to Poco::UInt8 -{ - return other += da.convert<Poco::UInt8>(); -} - - -inline Poco::UInt8 operator -= (Poco::UInt8& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from Poco::UInt8 -{ - return other -= da.convert<Poco::UInt8>(); -} - - -inline Poco::UInt8 operator *= (Poco::UInt8& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with Poco::UInt8 -{ - return other *= da.convert<Poco::UInt8>(); -} - - -inline Poco::UInt8 operator /= (Poco::UInt8& other, const Var& da) - /// Division assignment operator for dividing Var with Poco::UInt8 -{ - return other /= da.convert<Poco::UInt8>(); -} - - -inline bool operator == (const Poco::UInt8& other, const Var& da) - /// Equality operator for comparing Var with Poco::UInt8 -{ - if (da.isEmpty()) return false; - return other == da.convert<Poco::UInt8>(); -} - - -inline bool operator != (const Poco::UInt8& other, const Var& da) - /// Inequality operator for comparing Var with Poco::UInt8 -{ - if (da.isEmpty()) return true; - return other != da.convert<Poco::UInt8>(); -} - - -inline bool operator < (const Poco::UInt8& other, const Var& da) - /// Less than operator for comparing Var with Poco::UInt8 -{ - if (da.isEmpty()) return false; - return other < da.convert<Poco::UInt8>(); -} - - -inline bool operator <= (const Poco::UInt8& other, const Var& da) - /// Less than or equal operator for comparing Var with Poco::UInt8 -{ - if (da.isEmpty()) return false; - return other <= da.convert<Poco::UInt8>(); -} - - -inline bool operator > (const Poco::UInt8& other, const Var& da) - /// Greater than operator for comparing Var with Poco::UInt8 -{ - if (da.isEmpty()) return false; - return other > da.convert<Poco::UInt8>(); -} - - -inline bool operator >= (const Poco::UInt8& other, const Var& da) - /// Greater than or equal operator for comparing Var with Poco::UInt8 -{ - if (da.isEmpty()) return false; - return other >= da.convert<Poco::UInt8>(); -} - - -inline Poco::Int16 operator + (const Poco::Int16& other, const Var& da) - /// Addition operator for adding Var to Poco::Int16 -{ - return other + da.convert<Poco::Int16>(); -} - - -inline Poco::Int16 operator - (const Poco::Int16& other, const Var& da) - /// Subtraction operator for subtracting Var from Poco::Int16 -{ - return other - da.convert<Poco::Int16>(); -} - - -inline Poco::Int16 operator * (const Poco::Int16& other, const Var& da) - /// Multiplication operator for multiplying Var with Poco::Int16 -{ - return other * da.convert<Poco::Int16>(); -} - - -inline Poco::Int16 operator / (const Poco::Int16& other, const Var& da) - /// Division operator for dividing Var with Poco::Int16 -{ - return other / da.convert<Poco::Int16>(); -} - - -inline Poco::Int16 operator += (Poco::Int16& other, const Var& da) - /// Addition assignment operator for adding Var to Poco::Int16 -{ - return other += da.convert<Poco::Int16>(); -} - - -inline Poco::Int16 operator -= (Poco::Int16& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from Poco::Int16 -{ - return other -= da.convert<Poco::Int16>(); -} - - -inline Poco::Int16 operator *= (Poco::Int16& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with Poco::Int16 -{ - return other *= da.convert<Poco::Int16>(); -} - - -inline Poco::Int16 operator /= (Poco::Int16& other, const Var& da) - /// Division assignment operator for dividing Var with Poco::Int16 -{ - return other /= da.convert<Poco::Int16>(); -} - - -inline bool operator == (const Poco::Int16& other, const Var& da) - /// Equality operator for comparing Var with Poco::Int16 -{ - if (da.isEmpty()) return false; - return other == da.convert<Poco::Int16>(); -} - - -inline bool operator != (const Poco::Int16& other, const Var& da) - /// Inequality operator for comparing Var with Poco::Int16 -{ - if (da.isEmpty()) return true; - return other != da.convert<Poco::Int16>(); -} - - -inline bool operator < (const Poco::Int16& other, const Var& da) - /// Less than operator for comparing Var with Poco::Int16 -{ - if (da.isEmpty()) return false; - return other < da.convert<Poco::Int16>(); -} - - -inline bool operator <= (const Poco::Int16& other, const Var& da) - /// Less than or equal operator for comparing Var with Poco::Int16 -{ - if (da.isEmpty()) return false; - return other <= da.convert<Poco::Int16>(); -} - - -inline bool operator > (const Poco::Int16& other, const Var& da) - /// Greater than operator for comparing Var with Poco::Int16 -{ - if (da.isEmpty()) return false; - return other > da.convert<Poco::Int16>(); -} - - -inline bool operator >= (const Poco::Int16& other, const Var& da) - /// Greater than or equal operator for comparing Var with Poco::Int16 -{ - if (da.isEmpty()) return false; - return other >= da.convert<Poco::Int16>(); -} - - -inline Poco::UInt16 operator + (const Poco::UInt16& other, const Var& da) - /// Addition operator for adding Var to Poco::UInt16 -{ - return other + da.convert<Poco::UInt16>(); -} - - -inline Poco::UInt16 operator - (const Poco::UInt16& other, const Var& da) - /// Subtraction operator for subtracting Var from Poco::UInt16 -{ - return other - da.convert<Poco::UInt16>(); -} - - -inline Poco::UInt16 operator * (const Poco::UInt16& other, const Var& da) - /// Multiplication operator for multiplying Var with Poco::UInt16 -{ - return other * da.convert<Poco::UInt16>(); -} - - -inline Poco::UInt16 operator / (const Poco::UInt16& other, const Var& da) - /// Division operator for dividing Var with Poco::UInt16 -{ - return other / da.convert<Poco::UInt16>(); -} - - -inline Poco::UInt16 operator += (Poco::UInt16& other, const Var& da) - /// Addition assignment operator for adding Var to Poco::UInt16 -{ - return other += da.convert<Poco::UInt16>(); -} - - -inline Poco::UInt16 operator -= (Poco::UInt16& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from Poco::UInt16 -{ - return other -= da.convert<Poco::UInt16>(); -} - - -inline Poco::UInt16 operator *= (Poco::UInt16& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with Poco::UInt16 -{ - return other *= da.convert<Poco::UInt16>(); -} - - -inline Poco::UInt16 operator /= (Poco::UInt16& other, const Var& da) - /// Division assignment operator for dividing Var with Poco::UInt16 -{ - return other /= da.convert<Poco::UInt16>(); -} - - -inline bool operator == (const Poco::UInt16& other, const Var& da) - /// Equality operator for comparing Var with Poco::UInt16 -{ - if (da.isEmpty()) return false; - return other == da.convert<Poco::UInt16>(); -} - - -inline bool operator != (const Poco::UInt16& other, const Var& da) - /// Inequality operator for comparing Var with Poco::UInt16 -{ - if (da.isEmpty()) return true; - return other != da.convert<Poco::UInt16>(); -} - - -inline bool operator < (const Poco::UInt16& other, const Var& da) - /// Less than operator for comparing Var with Poco::UInt16 -{ - if (da.isEmpty()) return false; - return other < da.convert<Poco::UInt16>(); -} - - -inline bool operator <= (const Poco::UInt16& other, const Var& da) - /// Less than or equal operator for comparing Var with Poco::UInt16 -{ - if (da.isEmpty()) return false; - return other <= da.convert<Poco::UInt16>(); -} - - -inline bool operator > (const Poco::UInt16& other, const Var& da) - /// Greater than operator for comparing Var with Poco::UInt16 -{ - if (da.isEmpty()) return false; - return other > da.convert<Poco::UInt16>(); -} - - -inline bool operator >= (const Poco::UInt16& other, const Var& da) - /// Greater than or equal operator for comparing Var with Poco::UInt16 -{ - if (da.isEmpty()) return false; - return other >= da.convert<Poco::UInt16>(); -} - - -inline Poco::Int32 operator + (const Poco::Int32& other, const Var& da) - /// Addition operator for adding Var to Poco::Int32 -{ - return other + da.convert<Poco::Int32>(); -} - - -inline Poco::Int32 operator - (const Poco::Int32& other, const Var& da) - /// Subtraction operator for subtracting Var from Poco::Int32 -{ - return other - da.convert<Poco::Int32>(); -} - - -inline Poco::Int32 operator * (const Poco::Int32& other, const Var& da) - /// Multiplication operator for multiplying Var with Poco::Int32 -{ - return other * da.convert<Poco::Int32>(); -} - - -inline Poco::Int32 operator / (const Poco::Int32& other, const Var& da) - /// Division operator for dividing Var with Poco::Int32 -{ - return other / da.convert<Poco::Int32>(); -} - - -inline Poco::Int32 operator += (Poco::Int32& other, const Var& da) - /// Addition assignment operator for adding Var to Poco::Int32 -{ - return other += da.convert<Poco::Int32>(); -} - - -inline Poco::Int32 operator -= (Poco::Int32& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from Poco::Int32 -{ - return other -= da.convert<Poco::Int32>(); -} - - -inline Poco::Int32 operator *= (Poco::Int32& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with Poco::Int32 -{ - return other *= da.convert<Poco::Int32>(); -} - - -inline Poco::Int32 operator /= (Poco::Int32& other, const Var& da) - /// Division assignment operator for dividing Var with Poco::Int32 -{ - return other /= da.convert<Poco::Int32>(); -} - - -inline bool operator == (const Poco::Int32& other, const Var& da) - /// Equality operator for comparing Var with Poco::Int32 -{ - if (da.isEmpty()) return false; - return other == da.convert<Poco::Int32>(); -} - - -inline bool operator != (const Poco::Int32& other, const Var& da) - /// Inequality operator for comparing Var with Poco::Int32 -{ - if (da.isEmpty()) return true; - return other != da.convert<Poco::Int32>(); -} - - -inline bool operator < (const Poco::Int32& other, const Var& da) - /// Less than operator for comparing Var with Poco::Int32 -{ - if (da.isEmpty()) return false; - return other < da.convert<Poco::Int32>(); -} - - -inline bool operator <= (const Poco::Int32& other, const Var& da) - /// Less than or equal operator for comparing Var with Poco::Int32 -{ - if (da.isEmpty()) return false; - return other <= da.convert<Poco::Int32>(); -} - - -inline bool operator > (const Poco::Int32& other, const Var& da) - /// Greater than operator for comparing Var with Poco::Int32 -{ - if (da.isEmpty()) return false; - return other > da.convert<Poco::Int32>(); -} - - -inline bool operator >= (const Poco::Int32& other, const Var& da) - /// Greater than or equal operator for comparing Var with Poco::Int32 -{ - if (da.isEmpty()) return false; - return other >= da.convert<Poco::Int32>(); -} - - -inline Poco::UInt32 operator + (const Poco::UInt32& other, const Var& da) - /// Addition operator for adding Var to Poco::UInt32 -{ - return other + da.convert<Poco::UInt32>(); -} - - -inline Poco::UInt32 operator - (const Poco::UInt32& other, const Var& da) - /// Subtraction operator for subtracting Var from Poco::UInt32 -{ - return other - da.convert<Poco::UInt32>(); -} - - -inline Poco::UInt32 operator * (const Poco::UInt32& other, const Var& da) - /// Multiplication operator for multiplying Var with Poco::UInt32 -{ - return other * da.convert<Poco::UInt32>(); -} - - -inline Poco::UInt32 operator / (const Poco::UInt32& other, const Var& da) - /// Division operator for dividing Var with Poco::UInt32 -{ - return other / da.convert<Poco::UInt32>(); -} - - -inline Poco::UInt32 operator += (Poco::UInt32& other, const Var& da) - /// Addition assignment operator for adding Var to Poco::UInt32 -{ - return other += da.convert<Poco::UInt32>(); -} - - -inline Poco::UInt32 operator -= (Poco::UInt32& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from Poco::UInt32 -{ - return other -= da.convert<Poco::UInt32>(); -} - - -inline Poco::UInt32 operator *= (Poco::UInt32& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with Poco::UInt32 -{ - return other *= da.convert<Poco::UInt32>(); -} - - -inline Poco::UInt32 operator /= (Poco::UInt32& other, const Var& da) - /// Division assignment operator for dividing Var with Poco::UInt32 -{ - return other /= da.convert<Poco::UInt32>(); -} - - -inline bool operator == (const Poco::UInt32& other, const Var& da) - /// Equality operator for comparing Var with Poco::UInt32 -{ - if (da.isEmpty()) return false; - return other == da.convert<Poco::UInt32>(); -} - - -inline bool operator != (const Poco::UInt32& other, const Var& da) - /// Inequality operator for comparing Var with Poco::UInt32 -{ - if (da.isEmpty()) return true; - return other != da.convert<Poco::UInt32>(); -} - - -inline bool operator < (const Poco::UInt32& other, const Var& da) - /// Less than operator for comparing Var with Poco::UInt32 -{ - if (da.isEmpty()) return false; - return other < da.convert<Poco::UInt32>(); -} - - -inline bool operator <= (const Poco::UInt32& other, const Var& da) - /// Less than or equal operator for comparing Var with Poco::UInt32 -{ - if (da.isEmpty()) return false; - return other <= da.convert<Poco::UInt32>(); -} - - -inline bool operator > (const Poco::UInt32& other, const Var& da) - /// Greater than operator for comparing Var with Poco::UInt32 -{ - if (da.isEmpty()) return false; - return other > da.convert<Poco::UInt32>(); -} - - -inline bool operator >= (const Poco::UInt32& other, const Var& da) - /// Greater than or equal operator for comparing Var with Poco::UInt32 -{ - if (da.isEmpty()) return false; - return other >= da.convert<Poco::UInt32>(); -} - - -inline Poco::Int64 operator + (const Poco::Int64& other, const Var& da) - /// Addition operator for adding Var to Poco::Int64 -{ - return other + da.convert<Poco::Int64>(); -} - - -inline Poco::Int64 operator - (const Poco::Int64& other, const Var& da) - /// Subtraction operator for subtracting Var from Poco::Int64 -{ - return other - da.convert<Poco::Int64>(); -} - - -inline Poco::Int64 operator * (const Poco::Int64& other, const Var& da) - /// Multiplication operator for multiplying Var with Poco::Int64 -{ - return other * da.convert<Poco::Int64>(); -} - - -inline Poco::Int64 operator / (const Poco::Int64& other, const Var& da) - /// Division operator for dividing Var with Poco::Int64 -{ - return other / da.convert<Poco::Int64>(); -} - - -inline Poco::Int64 operator += (Poco::Int64& other, const Var& da) - /// Addition assignment operator for adding Var to Poco::Int64 -{ - return other += da.convert<Poco::Int64>(); -} - - -inline Poco::Int64 operator -= (Poco::Int64& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from Poco::Int64 -{ - return other -= da.convert<Poco::Int64>(); -} - - -inline Poco::Int64 operator *= (Poco::Int64& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with Poco::Int64 -{ - return other *= da.convert<Poco::Int64>(); -} - - -inline Poco::Int64 operator /= (Poco::Int64& other, const Var& da) - /// Division assignment operator for dividing Var with Poco::Int64 -{ - return other /= da.convert<Poco::Int64>(); -} - - -inline bool operator == (const Poco::Int64& other, const Var& da) - /// Equality operator for comparing Var with Poco::Int64 -{ - if (da.isEmpty()) return false; - return other == da.convert<Poco::Int64>(); -} - - -inline bool operator != (const Poco::Int64& other, const Var& da) - /// Inequality operator for comparing Var with Poco::Int64 -{ - if (da.isEmpty()) return true; - return other != da.convert<Poco::Int64>(); -} - - -inline bool operator < (const Poco::Int64& other, const Var& da) - /// Less than operator for comparing Var with Poco::Int64 -{ - if (da.isEmpty()) return false; - return other < da.convert<Poco::Int64>(); -} - - -inline bool operator <= (const Poco::Int64& other, const Var& da) - /// Less than or equal operator for comparing Var with Poco::Int64 -{ - if (da.isEmpty()) return false; - return other <= da.convert<Poco::Int64>(); -} - - -inline bool operator > (const Poco::Int64& other, const Var& da) - /// Greater than operator for comparing Var with Poco::Int64 -{ - if (da.isEmpty()) return false; - return other > da.convert<Poco::Int64>(); -} - - -inline bool operator >= (const Poco::Int64& other, const Var& da) - /// Greater than or equal operator for comparing Var with Poco::Int64 -{ - if (da.isEmpty()) return false; - return other >= da.convert<Poco::Int64>(); -} - - -inline Poco::UInt64 operator + (const Poco::UInt64& other, const Var& da) - /// Addition operator for adding Var to Poco::UInt64 -{ - return other + da.convert<Poco::UInt64>(); -} - - -inline Poco::UInt64 operator - (const Poco::UInt64& other, const Var& da) - /// Subtraction operator for subtracting Var from Poco::UInt64 -{ - return other - da.convert<Poco::UInt64>(); -} - - -inline Poco::UInt64 operator * (const Poco::UInt64& other, const Var& da) - /// Multiplication operator for multiplying Var with Poco::UInt64 -{ - return other * da.convert<Poco::UInt64>(); -} - - -inline Poco::UInt64 operator / (const Poco::UInt64& other, const Var& da) - /// Division operator for dividing Var with Poco::UInt64 -{ - return other / da.convert<Poco::UInt64>(); -} - - -inline Poco::UInt64 operator += (Poco::UInt64& other, const Var& da) - /// Addition assignment operator for adding Var to Poco::UInt64 -{ - return other += da.convert<Poco::UInt64>(); -} - - -inline Poco::UInt64 operator -= (Poco::UInt64& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from Poco::UInt64 -{ - return other -= da.convert<Poco::UInt64>(); -} - - -inline Poco::UInt64 operator *= (Poco::UInt64& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with Poco::UInt64 -{ - return other *= da.convert<Poco::UInt64>(); -} - - -inline Poco::UInt64 operator /= (Poco::UInt64& other, const Var& da) - /// Division assignment operator for dividing Var with Poco::UInt64 -{ - return other /= da.convert<Poco::UInt64>(); -} - - -inline bool operator == (const Poco::UInt64& other, const Var& da) - /// Equality operator for comparing Var with Poco::UInt64 -{ - if (da.isEmpty()) return false; - return other == da.convert<Poco::UInt64>(); -} - - -inline bool operator != (const Poco::UInt64& other, const Var& da) - /// Inequality operator for comparing Var with Poco::UInt64 -{ - if (da.isEmpty()) return true; - return other != da.convert<Poco::UInt64>(); -} - - -inline bool operator < (const Poco::UInt64& other, const Var& da) - /// Less than operator for comparing Var with Poco::UInt64 -{ - if (da.isEmpty()) return false; - return other < da.convert<Poco::UInt64>(); -} - - -inline bool operator <= (const Poco::UInt64& other, const Var& da) - /// Less than or equal operator for comparing Var with Poco::UInt64 -{ - if (da.isEmpty()) return false; - return other <= da.convert<Poco::UInt64>(); -} - - -inline bool operator > (const Poco::UInt64& other, const Var& da) - /// Greater than operator for comparing Var with Poco::UInt64 -{ - if (da.isEmpty()) return false; - return other > da.convert<Poco::UInt64>(); -} - - -inline bool operator >= (const Poco::UInt64& other, const Var& da) - /// Greater than or equal operator for comparing Var with Poco::UInt64 -{ - if (da.isEmpty()) return false; - return other >= da.convert<Poco::UInt64>(); -} - - -inline float operator + (const float& other, const Var& da) - /// Addition operator for adding Var to float -{ - return other + da.convert<float>(); -} - - -inline float operator - (const float& other, const Var& da) - /// Subtraction operator for subtracting Var from float -{ - return other - da.convert<float>(); -} - - -inline float operator * (const float& other, const Var& da) - /// Multiplication operator for multiplying Var with float -{ - return other * da.convert<float>(); -} - - -inline float operator / (const float& other, const Var& da) - /// Division operator for dividing Var with float -{ - return other / da.convert<float>(); -} - - -inline float operator += (float& other, const Var& da) - /// Addition assignment operator for adding Var to float -{ - return other += da.convert<float>(); -} - - -inline float operator -= (float& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from float -{ - return other -= da.convert<float>(); -} - - -inline float operator *= (float& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with float -{ - return other *= da.convert<float>(); -} - - -inline float operator /= (float& other, const Var& da) - /// Division assignment operator for dividing Var with float -{ - return other /= da.convert<float>(); -} - - -inline bool operator == (const float& other, const Var& da) - /// Equality operator for comparing Var with float -{ - if (da.isEmpty()) return false; - return other == da.convert<float>(); -} - - -inline bool operator != (const float& other, const Var& da) - /// Inequality operator for comparing Var with float -{ - if (da.isEmpty()) return true; - return other != da.convert<float>(); -} - - -inline bool operator < (const float& other, const Var& da) - /// Less than operator for comparing Var with float -{ - if (da.isEmpty()) return false; - return other < da.convert<float>(); -} - - -inline bool operator <= (const float& other, const Var& da) - /// Less than or equal operator for comparing Var with float -{ - if (da.isEmpty()) return false; - return other <= da.convert<float>(); -} - - -inline bool operator > (const float& other, const Var& da) - /// Greater than operator for comparing Var with float -{ - if (da.isEmpty()) return false; - return other > da.convert<float>(); -} - - -inline bool operator >= (const float& other, const Var& da) - /// Greater than or equal operator for comparing Var with float -{ - if (da.isEmpty()) return false; - return other >= da.convert<float>(); -} - - -inline double operator + (const double& other, const Var& da) - /// Addition operator for adding Var to double -{ - return other + da.convert<double>(); -} - - -inline double operator - (const double& other, const Var& da) - /// Subtraction operator for subtracting Var from double -{ - return other - da.convert<double>(); -} - - -inline double operator * (const double& other, const Var& da) - /// Multiplication operator for multiplying Var with double -{ - return other * da.convert<double>(); -} - - -inline double operator / (const double& other, const Var& da) - /// Division operator for dividing Var with double -{ - return other / da.convert<double>(); -} - - -inline double operator += (double& other, const Var& da) - /// Addition assignment operator for adding Var to double -{ - return other += da.convert<double>(); -} - - -inline double operator -= (double& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from double -{ - return other -= da.convert<double>(); -} - - -inline double operator *= (double& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with double -{ - return other *= da.convert<double>(); -} - - -inline double operator /= (double& other, const Var& da) - /// Division assignment operator for dividing Var with double -{ - return other /= da.convert<double>(); -} - - -inline bool operator == (const double& other, const Var& da) - /// Equality operator for comparing Var with double -{ - if (da.isEmpty()) return false; - return other == da.convert<double>(); -} - - -inline bool operator != (const double& other, const Var& da) - /// Inequality operator for comparing Var with double -{ - if (da.isEmpty()) return true; - return other != da.convert<double>(); -} - - -inline bool operator < (const double& other, const Var& da) - /// Less than operator for comparing Var with double -{ - if (da.isEmpty()) return false; - return other < da.convert<double>(); -} - - -inline bool operator <= (const double& other, const Var& da) - /// Less than or equal operator for comparing Var with double -{ - if (da.isEmpty()) return false; - return other <= da.convert<double>(); -} - - -inline bool operator > (const double& other, const Var& da) - /// Greater than operator for comparing Var with double -{ - if (da.isEmpty()) return false; - return other > da.convert<double>(); -} - - -inline bool operator >= (const double& other, const Var& da) - /// Greater than or equal operator for comparing Var with double -{ - if (da.isEmpty()) return false; - return other >= da.convert<double>(); -} - - -inline bool operator == (const bool& other, const Var& da) - /// Equality operator for comparing Var with bool -{ - if (da.isEmpty()) return false; - return other == da.convert<bool>(); -} - - -inline bool operator != (const bool& other, const Var& da) - /// Inequality operator for comparing Var with bool -{ - if (da.isEmpty()) return true; - return other != da.convert<bool>(); -} - - -inline bool operator == (const std::string& other, const Var& da) - /// Equality operator for comparing Var with std::string -{ - if (da.isEmpty()) return false; - return other == da.convert<std::string>(); -} - - -inline bool operator != (const std::string& other, const Var& da) - /// Inequality operator for comparing Var with std::string -{ - if (da.isEmpty()) return true; - return other != da.convert<std::string>(); -} - - -inline bool operator == (const UTF16String& other, const Var& da) - /// Equality operator for comparing Var with UTF16String -{ - if (da.isEmpty()) return false; - return other == da.convert<UTF16String>(); -} - - -inline bool operator != (const UTF16String& other, const Var& da) - /// Inequality operator for comparing Var with UTF16String -{ - if (da.isEmpty()) return true; - return other != da.convert<UTF16String>(); -} - - -inline bool operator == (const char* other, const Var& da) - /// Equality operator for comparing Var with const char* -{ - if (da.isEmpty()) return false; - return da.convert<std::string>() == other; -} - - -inline bool operator != (const char* other, const Var& da) - /// Inequality operator for comparing Var with const char* -{ - if (da.isEmpty()) return true; - return da.convert<std::string>() != other; -} - - -#ifndef POCO_LONG_IS_64_BIT - - -inline long operator + (const long& other, const Var& da) - /// Addition operator for adding Var to long -{ - return other + da.convert<long>(); -} - - -inline long operator - (const long& other, const Var& da) - /// Subtraction operator for subtracting Var from long -{ - return other - da.convert<long>(); -} - - -inline long operator * (const long& other, const Var& da) - /// Multiplication operator for multiplying Var with long -{ - return other * da.convert<long>(); -} - - -inline long operator / (const long& other, const Var& da) - /// Division operator for dividing Var with long -{ - return other / da.convert<long>(); -} - - -inline long operator += (long& other, const Var& da) - /// Addition assignment operator for adding Var to long -{ - return other += da.convert<long>(); -} - - -inline long operator -= (long& other, const Var& da) - /// Subtraction assignment operator for subtracting Var from long -{ - return other -= da.convert<long>(); -} - - -inline long operator *= (long& other, const Var& da) - /// Multiplication assignment operator for multiplying Var with long -{ - return other *= da.convert<long>(); -} - - -inline long operator /= (long& other, const Var& da) - /// Division assignment operator for dividing Var with long -{ - return other /= da.convert<long>(); -} - - -inline bool operator == (const long& other, const Var& da) - /// Equality operator for comparing Var with long -{ - if (da.isEmpty()) return false; - return other == da.convert<long>(); -} - - -inline bool operator != (const long& other, const Var& da) - /// Inequality operator for comparing Var with long -{ - if (da.isEmpty()) return true; - return other != da.convert<long>(); -} - - -inline bool operator < (const long& other, const Var& da) - /// Less than operator for comparing Var with long -{ - if (da.isEmpty()) return false; - return other < da.convert<long>(); -} - - -inline bool operator <= (const long& other, const Var& da) - /// Less than or equal operator for comparing Var with long -{ - if (da.isEmpty()) return false; - return other <= da.convert<long>(); -} - - -inline bool operator > (const long& other, const Var& da) - /// Greater than operator for comparing Var with long -{ - if (da.isEmpty()) return false; - return other > da.convert<long>(); -} - - -inline bool operator >= (const long& other, const Var& da) - /// Greater than or equal operator for comparing Var with long -{ - if (da.isEmpty()) return false; - return other >= da.convert<long>(); -} - - -#endif // POCO_LONG_IS_64_BIT - - -} // namespace Dynamic - - -//@ deprecated -typedef Dynamic::Var DynamicAny; - - -} // namespace Poco - - -#endif // Foundation_Var_INCLUDED + bool operator >= (const T& other) const + /// Greater than or equal operator + { + if (isEmpty()) return false; + return convert<T>() >= other; + } + + bool operator >= (const Var& other) const; + /// Greater than or equal operator overload for Var + + template <typename T> + bool operator || (const T& other) const + /// Logical OR operator + { + if (isEmpty()) return false; + return convert<bool>() || other; + } + + bool operator || (const Var& other) const; + /// Logical OR operator operator overload for Var + + template <typename T> + bool operator && (const T& other) const + /// Logical AND operator. + { + if (isEmpty()) return false; + return convert<bool>() && other; + } + + bool operator && (const Var& other) const; + /// Logical AND operator operator overload for Var. + + bool isArray() const; + /// Returns true if Var is an array. + + bool isVector() const; + /// Returns true if Var represents a vector. + + bool isList() const; + /// Returns true if Var represents a list. + + bool isDeque() const; + /// Returns true if Var represents a deque. + + bool isStruct() const; + /// Returns true if Var represents a struct. + + char& at(std::size_t n); + /// Returns character at position n. This function only works with + /// Var containing a std::string. + + + template <typename T> + Var& operator [] (const T& n) + { + return getAt(n); + } + + template <typename T> + const Var& operator [] (const T& n) const + { + return const_cast<Var*>(this)->getAt(n); + } + + Var& operator [] (const std::string& name); + /// Index operator by name, only use on Vars where isStruct + /// returns true! In all other cases InvalidAccessException is thrown. + + const Var& operator [] (const std::string& name) const; + /// Index operator by name, only use on Vars where isStruct + /// returns true! In all other cases InvalidAccessException is thrown. + + const std::type_info& type() const; + /// Returns the type information of the stored content. + + //@ deprecated + void empty(); + /// Empties Var. + /// This function is deprecated and will be removed. + /// Please use clear(). + + void clear(); + /// Empties Var. + + bool isEmpty() const; + /// Returns true if empty. + + bool isInteger() const; + /// Returns true if stored value is integer. + + bool isSigned() const; + /// Returns true if stored value is signed. + + bool isNumeric() const; + /// Returns true if stored value is numeric. + /// Returns false for numeric strings (e.g. "123" is string, not number) + + bool isBoolean() const; + /// Returns true if stored value is boolean. + /// Returns false for boolean strings (e.g. "true" is string, not number) + + bool isString() const; + /// Returns true if stored value is std::string. + + bool isDate() const; + /// Returns true if stored value represents a date. + + bool isTime() const; + /// Returns true if stored value represents time or date/time. + + bool isDateTime() const; + /// Returns true if stored value represents a date/time. + + std::size_t size() const; + /// Returns the size of this Var. + /// This function returns 0 when Var is empty, 1 for POD or the size (i.e. length) + /// for held container. + + std::string toString() const + /// Returns the stored value as string. + { + VarHolder* pHolder = content(); + + if (!pHolder) + throw InvalidAccessException("Can not convert empty value."); + + if (typeid(std::string) == pHolder->type()) + return extract<std::string>(); + else + { + std::string result; + pHolder->convert(result); + return result; + } + } + + static Var parse(const std::string& val); + /// Parses the string which must be in JSON format + + static std::string toString(const Var& var); + /// Converts the Var to a string in JSON format. Note that toString(const Var&) will return + /// a different result than Var::convert<std::string>() and Var::toString()! + +private: + Var& getAt(std::size_t n); + Var& getAt(const std::string& n); + + static Var parse(const std::string& val, std::string::size_type& offset); + /// Parses the string which must be in JSON format + + static Var parseObject(const std::string& val, std::string::size_type& pos); + static Var parseArray(const std::string& val, std::string::size_type& pos); + static std::string parseString(const std::string& val, std::string::size_type& pos); + static std::string parseJSONString(const std::string& val, std::string::size_type& pos); + static void skipWhiteSpace(const std::string& val, std::string::size_type& pos); + + template <typename T> + T add(const Var& other) const + { + return convert<T>() + other.convert<T>(); + } + + template <typename T> + T subtract(const Var& other) const + { + return convert<T>() - other.convert<T>(); + } + + template <typename T> + T multiply(const Var& other) const + { + return convert<T>() * other.convert<T>(); + } + + template <typename T> + T divide(const Var& other) const + { + return convert<T>() / other.convert<T>(); + } + + template <typename T, typename E> + VarHolderImpl<T>* holderImpl(const std::string errorMessage = "") const + { + VarHolder* pHolder = content(); + + if (pHolder && pHolder->type() == typeid(T)) + return static_cast<VarHolderImpl<T>*>(pHolder); + else if (!pHolder) + throw InvalidAccessException("Can not access empty value."); + else + throw E(errorMessage); + } + + Var& structIndexOperator(VarHolderImpl<Struct<int> >* pStr, int n) const; + +#ifdef POCO_NO_SOO + + VarHolder* content() const + { + return _pHolder; + } + + void destruct() + { + if (!isEmpty()) delete content(); + } + + VarHolder* _pHolder; + +#else + + VarHolder* content() const + { + return _placeholder.content(); + } + + template<typename ValueType> + void construct(const ValueType& value) + { + if (sizeof(VarHolderImpl<ValueType>) <= Placeholder<ValueType>::Size::value) + { + new (reinterpret_cast<VarHolder*>(_placeholder.holder)) VarHolderImpl<ValueType>(value); + _placeholder.setLocal(true); + } + else + { + _placeholder.pHolder = new VarHolderImpl<ValueType>(value); + _placeholder.setLocal(false); + } + } + + void construct(const char* value) + { + std::string val(value); + if (sizeof(VarHolderImpl<std::string>) <= Placeholder<std::string>::Size::value) + { + new (reinterpret_cast<VarHolder*>(_placeholder.holder)) VarHolderImpl<std::string>(val); + _placeholder.setLocal(true); + } + else + { + _placeholder.pHolder = new VarHolderImpl<std::string>(val); + _placeholder.setLocal(false); + } + } + + void construct(const Var& other) + { + if (!other.isEmpty()) + other.content()->clone(&_placeholder); + else + _placeholder.erase(); + } + + void destruct() + { + if (!isEmpty()) + { + if (_placeholder.isLocal()) + content()->~VarHolder(); + else + delete content(); + } + } + + Placeholder<VarHolder> _placeholder; + +#endif // POCO_NO_SOO +}; + + +/// +/// inlines +/// + + +/// +/// Var members +/// + +inline void Var::swap(Var& other) +{ +#ifdef POCO_NO_SOO + + std::swap(_pHolder, other._pHolder); + +#else + + if (this == &other) return; + + if (!_placeholder.isLocal() && !other._placeholder.isLocal()) + { + std::swap(_placeholder.pHolder, other._placeholder.pHolder); + } + else + { + Var tmp(*this); + try + { + if (_placeholder.isLocal()) destruct(); + construct(other); + other = tmp; + } + catch (...) + { + construct(tmp); + throw; + } + } + +#endif +} + + +inline const std::type_info& Var::type() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->type() : typeid(void); +} + + +inline Var::ConstIterator Var::begin() const +{ + if (isEmpty()) return ConstIterator(const_cast<Var*>(this), true); + + return ConstIterator(const_cast<Var*>(this), false); +} + +inline Var::ConstIterator Var::end() const +{ + return ConstIterator(const_cast<Var*>(this), true); +} + +inline Var::Iterator Var::begin() +{ + if (isEmpty()) return Iterator(const_cast<Var*>(this), true); + + return Iterator(const_cast<Var*>(this), false); +} + +inline Var::Iterator Var::end() +{ + return Iterator(this, true); +} + + +inline Var& Var::operator [] (const std::string& name) +{ + return getAt(name); +} + + +inline const Var& Var::operator [] (const std::string& name) const +{ + return const_cast<Var*>(this)->getAt(name); +} + + +inline const Var Var::operator + (const char* other) const +{ + return convert<std::string>() + other; +} + + +inline Var& Var::operator += (const char*other) +{ + return *this = convert<std::string>() + other; +} + + +inline bool Var::operator ! () const +{ + return !convert<bool>(); +} + + +inline bool Var::isEmpty() const +{ + return 0 == content(); +} + + +inline bool Var::isArray() const +{ + if (isEmpty() || + isString()) return false; + + VarHolder* pHolder = content(); + return pHolder ? pHolder->isArray() : false; +} + + +inline bool Var::isVector() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isVector() : false; +} + + +inline bool Var::isList() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isList() : false; +} + + +inline bool Var::isDeque() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isDeque() : false; +} + + +inline bool Var::isStruct() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isStruct() : false; +} + + +inline bool Var::isInteger() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isInteger() : false; +} + + +inline bool Var::isSigned() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isSigned() : false; +} + + +inline bool Var::isNumeric() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isNumeric() : false; +} + + +inline bool Var::isBoolean() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isBoolean() : false; +} + + +inline bool Var::isString() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isString() : false; +} + + +inline bool Var::isDate() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isDate() : false; +} + + +inline bool Var::isTime() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isTime() : false; +} + + +inline bool Var::isDateTime() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->isDateTime() : false; +} + + +inline std::size_t Var::size() const +{ + VarHolder* pHolder = content(); + return pHolder ? pHolder->size() : 0; +} + + +/// +/// Var non-member functions +/// + +inline const Var operator + (const char* other, const Var& da) + /// Addition operator for adding Var to const char* +{ + std::string tmp = other; + return tmp + da.convert<std::string>(); +} + + +inline char operator + (const char& other, const Var& da) + /// Addition operator for adding Var to char +{ + return other + da.convert<char>(); +} + + +inline char operator - (const char& other, const Var& da) + /// Subtraction operator for subtracting Var from char +{ + return other - da.convert<char>(); +} + + +inline char operator * (const char& other, const Var& da) + /// Multiplication operator for multiplying Var with char +{ + return other * da.convert<char>(); +} + + +inline char operator / (const char& other, const Var& da) + /// Division operator for dividing Var with char +{ + return other / da.convert<char>(); +} + + +inline char operator += (char& other, const Var& da) + /// Addition assignment operator for adding Var to char +{ + return other += da.convert<char>(); +} + + +inline char operator -= (char& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from char +{ + return other -= da.convert<char>(); +} + + +inline char operator *= (char& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with char +{ + return other *= da.convert<char>(); +} + + +inline char operator /= (char& other, const Var& da) + /// Division assignment operator for dividing Var with char +{ + return other /= da.convert<char>(); +} + + +inline bool operator == (const char& other, const Var& da) + /// Equality operator for comparing Var with char +{ + if (da.isEmpty()) return false; + return other == da.convert<char>(); +} + + +inline bool operator != (const char& other, const Var& da) + /// Inequality operator for comparing Var with char +{ + if (da.isEmpty()) return true; + return other != da.convert<char>(); +} + + +inline bool operator < (const char& other, const Var& da) + /// Less than operator for comparing Var with char +{ + if (da.isEmpty()) return false; + return other < da.convert<char>(); +} + + +inline bool operator <= (const char& other, const Var& da) + /// Less than or equal operator for comparing Var with char +{ + if (da.isEmpty()) return false; + return other <= da.convert<char>(); +} + + +inline bool operator > (const char& other, const Var& da) + /// Greater than operator for comparing Var with char +{ + if (da.isEmpty())return false; + return other > da.convert<char>(); +} + + +inline bool operator >= (const char& other, const Var& da) + /// Greater than or equal operator for comparing Var with char +{ + if (da.isEmpty())return false; + return other >= da.convert<char>(); +} + + +inline Poco::Int8 operator + (const Poco::Int8& other, const Var& da) + /// Addition operator for adding Var to Poco::Int8 +{ + return other + da.convert<Poco::Int8>(); +} + + +inline Poco::Int8 operator - (const Poco::Int8& other, const Var& da) + /// Subtraction operator for subtracting Var from Poco::Int8 +{ + return other - da.convert<Poco::Int8>(); +} + + +inline Poco::Int8 operator * (const Poco::Int8& other, const Var& da) + /// Multiplication operator for multiplying Var with Poco::Int8 +{ + return other * da.convert<Poco::Int8>(); +} + + +inline Poco::Int8 operator / (const Poco::Int8& other, const Var& da) + /// Division operator for dividing Var with Poco::Int8 +{ + return other / da.convert<Poco::Int8>(); +} + + +inline Poco::Int8 operator += (Poco::Int8& other, const Var& da) + /// Addition assignment operator for adding Var to Poco::Int8 +{ + return other += da.convert<Poco::Int8>(); +} + + +inline Poco::Int8 operator -= (Poco::Int8& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from Poco::Int8 +{ + return other -= da.convert<Poco::Int8>(); +} + + +inline Poco::Int8 operator *= (Poco::Int8& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with Poco::Int8 +{ + return other *= da.convert<Poco::Int8>(); +} + + +inline Poco::Int8 operator /= (Poco::Int8& other, const Var& da) + /// Division assignment operator for dividing Var with Poco::Int8 +{ + return other /= da.convert<Poco::Int8>(); +} + + +inline bool operator == (const Poco::Int8& other, const Var& da) + /// Equality operator for comparing Var with Poco::Int8 +{ + if (da.isEmpty()) return false; + return other == da.convert<Poco::Int8>(); +} + + +inline bool operator != (const Poco::Int8& other, const Var& da) + /// Inequality operator for comparing Var with Poco::Int8 +{ + if (da.isEmpty()) return true; + return other != da.convert<Poco::Int8>(); +} + + +inline bool operator < (const Poco::Int8& other, const Var& da) + /// Less than operator for comparing Var with Poco::Int8 +{ + if (da.isEmpty()) return false; + return other < da.convert<Poco::Int8>(); +} + + +inline bool operator <= (const Poco::Int8& other, const Var& da) + /// Less than or equal operator for comparing Var with Poco::Int8 +{ + if (da.isEmpty()) return false; + return other <= da.convert<Poco::Int8>(); +} + + +inline bool operator > (const Poco::Int8& other, const Var& da) + /// Greater than operator for comparing Var with Poco::Int8 +{ + if (da.isEmpty()) return false; + return other > da.convert<Poco::Int8>(); +} + + +inline bool operator >= (const Poco::Int8& other, const Var& da) + /// Greater than or equal operator for comparing Var with Poco::Int8 +{ + if (da.isEmpty()) return false; + return other >= da.convert<Poco::Int8>(); +} + + +inline Poco::UInt8 operator + (const Poco::UInt8& other, const Var& da) + /// Addition operator for adding Var to Poco::UInt8 +{ + return other + da.convert<Poco::UInt8>(); +} + + +inline Poco::UInt8 operator - (const Poco::UInt8& other, const Var& da) + /// Subtraction operator for subtracting Var from Poco::UInt8 +{ + return other - da.convert<Poco::UInt8>(); +} + + +inline Poco::UInt8 operator * (const Poco::UInt8& other, const Var& da) + /// Multiplication operator for multiplying Var with Poco::UInt8 +{ + return other * da.convert<Poco::UInt8>(); +} + + +inline Poco::UInt8 operator / (const Poco::UInt8& other, const Var& da) + /// Division operator for dividing Var with Poco::UInt8 +{ + return other / da.convert<Poco::UInt8>(); +} + + +inline Poco::UInt8 operator += (Poco::UInt8& other, const Var& da) + /// Addition assignment operator for adding Var to Poco::UInt8 +{ + return other += da.convert<Poco::UInt8>(); +} + + +inline Poco::UInt8 operator -= (Poco::UInt8& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from Poco::UInt8 +{ + return other -= da.convert<Poco::UInt8>(); +} + + +inline Poco::UInt8 operator *= (Poco::UInt8& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with Poco::UInt8 +{ + return other *= da.convert<Poco::UInt8>(); +} + + +inline Poco::UInt8 operator /= (Poco::UInt8& other, const Var& da) + /// Division assignment operator for dividing Var with Poco::UInt8 +{ + return other /= da.convert<Poco::UInt8>(); +} + + +inline bool operator == (const Poco::UInt8& other, const Var& da) + /// Equality operator for comparing Var with Poco::UInt8 +{ + if (da.isEmpty()) return false; + return other == da.convert<Poco::UInt8>(); +} + + +inline bool operator != (const Poco::UInt8& other, const Var& da) + /// Inequality operator for comparing Var with Poco::UInt8 +{ + if (da.isEmpty()) return true; + return other != da.convert<Poco::UInt8>(); +} + + +inline bool operator < (const Poco::UInt8& other, const Var& da) + /// Less than operator for comparing Var with Poco::UInt8 +{ + if (da.isEmpty()) return false; + return other < da.convert<Poco::UInt8>(); +} + + +inline bool operator <= (const Poco::UInt8& other, const Var& da) + /// Less than or equal operator for comparing Var with Poco::UInt8 +{ + if (da.isEmpty()) return false; + return other <= da.convert<Poco::UInt8>(); +} + + +inline bool operator > (const Poco::UInt8& other, const Var& da) + /// Greater than operator for comparing Var with Poco::UInt8 +{ + if (da.isEmpty()) return false; + return other > da.convert<Poco::UInt8>(); +} + + +inline bool operator >= (const Poco::UInt8& other, const Var& da) + /// Greater than or equal operator for comparing Var with Poco::UInt8 +{ + if (da.isEmpty()) return false; + return other >= da.convert<Poco::UInt8>(); +} + + +inline Poco::Int16 operator + (const Poco::Int16& other, const Var& da) + /// Addition operator for adding Var to Poco::Int16 +{ + return other + da.convert<Poco::Int16>(); +} + + +inline Poco::Int16 operator - (const Poco::Int16& other, const Var& da) + /// Subtraction operator for subtracting Var from Poco::Int16 +{ + return other - da.convert<Poco::Int16>(); +} + + +inline Poco::Int16 operator * (const Poco::Int16& other, const Var& da) + /// Multiplication operator for multiplying Var with Poco::Int16 +{ + return other * da.convert<Poco::Int16>(); +} + + +inline Poco::Int16 operator / (const Poco::Int16& other, const Var& da) + /// Division operator for dividing Var with Poco::Int16 +{ + return other / da.convert<Poco::Int16>(); +} + + +inline Poco::Int16 operator += (Poco::Int16& other, const Var& da) + /// Addition assignment operator for adding Var to Poco::Int16 +{ + return other += da.convert<Poco::Int16>(); +} + + +inline Poco::Int16 operator -= (Poco::Int16& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from Poco::Int16 +{ + return other -= da.convert<Poco::Int16>(); +} + + +inline Poco::Int16 operator *= (Poco::Int16& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with Poco::Int16 +{ + return other *= da.convert<Poco::Int16>(); +} + + +inline Poco::Int16 operator /= (Poco::Int16& other, const Var& da) + /// Division assignment operator for dividing Var with Poco::Int16 +{ + return other /= da.convert<Poco::Int16>(); +} + + +inline bool operator == (const Poco::Int16& other, const Var& da) + /// Equality operator for comparing Var with Poco::Int16 +{ + if (da.isEmpty()) return false; + return other == da.convert<Poco::Int16>(); +} + + +inline bool operator != (const Poco::Int16& other, const Var& da) + /// Inequality operator for comparing Var with Poco::Int16 +{ + if (da.isEmpty()) return true; + return other != da.convert<Poco::Int16>(); +} + + +inline bool operator < (const Poco::Int16& other, const Var& da) + /// Less than operator for comparing Var with Poco::Int16 +{ + if (da.isEmpty()) return false; + return other < da.convert<Poco::Int16>(); +} + + +inline bool operator <= (const Poco::Int16& other, const Var& da) + /// Less than or equal operator for comparing Var with Poco::Int16 +{ + if (da.isEmpty()) return false; + return other <= da.convert<Poco::Int16>(); +} + + +inline bool operator > (const Poco::Int16& other, const Var& da) + /// Greater than operator for comparing Var with Poco::Int16 +{ + if (da.isEmpty()) return false; + return other > da.convert<Poco::Int16>(); +} + + +inline bool operator >= (const Poco::Int16& other, const Var& da) + /// Greater than or equal operator for comparing Var with Poco::Int16 +{ + if (da.isEmpty()) return false; + return other >= da.convert<Poco::Int16>(); +} + + +inline Poco::UInt16 operator + (const Poco::UInt16& other, const Var& da) + /// Addition operator for adding Var to Poco::UInt16 +{ + return other + da.convert<Poco::UInt16>(); +} + + +inline Poco::UInt16 operator - (const Poco::UInt16& other, const Var& da) + /// Subtraction operator for subtracting Var from Poco::UInt16 +{ + return other - da.convert<Poco::UInt16>(); +} + + +inline Poco::UInt16 operator * (const Poco::UInt16& other, const Var& da) + /// Multiplication operator for multiplying Var with Poco::UInt16 +{ + return other * da.convert<Poco::UInt16>(); +} + + +inline Poco::UInt16 operator / (const Poco::UInt16& other, const Var& da) + /// Division operator for dividing Var with Poco::UInt16 +{ + return other / da.convert<Poco::UInt16>(); +} + + +inline Poco::UInt16 operator += (Poco::UInt16& other, const Var& da) + /// Addition assignment operator for adding Var to Poco::UInt16 +{ + return other += da.convert<Poco::UInt16>(); +} + + +inline Poco::UInt16 operator -= (Poco::UInt16& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from Poco::UInt16 +{ + return other -= da.convert<Poco::UInt16>(); +} + + +inline Poco::UInt16 operator *= (Poco::UInt16& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with Poco::UInt16 +{ + return other *= da.convert<Poco::UInt16>(); +} + + +inline Poco::UInt16 operator /= (Poco::UInt16& other, const Var& da) + /// Division assignment operator for dividing Var with Poco::UInt16 +{ + return other /= da.convert<Poco::UInt16>(); +} + + +inline bool operator == (const Poco::UInt16& other, const Var& da) + /// Equality operator for comparing Var with Poco::UInt16 +{ + if (da.isEmpty()) return false; + return other == da.convert<Poco::UInt16>(); +} + + +inline bool operator != (const Poco::UInt16& other, const Var& da) + /// Inequality operator for comparing Var with Poco::UInt16 +{ + if (da.isEmpty()) return true; + return other != da.convert<Poco::UInt16>(); +} + + +inline bool operator < (const Poco::UInt16& other, const Var& da) + /// Less than operator for comparing Var with Poco::UInt16 +{ + if (da.isEmpty()) return false; + return other < da.convert<Poco::UInt16>(); +} + + +inline bool operator <= (const Poco::UInt16& other, const Var& da) + /// Less than or equal operator for comparing Var with Poco::UInt16 +{ + if (da.isEmpty()) return false; + return other <= da.convert<Poco::UInt16>(); +} + + +inline bool operator > (const Poco::UInt16& other, const Var& da) + /// Greater than operator for comparing Var with Poco::UInt16 +{ + if (da.isEmpty()) return false; + return other > da.convert<Poco::UInt16>(); +} + + +inline bool operator >= (const Poco::UInt16& other, const Var& da) + /// Greater than or equal operator for comparing Var with Poco::UInt16 +{ + if (da.isEmpty()) return false; + return other >= da.convert<Poco::UInt16>(); +} + + +inline Poco::Int32 operator + (const Poco::Int32& other, const Var& da) + /// Addition operator for adding Var to Poco::Int32 +{ + return other + da.convert<Poco::Int32>(); +} + + +inline Poco::Int32 operator - (const Poco::Int32& other, const Var& da) + /// Subtraction operator for subtracting Var from Poco::Int32 +{ + return other - da.convert<Poco::Int32>(); +} + + +inline Poco::Int32 operator * (const Poco::Int32& other, const Var& da) + /// Multiplication operator for multiplying Var with Poco::Int32 +{ + return other * da.convert<Poco::Int32>(); +} + + +inline Poco::Int32 operator / (const Poco::Int32& other, const Var& da) + /// Division operator for dividing Var with Poco::Int32 +{ + return other / da.convert<Poco::Int32>(); +} + + +inline Poco::Int32 operator += (Poco::Int32& other, const Var& da) + /// Addition assignment operator for adding Var to Poco::Int32 +{ + return other += da.convert<Poco::Int32>(); +} + + +inline Poco::Int32 operator -= (Poco::Int32& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from Poco::Int32 +{ + return other -= da.convert<Poco::Int32>(); +} + + +inline Poco::Int32 operator *= (Poco::Int32& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with Poco::Int32 +{ + return other *= da.convert<Poco::Int32>(); +} + + +inline Poco::Int32 operator /= (Poco::Int32& other, const Var& da) + /// Division assignment operator for dividing Var with Poco::Int32 +{ + return other /= da.convert<Poco::Int32>(); +} + + +inline bool operator == (const Poco::Int32& other, const Var& da) + /// Equality operator for comparing Var with Poco::Int32 +{ + if (da.isEmpty()) return false; + return other == da.convert<Poco::Int32>(); +} + + +inline bool operator != (const Poco::Int32& other, const Var& da) + /// Inequality operator for comparing Var with Poco::Int32 +{ + if (da.isEmpty()) return true; + return other != da.convert<Poco::Int32>(); +} + + +inline bool operator < (const Poco::Int32& other, const Var& da) + /// Less than operator for comparing Var with Poco::Int32 +{ + if (da.isEmpty()) return false; + return other < da.convert<Poco::Int32>(); +} + + +inline bool operator <= (const Poco::Int32& other, const Var& da) + /// Less than or equal operator for comparing Var with Poco::Int32 +{ + if (da.isEmpty()) return false; + return other <= da.convert<Poco::Int32>(); +} + + +inline bool operator > (const Poco::Int32& other, const Var& da) + /// Greater than operator for comparing Var with Poco::Int32 +{ + if (da.isEmpty()) return false; + return other > da.convert<Poco::Int32>(); +} + + +inline bool operator >= (const Poco::Int32& other, const Var& da) + /// Greater than or equal operator for comparing Var with Poco::Int32 +{ + if (da.isEmpty()) return false; + return other >= da.convert<Poco::Int32>(); +} + + +inline Poco::UInt32 operator + (const Poco::UInt32& other, const Var& da) + /// Addition operator for adding Var to Poco::UInt32 +{ + return other + da.convert<Poco::UInt32>(); +} + + +inline Poco::UInt32 operator - (const Poco::UInt32& other, const Var& da) + /// Subtraction operator for subtracting Var from Poco::UInt32 +{ + return other - da.convert<Poco::UInt32>(); +} + + +inline Poco::UInt32 operator * (const Poco::UInt32& other, const Var& da) + /// Multiplication operator for multiplying Var with Poco::UInt32 +{ + return other * da.convert<Poco::UInt32>(); +} + + +inline Poco::UInt32 operator / (const Poco::UInt32& other, const Var& da) + /// Division operator for dividing Var with Poco::UInt32 +{ + return other / da.convert<Poco::UInt32>(); +} + + +inline Poco::UInt32 operator += (Poco::UInt32& other, const Var& da) + /// Addition assignment operator for adding Var to Poco::UInt32 +{ + return other += da.convert<Poco::UInt32>(); +} + + +inline Poco::UInt32 operator -= (Poco::UInt32& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from Poco::UInt32 +{ + return other -= da.convert<Poco::UInt32>(); +} + + +inline Poco::UInt32 operator *= (Poco::UInt32& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with Poco::UInt32 +{ + return other *= da.convert<Poco::UInt32>(); +} + + +inline Poco::UInt32 operator /= (Poco::UInt32& other, const Var& da) + /// Division assignment operator for dividing Var with Poco::UInt32 +{ + return other /= da.convert<Poco::UInt32>(); +} + + +inline bool operator == (const Poco::UInt32& other, const Var& da) + /// Equality operator for comparing Var with Poco::UInt32 +{ + if (da.isEmpty()) return false; + return other == da.convert<Poco::UInt32>(); +} + + +inline bool operator != (const Poco::UInt32& other, const Var& da) + /// Inequality operator for comparing Var with Poco::UInt32 +{ + if (da.isEmpty()) return true; + return other != da.convert<Poco::UInt32>(); +} + + +inline bool operator < (const Poco::UInt32& other, const Var& da) + /// Less than operator for comparing Var with Poco::UInt32 +{ + if (da.isEmpty()) return false; + return other < da.convert<Poco::UInt32>(); +} + + +inline bool operator <= (const Poco::UInt32& other, const Var& da) + /// Less than or equal operator for comparing Var with Poco::UInt32 +{ + if (da.isEmpty()) return false; + return other <= da.convert<Poco::UInt32>(); +} + + +inline bool operator > (const Poco::UInt32& other, const Var& da) + /// Greater than operator for comparing Var with Poco::UInt32 +{ + if (da.isEmpty()) return false; + return other > da.convert<Poco::UInt32>(); +} + + +inline bool operator >= (const Poco::UInt32& other, const Var& da) + /// Greater than or equal operator for comparing Var with Poco::UInt32 +{ + if (da.isEmpty()) return false; + return other >= da.convert<Poco::UInt32>(); +} + + +inline Poco::Int64 operator + (const Poco::Int64& other, const Var& da) + /// Addition operator for adding Var to Poco::Int64 +{ + return other + da.convert<Poco::Int64>(); +} + + +inline Poco::Int64 operator - (const Poco::Int64& other, const Var& da) + /// Subtraction operator for subtracting Var from Poco::Int64 +{ + return other - da.convert<Poco::Int64>(); +} + + +inline Poco::Int64 operator * (const Poco::Int64& other, const Var& da) + /// Multiplication operator for multiplying Var with Poco::Int64 +{ + return other * da.convert<Poco::Int64>(); +} + + +inline Poco::Int64 operator / (const Poco::Int64& other, const Var& da) + /// Division operator for dividing Var with Poco::Int64 +{ + return other / da.convert<Poco::Int64>(); +} + + +inline Poco::Int64 operator += (Poco::Int64& other, const Var& da) + /// Addition assignment operator for adding Var to Poco::Int64 +{ + return other += da.convert<Poco::Int64>(); +} + + +inline Poco::Int64 operator -= (Poco::Int64& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from Poco::Int64 +{ + return other -= da.convert<Poco::Int64>(); +} + + +inline Poco::Int64 operator *= (Poco::Int64& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with Poco::Int64 +{ + return other *= da.convert<Poco::Int64>(); +} + + +inline Poco::Int64 operator /= (Poco::Int64& other, const Var& da) + /// Division assignment operator for dividing Var with Poco::Int64 +{ + return other /= da.convert<Poco::Int64>(); +} + + +inline bool operator == (const Poco::Int64& other, const Var& da) + /// Equality operator for comparing Var with Poco::Int64 +{ + if (da.isEmpty()) return false; + return other == da.convert<Poco::Int64>(); +} + + +inline bool operator != (const Poco::Int64& other, const Var& da) + /// Inequality operator for comparing Var with Poco::Int64 +{ + if (da.isEmpty()) return true; + return other != da.convert<Poco::Int64>(); +} + + +inline bool operator < (const Poco::Int64& other, const Var& da) + /// Less than operator for comparing Var with Poco::Int64 +{ + if (da.isEmpty()) return false; + return other < da.convert<Poco::Int64>(); +} + + +inline bool operator <= (const Poco::Int64& other, const Var& da) + /// Less than or equal operator for comparing Var with Poco::Int64 +{ + if (da.isEmpty()) return false; + return other <= da.convert<Poco::Int64>(); +} + + +inline bool operator > (const Poco::Int64& other, const Var& da) + /// Greater than operator for comparing Var with Poco::Int64 +{ + if (da.isEmpty()) return false; + return other > da.convert<Poco::Int64>(); +} + + +inline bool operator >= (const Poco::Int64& other, const Var& da) + /// Greater than or equal operator for comparing Var with Poco::Int64 +{ + if (da.isEmpty()) return false; + return other >= da.convert<Poco::Int64>(); +} + + +inline Poco::UInt64 operator + (const Poco::UInt64& other, const Var& da) + /// Addition operator for adding Var to Poco::UInt64 +{ + return other + da.convert<Poco::UInt64>(); +} + + +inline Poco::UInt64 operator - (const Poco::UInt64& other, const Var& da) + /// Subtraction operator for subtracting Var from Poco::UInt64 +{ + return other - da.convert<Poco::UInt64>(); +} + + +inline Poco::UInt64 operator * (const Poco::UInt64& other, const Var& da) + /// Multiplication operator for multiplying Var with Poco::UInt64 +{ + return other * da.convert<Poco::UInt64>(); +} + + +inline Poco::UInt64 operator / (const Poco::UInt64& other, const Var& da) + /// Division operator for dividing Var with Poco::UInt64 +{ + return other / da.convert<Poco::UInt64>(); +} + + +inline Poco::UInt64 operator += (Poco::UInt64& other, const Var& da) + /// Addition assignment operator for adding Var to Poco::UInt64 +{ + return other += da.convert<Poco::UInt64>(); +} + + +inline Poco::UInt64 operator -= (Poco::UInt64& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from Poco::UInt64 +{ + return other -= da.convert<Poco::UInt64>(); +} + + +inline Poco::UInt64 operator *= (Poco::UInt64& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with Poco::UInt64 +{ + return other *= da.convert<Poco::UInt64>(); +} + + +inline Poco::UInt64 operator /= (Poco::UInt64& other, const Var& da) + /// Division assignment operator for dividing Var with Poco::UInt64 +{ + return other /= da.convert<Poco::UInt64>(); +} + + +inline bool operator == (const Poco::UInt64& other, const Var& da) + /// Equality operator for comparing Var with Poco::UInt64 +{ + if (da.isEmpty()) return false; + return other == da.convert<Poco::UInt64>(); +} + + +inline bool operator != (const Poco::UInt64& other, const Var& da) + /// Inequality operator for comparing Var with Poco::UInt64 +{ + if (da.isEmpty()) return true; + return other != da.convert<Poco::UInt64>(); +} + + +inline bool operator < (const Poco::UInt64& other, const Var& da) + /// Less than operator for comparing Var with Poco::UInt64 +{ + if (da.isEmpty()) return false; + return other < da.convert<Poco::UInt64>(); +} + + +inline bool operator <= (const Poco::UInt64& other, const Var& da) + /// Less than or equal operator for comparing Var with Poco::UInt64 +{ + if (da.isEmpty()) return false; + return other <= da.convert<Poco::UInt64>(); +} + + +inline bool operator > (const Poco::UInt64& other, const Var& da) + /// Greater than operator for comparing Var with Poco::UInt64 +{ + if (da.isEmpty()) return false; + return other > da.convert<Poco::UInt64>(); +} + + +inline bool operator >= (const Poco::UInt64& other, const Var& da) + /// Greater than or equal operator for comparing Var with Poco::UInt64 +{ + if (da.isEmpty()) return false; + return other >= da.convert<Poco::UInt64>(); +} + + +inline float operator + (const float& other, const Var& da) + /// Addition operator for adding Var to float +{ + return other + da.convert<float>(); +} + + +inline float operator - (const float& other, const Var& da) + /// Subtraction operator for subtracting Var from float +{ + return other - da.convert<float>(); +} + + +inline float operator * (const float& other, const Var& da) + /// Multiplication operator for multiplying Var with float +{ + return other * da.convert<float>(); +} + + +inline float operator / (const float& other, const Var& da) + /// Division operator for dividing Var with float +{ + return other / da.convert<float>(); +} + + +inline float operator += (float& other, const Var& da) + /// Addition assignment operator for adding Var to float +{ + return other += da.convert<float>(); +} + + +inline float operator -= (float& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from float +{ + return other -= da.convert<float>(); +} + + +inline float operator *= (float& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with float +{ + return other *= da.convert<float>(); +} + + +inline float operator /= (float& other, const Var& da) + /// Division assignment operator for dividing Var with float +{ + return other /= da.convert<float>(); +} + + +inline bool operator == (const float& other, const Var& da) + /// Equality operator for comparing Var with float +{ + if (da.isEmpty()) return false; + return other == da.convert<float>(); +} + + +inline bool operator != (const float& other, const Var& da) + /// Inequality operator for comparing Var with float +{ + if (da.isEmpty()) return true; + return other != da.convert<float>(); +} + + +inline bool operator < (const float& other, const Var& da) + /// Less than operator for comparing Var with float +{ + if (da.isEmpty()) return false; + return other < da.convert<float>(); +} + + +inline bool operator <= (const float& other, const Var& da) + /// Less than or equal operator for comparing Var with float +{ + if (da.isEmpty()) return false; + return other <= da.convert<float>(); +} + + +inline bool operator > (const float& other, const Var& da) + /// Greater than operator for comparing Var with float +{ + if (da.isEmpty()) return false; + return other > da.convert<float>(); +} + + +inline bool operator >= (const float& other, const Var& da) + /// Greater than or equal operator for comparing Var with float +{ + if (da.isEmpty()) return false; + return other >= da.convert<float>(); +} + + +inline double operator + (const double& other, const Var& da) + /// Addition operator for adding Var to double +{ + return other + da.convert<double>(); +} + + +inline double operator - (const double& other, const Var& da) + /// Subtraction operator for subtracting Var from double +{ + return other - da.convert<double>(); +} + + +inline double operator * (const double& other, const Var& da) + /// Multiplication operator for multiplying Var with double +{ + return other * da.convert<double>(); +} + + +inline double operator / (const double& other, const Var& da) + /// Division operator for dividing Var with double +{ + return other / da.convert<double>(); +} + + +inline double operator += (double& other, const Var& da) + /// Addition assignment operator for adding Var to double +{ + return other += da.convert<double>(); +} + + +inline double operator -= (double& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from double +{ + return other -= da.convert<double>(); +} + + +inline double operator *= (double& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with double +{ + return other *= da.convert<double>(); +} + + +inline double operator /= (double& other, const Var& da) + /// Division assignment operator for dividing Var with double +{ + return other /= da.convert<double>(); +} + + +inline bool operator == (const double& other, const Var& da) + /// Equality operator for comparing Var with double +{ + if (da.isEmpty()) return false; + return other == da.convert<double>(); +} + + +inline bool operator != (const double& other, const Var& da) + /// Inequality operator for comparing Var with double +{ + if (da.isEmpty()) return true; + return other != da.convert<double>(); +} + + +inline bool operator < (const double& other, const Var& da) + /// Less than operator for comparing Var with double +{ + if (da.isEmpty()) return false; + return other < da.convert<double>(); +} + + +inline bool operator <= (const double& other, const Var& da) + /// Less than or equal operator for comparing Var with double +{ + if (da.isEmpty()) return false; + return other <= da.convert<double>(); +} + + +inline bool operator > (const double& other, const Var& da) + /// Greater than operator for comparing Var with double +{ + if (da.isEmpty()) return false; + return other > da.convert<double>(); +} + + +inline bool operator >= (const double& other, const Var& da) + /// Greater than or equal operator for comparing Var with double +{ + if (da.isEmpty()) return false; + return other >= da.convert<double>(); +} + + +inline bool operator == (const bool& other, const Var& da) + /// Equality operator for comparing Var with bool +{ + if (da.isEmpty()) return false; + return other == da.convert<bool>(); +} + + +inline bool operator != (const bool& other, const Var& da) + /// Inequality operator for comparing Var with bool +{ + if (da.isEmpty()) return true; + return other != da.convert<bool>(); +} + + +inline bool operator == (const std::string& other, const Var& da) + /// Equality operator for comparing Var with std::string +{ + if (da.isEmpty()) return false; + return other == da.convert<std::string>(); +} + + +inline bool operator != (const std::string& other, const Var& da) + /// Inequality operator for comparing Var with std::string +{ + if (da.isEmpty()) return true; + return other != da.convert<std::string>(); +} + + +inline bool operator == (const UTF16String& other, const Var& da) + /// Equality operator for comparing Var with UTF16String +{ + if (da.isEmpty()) return false; + return other == da.convert<UTF16String>(); +} + + +inline bool operator != (const UTF16String& other, const Var& da) + /// Inequality operator for comparing Var with UTF16String +{ + if (da.isEmpty()) return true; + return other != da.convert<UTF16String>(); +} + + +inline bool operator == (const char* other, const Var& da) + /// Equality operator for comparing Var with const char* +{ + if (da.isEmpty()) return false; + return da.convert<std::string>() == other; +} + + +inline bool operator != (const char* other, const Var& da) + /// Inequality operator for comparing Var with const char* +{ + if (da.isEmpty()) return true; + return da.convert<std::string>() != other; +} + + +#ifndef POCO_LONG_IS_64_BIT + + +inline long operator + (const long& other, const Var& da) + /// Addition operator for adding Var to long +{ + return other + da.convert<long>(); +} + + +inline long operator - (const long& other, const Var& da) + /// Subtraction operator for subtracting Var from long +{ + return other - da.convert<long>(); +} + + +inline long operator * (const long& other, const Var& da) + /// Multiplication operator for multiplying Var with long +{ + return other * da.convert<long>(); +} + + +inline long operator / (const long& other, const Var& da) + /// Division operator for dividing Var with long +{ + return other / da.convert<long>(); +} + + +inline long operator += (long& other, const Var& da) + /// Addition assignment operator for adding Var to long +{ + return other += da.convert<long>(); +} + + +inline long operator -= (long& other, const Var& da) + /// Subtraction assignment operator for subtracting Var from long +{ + return other -= da.convert<long>(); +} + + +inline long operator *= (long& other, const Var& da) + /// Multiplication assignment operator for multiplying Var with long +{ + return other *= da.convert<long>(); +} + + +inline long operator /= (long& other, const Var& da) + /// Division assignment operator for dividing Var with long +{ + return other /= da.convert<long>(); +} + + +inline bool operator == (const long& other, const Var& da) + /// Equality operator for comparing Var with long +{ + if (da.isEmpty()) return false; + return other == da.convert<long>(); +} + + +inline bool operator != (const long& other, const Var& da) + /// Inequality operator for comparing Var with long +{ + if (da.isEmpty()) return true; + return other != da.convert<long>(); +} + + +inline bool operator < (const long& other, const Var& da) + /// Less than operator for comparing Var with long +{ + if (da.isEmpty()) return false; + return other < da.convert<long>(); +} + + +inline bool operator <= (const long& other, const Var& da) + /// Less than or equal operator for comparing Var with long +{ + if (da.isEmpty()) return false; + return other <= da.convert<long>(); +} + + +inline bool operator > (const long& other, const Var& da) + /// Greater than operator for comparing Var with long +{ + if (da.isEmpty()) return false; + return other > da.convert<long>(); +} + + +inline bool operator >= (const long& other, const Var& da) + /// Greater than or equal operator for comparing Var with long +{ + if (da.isEmpty()) return false; + return other >= da.convert<long>(); +} + + +#endif // POCO_LONG_IS_64_BIT + + +} // namespace Dynamic + + +//@ deprecated +typedef Dynamic::Var DynamicAny; + + +} // namespace Poco + + +#endif // Foundation_Var_INCLUDED diff --git a/contrib/libs/poco/Foundation/include/Poco/Dynamic/VarHolder.h b/contrib/libs/poco/Foundation/include/Poco/Dynamic/VarHolder.h index f378e869fd..85af40f449 100644 --- a/contrib/libs/poco/Foundation/include/Poco/Dynamic/VarHolder.h +++ b/contrib/libs/poco/Foundation/include/Poco/Dynamic/VarHolder.h @@ -1,4213 +1,4213 @@ -// -// VarHolder.h -// -// Library: Foundation -// Package: Dynamic -// Module: VarHolder -// -// Definition of the VarHolder class. -// -// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Foundation_VarHolder_INCLUDED -#define Foundation_VarHolder_INCLUDED - - -#include "Poco/Foundation.h" -#include "Poco/NumberFormatter.h" -#include "Poco/NumberParser.h" -#include "Poco/DateTime.h" -#include "Poco/Timestamp.h" -#include "Poco/LocalDateTime.h" -#include "Poco/DateTimeFormat.h" -#include "Poco/DateTimeFormatter.h" -#include "Poco/DateTimeParser.h" -#include "Poco/String.h" -#include "Poco/UnicodeConverter.h" -#include "Poco/UTFString.h" -#include "Poco/UTF8String.h" -#include "Poco/Any.h" -#include "Poco/Exception.h" -#include <vector> -#include <list> -#include <deque> -#include <typeinfo> -#undef min -#undef max -#include <limits> - - -namespace Poco { -namespace Dynamic { - - -class Var; - - -namespace Impl { - - -bool Foundation_API isJSONString(const Var& any); - /// Returns true for values that should be JSON-formatted as string. - - -void Foundation_API appendJSONKey(std::string& val, const Var& any); - /// Converts the any to a JSON key (i.e. wraps it into double quotes - /// regardless of the underlying type) and appends it to val. - - -void Foundation_API appendJSONString(std::string& val, const Var& any); - /// Converts the any to a JSON string (i.e. wraps it into double quotes) - /// regardless of the underlying type) and appends it to val. - - -void Foundation_API appendJSONValue(std::string& val, const Var& any); - /// Converts the any to a JSON value (if underlying type qualifies - /// as string - see isJSONString() - , it is wrapped into double quotes) - /// and appends it to val - - -template <typename C> -void containerToJSON(C& cont, std::string& val) -{ - // Serialize in JSON format. Note: although this is a vector<T>, the code only - // supports vector<Var>. Total specialization is not possible - // because of the cyclic dependency between Var and VarHolder - - // JSON format definition: [ n times: elem ',' ], no ',' for last elem - val.append("[ "); - typename C::const_iterator it = cont.begin(); - typename C::const_iterator itEnd = cont.end(); - if (!cont.empty()) - { - appendJSONValue(val, *it); - ++it; - } - for (; it != itEnd; ++it) - { - val.append(", "); - appendJSONValue(val, *it); - } - val.append(" ]"); -} - - -} // namespace Impl - - -class Foundation_API VarHolder - /// Interface for a data holder used by the Var class. - /// Provides methods to convert between data types. - /// Only data types for which VarHolder specialization exists are supported. - /// - /// Provided are specializations for all C++ built-in types with addition of - /// std::string, Poco::UTF16String, DateTime, LocalDateTime, Timestamp, std::vector<Var> and DynamicStruct. +// +// VarHolder.h +// +// Library: Foundation +// Package: Dynamic +// Module: VarHolder +// +// Definition of the VarHolder class. +// +// Copyright (c) 2007, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#ifndef Foundation_VarHolder_INCLUDED +#define Foundation_VarHolder_INCLUDED + + +#include "Poco/Foundation.h" +#include "Poco/NumberFormatter.h" +#include "Poco/NumberParser.h" +#include "Poco/DateTime.h" +#include "Poco/Timestamp.h" +#include "Poco/LocalDateTime.h" +#include "Poco/DateTimeFormat.h" +#include "Poco/DateTimeFormatter.h" +#include "Poco/DateTimeParser.h" +#include "Poco/String.h" +#include "Poco/UnicodeConverter.h" +#include "Poco/UTFString.h" +#include "Poco/UTF8String.h" +#include "Poco/Any.h" +#include "Poco/Exception.h" +#include <vector> +#include <list> +#include <deque> +#include <typeinfo> +#undef min +#undef max +#include <limits> + + +namespace Poco { +namespace Dynamic { + + +class Var; + + +namespace Impl { + + +bool Foundation_API isJSONString(const Var& any); + /// Returns true for values that should be JSON-formatted as string. + + +void Foundation_API appendJSONKey(std::string& val, const Var& any); + /// Converts the any to a JSON key (i.e. wraps it into double quotes + /// regardless of the underlying type) and appends it to val. + + +void Foundation_API appendJSONString(std::string& val, const Var& any); + /// Converts the any to a JSON string (i.e. wraps it into double quotes) + /// regardless of the underlying type) and appends it to val. + + +void Foundation_API appendJSONValue(std::string& val, const Var& any); + /// Converts the any to a JSON value (if underlying type qualifies + /// as string - see isJSONString() - , it is wrapped into double quotes) + /// and appends it to val + + +template <typename C> +void containerToJSON(C& cont, std::string& val) +{ + // Serialize in JSON format. Note: although this is a vector<T>, the code only + // supports vector<Var>. Total specialization is not possible + // because of the cyclic dependency between Var and VarHolder + + // JSON format definition: [ n times: elem ',' ], no ',' for last elem + val.append("[ "); + typename C::const_iterator it = cont.begin(); + typename C::const_iterator itEnd = cont.end(); + if (!cont.empty()) + { + appendJSONValue(val, *it); + ++it; + } + for (; it != itEnd; ++it) + { + val.append(", "); + appendJSONValue(val, *it); + } + val.append(" ]"); +} + + +} // namespace Impl + + +class Foundation_API VarHolder + /// Interface for a data holder used by the Var class. + /// Provides methods to convert between data types. + /// Only data types for which VarHolder specialization exists are supported. /// - /// Additional types can be supported by adding specializations. When implementing specializations, - /// the only condition is that they reside in Poco namespace and implement the pure virtual functions - /// clone() and type(). - /// - /// Those conversions that are not implemented shall fail back to this base - /// class implementation. All the convert() function overloads in this class - /// throw BadCastException. -{ -public: - typedef Var ArrayValueType; - - virtual ~VarHolder(); - /// Destroys the VarHolder. - - virtual VarHolder* clone(Placeholder<VarHolder>* pHolder = 0) const = 0; - /// Implementation must implement this function to - /// deep-copy the VarHolder. - /// If small object optimization is enabled (i.e. if - /// POCO_NO_SOO is not defined), VarHolder will be - /// instantiated in-place if it's size is smaller - /// than POCO_SMALL_OBJECT_SIZE. - - virtual const std::type_info& type() const = 0; - /// Implementation must return the type information - /// (typeid) for the stored content. - - virtual void convert(Int8& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(Int16& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(Int32& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(Int64& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(UInt8& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(UInt16& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(UInt32& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(UInt64& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(DateTime& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(LocalDateTime& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(Timestamp& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - -#ifndef POCO_LONG_IS_64_BIT - - void convert(long& val) const; - /// Calls convert(Int32). - - void convert(unsigned long& val) const; - /// Calls convert(UInt32). - -#else - - virtual void convert(long long& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to suport the conversion. - - virtual void convert(unsigned long long & val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to suport the conversion. - -#endif - - virtual void convert(bool& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(float& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(double& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(char& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(std::string& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual void convert(Poco::UTF16String& val) const; - /// Throws BadCastException. Must be overriden in a type - /// specialization in order to support the conversion. - - virtual bool isArray() const; - /// Returns true. - - virtual bool isVector() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isList() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isDeque() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isStruct() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isInteger() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isSigned() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isNumeric() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isBoolean() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isString() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isDate() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isTime() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual bool isDateTime() const; - /// Returns false. Must be properly overriden in a type - /// specialization in order to support the diagnostic. - - virtual std::size_t size() const; - /// Returns 1 iff Var is not empty or this function overriden. - -protected: - VarHolder(); - /// Creates the VarHolder. - - template <typename T> - VarHolder* cloneHolder(Placeholder<VarHolder>* pVarHolder, const T& val) const - /// Instantiates value holder wrapper. If size of the wrapper is - /// larger than POCO_SMALL_OBJECT_SIZE, holder is instantiated on - /// the heap, otherwise it is instantiated in-place (in the - /// pre-allocated buffer inside the holder). - /// - /// Called from clone() member function of the implementation when - /// small object optimization is enabled. - { -#ifdef POCO_NO_SOO - (void)pVarHolder; - return new VarHolderImpl<T>(val); -#else - poco_check_ptr (pVarHolder); - if ((sizeof(VarHolderImpl<T>) <= Placeholder<T>::Size::value)) - { - new ((VarHolder*) pVarHolder->holder) VarHolderImpl<T>(val); - pVarHolder->setLocal(true); - return (VarHolder*) pVarHolder->holder; - } - else - { - pVarHolder->pHolder = new VarHolderImpl<T>(val); - pVarHolder->setLocal(false); - return pVarHolder->pHolder; - } -#endif - } - - template <typename F, typename T> - void convertToSmaller(const F& from, T& to) const - /// This function is meant to convert signed numeric values from - /// larger to smaller type. It checks the upper and lower bound and - /// if from value is within limits of type T (i.e. check calls do not throw), - /// it is converted. - { - poco_static_assert (std::numeric_limits<F>::is_specialized); - poco_static_assert (std::numeric_limits<T>::is_specialized); - poco_static_assert (std::numeric_limits<F>::is_signed); - poco_static_assert (std::numeric_limits<T>::is_signed); - - if (std::numeric_limits<F>::is_integer) - { - checkUpperLimit<F,T>(from); - checkLowerLimit<F,T>(from); - } - else - { - checkUpperLimitFloat<F,T>(from); - checkLowerLimitFloat<F,T>(from); - } - - to = static_cast<T>(from); - } - - template <typename F, typename T> - void convertToSmallerUnsigned(const F& from, T& to) const - /// This function is meant for converting unsigned integral data types, - /// from larger to smaller type. Since lower limit is always 0 for unsigned types, - /// only the upper limit is checked, thus saving some cycles compared to the signed - /// version of the function. If the value to be converted is smaller than - /// the maximum value for the target type, the conversion is performed. - { - poco_static_assert (std::numeric_limits<F>::is_specialized); - poco_static_assert (std::numeric_limits<T>::is_specialized); - poco_static_assert (!std::numeric_limits<F>::is_signed); - poco_static_assert (!std::numeric_limits<T>::is_signed); - - checkUpperLimit<F,T>(from); - to = static_cast<T>(from); - } - - template <typename F, typename T> - void convertSignedToUnsigned(const F& from, T& to) const - /// This function is meant for converting signed integral data types to - /// unsigned data types. Negative values can not be converted and if one - /// is encountered, RangeException is thrown. - /// If upper limit is within the target data type limits, the conversion is performed. - { - poco_static_assert (std::numeric_limits<F>::is_specialized); - poco_static_assert (std::numeric_limits<T>::is_specialized); - poco_static_assert (std::numeric_limits<F>::is_signed); - poco_static_assert (!std::numeric_limits<T>::is_signed); - - if (from < 0) - throw RangeException("Value too small."); - checkUpperLimit<F,T>(from); - to = static_cast<T>(from); - } - - template <typename F, typename T> - void convertSignedFloatToUnsigned(const F& from, T& to) const - /// This function is meant for converting floating point data types to - /// unsigned integral data types. Negative values can not be converted and if one - /// is encountered, RangeException is thrown. - /// If upper limit is within the target data type limits, the conversion is performed. - { - poco_static_assert (std::numeric_limits<F>::is_specialized); - poco_static_assert (std::numeric_limits<T>::is_specialized); - poco_static_assert (!std::numeric_limits<F>::is_integer); - poco_static_assert (std::numeric_limits<T>::is_integer); - poco_static_assert (!std::numeric_limits<T>::is_signed); - - if (from < 0) - throw RangeException("Value too small."); - checkUpperLimitFloat<F,T>(from); - to = static_cast<T>(from); - } - - template <typename F, typename T> - void convertUnsignedToSigned(const F& from, T& to) const - /// This function is meant for converting unsigned integral data types to - /// signed integral data types. Negative values can not be converted and if one - /// is encountered, RangeException is thrown. - /// If upper limit is within the target data type limits, the conversion is performed. - { - poco_static_assert (std::numeric_limits<F>::is_specialized); - poco_static_assert (std::numeric_limits<T>::is_specialized); - poco_static_assert (!std::numeric_limits<F>::is_signed); - poco_static_assert (std::numeric_limits<T>::is_signed); - + /// Provided are specializations for all C++ built-in types with addition of + /// std::string, Poco::UTF16String, DateTime, LocalDateTime, Timestamp, std::vector<Var> and DynamicStruct. + /// + /// Additional types can be supported by adding specializations. When implementing specializations, + /// the only condition is that they reside in Poco namespace and implement the pure virtual functions + /// clone() and type(). + /// + /// Those conversions that are not implemented shall fail back to this base + /// class implementation. All the convert() function overloads in this class + /// throw BadCastException. +{ +public: + typedef Var ArrayValueType; + + virtual ~VarHolder(); + /// Destroys the VarHolder. + + virtual VarHolder* clone(Placeholder<VarHolder>* pHolder = 0) const = 0; + /// Implementation must implement this function to + /// deep-copy the VarHolder. + /// If small object optimization is enabled (i.e. if + /// POCO_NO_SOO is not defined), VarHolder will be + /// instantiated in-place if it's size is smaller + /// than POCO_SMALL_OBJECT_SIZE. + + virtual const std::type_info& type() const = 0; + /// Implementation must return the type information + /// (typeid) for the stored content. + + virtual void convert(Int8& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(Int16& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(Int32& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(Int64& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(UInt8& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(UInt16& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(UInt32& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(UInt64& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(DateTime& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(LocalDateTime& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(Timestamp& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + +#ifndef POCO_LONG_IS_64_BIT + + void convert(long& val) const; + /// Calls convert(Int32). + + void convert(unsigned long& val) const; + /// Calls convert(UInt32). + +#else + + virtual void convert(long long& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to suport the conversion. + + virtual void convert(unsigned long long & val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to suport the conversion. + +#endif + + virtual void convert(bool& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(float& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(double& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(char& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(std::string& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual void convert(Poco::UTF16String& val) const; + /// Throws BadCastException. Must be overriden in a type + /// specialization in order to support the conversion. + + virtual bool isArray() const; + /// Returns true. + + virtual bool isVector() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isList() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isDeque() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isStruct() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isInteger() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isSigned() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isNumeric() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isBoolean() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isString() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isDate() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isTime() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual bool isDateTime() const; + /// Returns false. Must be properly overriden in a type + /// specialization in order to support the diagnostic. + + virtual std::size_t size() const; + /// Returns 1 iff Var is not empty or this function overriden. + +protected: + VarHolder(); + /// Creates the VarHolder. + + template <typename T> + VarHolder* cloneHolder(Placeholder<VarHolder>* pVarHolder, const T& val) const + /// Instantiates value holder wrapper. If size of the wrapper is + /// larger than POCO_SMALL_OBJECT_SIZE, holder is instantiated on + /// the heap, otherwise it is instantiated in-place (in the + /// pre-allocated buffer inside the holder). + /// + /// Called from clone() member function of the implementation when + /// small object optimization is enabled. + { +#ifdef POCO_NO_SOO + (void)pVarHolder; + return new VarHolderImpl<T>(val); +#else + poco_check_ptr (pVarHolder); + if ((sizeof(VarHolderImpl<T>) <= Placeholder<T>::Size::value)) + { + new ((VarHolder*) pVarHolder->holder) VarHolderImpl<T>(val); + pVarHolder->setLocal(true); + return (VarHolder*) pVarHolder->holder; + } + else + { + pVarHolder->pHolder = new VarHolderImpl<T>(val); + pVarHolder->setLocal(false); + return pVarHolder->pHolder; + } +#endif + } + + template <typename F, typename T> + void convertToSmaller(const F& from, T& to) const + /// This function is meant to convert signed numeric values from + /// larger to smaller type. It checks the upper and lower bound and + /// if from value is within limits of type T (i.e. check calls do not throw), + /// it is converted. + { + poco_static_assert (std::numeric_limits<F>::is_specialized); + poco_static_assert (std::numeric_limits<T>::is_specialized); + poco_static_assert (std::numeric_limits<F>::is_signed); + poco_static_assert (std::numeric_limits<T>::is_signed); + + if (std::numeric_limits<F>::is_integer) + { + checkUpperLimit<F,T>(from); + checkLowerLimit<F,T>(from); + } + else + { + checkUpperLimitFloat<F,T>(from); + checkLowerLimitFloat<F,T>(from); + } + + to = static_cast<T>(from); + } + + template <typename F, typename T> + void convertToSmallerUnsigned(const F& from, T& to) const + /// This function is meant for converting unsigned integral data types, + /// from larger to smaller type. Since lower limit is always 0 for unsigned types, + /// only the upper limit is checked, thus saving some cycles compared to the signed + /// version of the function. If the value to be converted is smaller than + /// the maximum value for the target type, the conversion is performed. + { + poco_static_assert (std::numeric_limits<F>::is_specialized); + poco_static_assert (std::numeric_limits<T>::is_specialized); + poco_static_assert (!std::numeric_limits<F>::is_signed); + poco_static_assert (!std::numeric_limits<T>::is_signed); + checkUpperLimit<F,T>(from); - to = static_cast<T>(from); - } - -private: - -#ifdef _MSC_VER -#pragma warning( push ) -#pragma warning( disable : 4127 ) -#pragma warning( disable : 4018 ) -#endif - - template <typename F, typename T> - void checkUpperLimit(const F& from) const - { - // casting to type of smaller size AND - // 'from' is greater than 'T' max value - if ((sizeof(T) < sizeof(F)) && - (from > static_cast<F>(std::numeric_limits<T>::max()))) - { - throw RangeException("Value too large."); - } - // casting to type of equal/bigger size AND - // 'F' is signed AND - // 'T' is unsigned AND - // 'from' is negative - else if (std::numeric_limits<F>::is_signed && - !std::numeric_limits<T>::is_signed && from < 0) - { - throw RangeException("Value too small."); - } - // casting to type of equal/bigger size AND - // 'F' is unsigned AND - // 'T' is signed AND - // 'from' is greater than 'T' max value - else if (!std::numeric_limits<F>::is_signed && - std::numeric_limits<T>::is_signed && - static_cast<Poco::UInt64>(from) > std::numeric_limits<T>::max()) - { - throw RangeException("Value too large."); - } - } - -#ifdef _MSC_VER -#pragma warning( pop ) -#endif - - template <typename F, typename T> - void checkUpperLimitFloat(const F& from) const - { - if (from > std::numeric_limits<T>::max()) - throw RangeException("Value too large."); - } - - template <typename F, typename T> - void checkLowerLimitFloat(const F& from) const - { - if (from < -std::numeric_limits<T>::max()) - throw RangeException("Value too small."); - } - - template <typename F, typename T> - void checkLowerLimit(const F& from) const - { - if (from < std::numeric_limits<T>::min()) - throw RangeException("Value too small."); - } -}; - - -// -// inlines -// - - -inline void VarHolder::convert(Int8& /*val*/) const -{ - throw BadCastException("Can not convert to Int8"); -} - - -inline void VarHolder::convert(Int16& /*val*/) const -{ - throw BadCastException("Can not convert to Int16"); -} - - -inline void VarHolder::convert(Int32& /*val*/) const -{ - throw BadCastException("Can not convert to Int32"); -} - - -inline void VarHolder::convert(Int64& /*val*/) const -{ - throw BadCastException("Can not convert to Int64"); -} - - -inline void VarHolder::convert(UInt8& /*val*/) const -{ - throw BadCastException("Can not convert to UInt8"); -} - - -inline void VarHolder::convert(UInt16& /*val*/) const -{ - throw BadCastException("Can not convert to UInt16"); -} - - -inline void VarHolder::convert(UInt32& /*val*/) const -{ - throw BadCastException("Can not convert to UInt32"); -} - - -inline void VarHolder::convert(UInt64& /*val*/) const -{ - throw BadCastException("Can not convert to UInt64"); -} - - -inline void VarHolder::convert(DateTime& /*val*/) const -{ - throw BadCastException("Can not convert to DateTime"); -} - - -inline void VarHolder::convert(LocalDateTime& /*val*/) const -{ - throw BadCastException("Can not convert to LocalDateTime"); -} - - -inline void VarHolder::convert(Timestamp& /*val*/) const -{ - throw BadCastException("Can not convert to Timestamp"); -} - -#ifndef POCO_LONG_IS_64_BIT - -inline void VarHolder::convert(long& val) const -{ - Int32 tmp; - convert(tmp); - val = tmp; -} - - -inline void VarHolder::convert(unsigned long& val) const -{ - UInt32 tmp; - convert(tmp); - val = tmp; -} - -#else - -inline void VarHolder::convert(long long& /*val*/) const -{ - throw BadCastException("Can not convert to long long"); -} - - -inline void VarHolder::convert(unsigned long long& /*val*/) const -{ - throw BadCastException("Can not convert to unsigned long long"); -} - -#endif - -inline void VarHolder::convert(bool& /*val*/) const -{ - throw BadCastException("Can not convert to bool"); -} - - -inline void VarHolder::convert(float& /*val*/) const -{ - throw BadCastException("Can not convert to float"); -} - - -inline void VarHolder::convert(double& /*val*/) const -{ - throw BadCastException("Can not convert to double"); -} - - -inline void VarHolder::convert(char& /*val*/) const -{ - throw BadCastException("Can not convert to char"); -} - - -inline void VarHolder::convert(std::string& /*val*/) const -{ - throw BadCastException("Can not convert to std::string"); -} - - -inline void VarHolder::convert(Poco::UTF16String& /*val*/) const -{ - throw BadCastException("Can not convert to Poco::UTF16String"); -} - - -inline bool VarHolder::isArray() const -{ - return true; -} - - -inline bool VarHolder::isVector() const -{ - return false; -} - - -inline bool VarHolder::isList() const -{ - return false; -} - - -inline bool VarHolder::isDeque() const -{ - return false; -} - - -inline bool VarHolder::isStruct() const -{ - return false; -} - -inline bool VarHolder::isInteger() const -{ - return false; -} - - -inline bool VarHolder::isSigned() const -{ - return false; -} - - -inline bool VarHolder::isNumeric() const -{ - return false; -} - - -inline bool VarHolder::isBoolean() const -{ - return false; -} - - -inline bool VarHolder::isString() const -{ - return false; -} - - -inline bool VarHolder::isDate() const -{ - return false; -} - - -inline bool VarHolder::isTime() const -{ - return false; -} - - -inline bool VarHolder::isDateTime() const -{ - return false; -} - -inline std::size_t VarHolder::size() const -{ - return 1u; -} - - -template <typename T> -class VarHolderImpl: public VarHolder - /// Template based implementation of a VarHolder. - /// This class provides type storage for user-defined types - /// that do not have VarHolderImpl specialization. - /// - /// The actual conversion work happens in the template specializations - /// of this class. - /// - /// VarHolderImpl throws following exceptions: - /// BadCastException (if the requested conversion is not implemented) - /// RangeException (if an attempt is made to assign a numeric value outside of the target min/max limits - /// SyntaxException (if an attempt is made to convert a string containing non-numeric characters to number) - /// - /// In order to support efficient direct extraction of the held value, - /// all specializations must additionally implement a public member function: - /// - /// const T& value() const - /// - /// returning a const reference to the actual stored value. -{ -public: - VarHolderImpl(const T& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(T); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const T& value() const - { - return _val; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - T _val; -}; - - -template <> -class VarHolderImpl<Int8>: public VarHolder -{ -public: - VarHolderImpl(Int8 val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Int8); - } - - void convert(Int8& val) const - { - val = _val; - } - - void convert(Int16& val) const - { - val = _val; - } - - void convert(Int32& val) const - { - val = _val; - } - - void convert(Int64& val) const - { - val = _val; - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = _val; - } - - void convert(unsigned long long& val) const - { - convertSignedToUnsigned(_val, val); - } - -#endif - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - val = static_cast<char>(_val); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - void convert(Poco::UTF16String& val) const - { - std::string str = NumberFormatter::format(_val); - Poco::UnicodeConverter::convert(str, val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const Int8& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<Int8>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<Int8>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<Int8>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - Int8 _val; -}; - - -template <> -class VarHolderImpl<Int16>: public VarHolder -{ -public: - VarHolderImpl(Int16 val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Int16); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - val = _val; - } - - void convert(Int32& val) const - { - val = _val; - } - - void convert(Int64& val) const - { - val = _val; - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = _val; - } - - void convert(unsigned long long& val) const - { - convertSignedToUnsigned(_val, val); - } - -#endif - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - void convert(Poco::UTF16String& val) const - { - std::string str = NumberFormatter::format(_val); - Poco::UnicodeConverter::convert(str, val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const Int16& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<Int16>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<Int16>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<Int16>::is_specialized; - } - - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - Int16 _val; -}; - - -template <> -class VarHolderImpl<Int32>: public VarHolder -{ -public: - VarHolderImpl(Int32 val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Int32); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - val = _val; - } - - void convert(Int64& val) const - { - val = _val; - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = _val; - } - - void convert(unsigned long long& val) const - { - convertSignedToUnsigned(_val, val); - } - -#endif - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const Int32& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<Int32>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<Int32>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<Int32>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - Int32 _val; -}; - - -template <> -class VarHolderImpl<Int64>: public VarHolder -{ -public: - VarHolderImpl(Int64 val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Int64); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int64& val) const - { - val = _val; - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = _val; - } - - void convert(unsigned long long& val) const - { - convertSignedToUnsigned(_val, val); - } - -#endif - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - void convert(DateTime& dt) const - { - dt = Timestamp(_val); - } - - void convert(LocalDateTime& ldt) const - { - ldt = Timestamp(_val); - } - - void convert(Timestamp& val) const - { - val = Timestamp(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const Int64& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<Int64>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<Int64>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<Int64>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - Int64 _val; -}; - - -template <> -class VarHolderImpl<UInt8>: public VarHolder -{ -public: - VarHolderImpl(UInt8 val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(UInt8); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - val = static_cast<Int32>(_val); - } - - void convert(Int64& val) const - { - val = static_cast<Int64>(_val); - } - - void convert(UInt8& val) const - { - val = _val; - } - - void convert(UInt16& val) const - { - val = _val; - } - - void convert(UInt32& val) const - { - val = _val; - } - - void convert(UInt64& val) const - { - val = _val; - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = static_cast<long long>(_val); - } - - void convert(unsigned long long& val) const - { - val = _val; - } - -#endif - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const UInt8& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<UInt8>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<UInt8>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<UInt8>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - UInt8 _val; -}; - - -template <> -class VarHolderImpl<UInt16>: public VarHolder -{ -public: - VarHolderImpl(UInt16 val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(UInt16); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int64& val) const - { - val = static_cast<Int64>(_val); - } - - void convert(UInt8& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - val = _val; - } - - void convert(UInt32& val) const - { - val = _val; - } - - void convert(UInt64& val) const - { - val = _val; - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = static_cast<long long>(_val); - } - - void convert(unsigned long long& val) const - { - val = _val; - } - -#endif - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const UInt16& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<UInt16>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<UInt16>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<UInt16>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - UInt16 _val; -}; - - -template <> -class VarHolderImpl<UInt32>: public VarHolder -{ -public: - VarHolderImpl(UInt32 val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(UInt32); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int64& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(UInt8& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - val = _val; - } - - void convert(UInt64& val) const - { - val = _val; - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(unsigned long long& val) const - { - val = _val; - } - -#endif - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const UInt32& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<UInt32>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<UInt32>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<UInt32>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - UInt32 _val; -}; - - -template <> -class VarHolderImpl<UInt64>: public VarHolder -{ -public: - VarHolderImpl(UInt64 val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(UInt64); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int64& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(UInt8& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - val = _val; - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(unsigned long long& val) const - { - val = _val; - } - -#endif - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - void convert(DateTime& dt) const - { - Int64 val; - convertUnsignedToSigned(_val, val); - dt = Timestamp(val); - } - - void convert(LocalDateTime& ldt) const - { - Int64 val; - convertUnsignedToSigned(_val, val); - ldt = Timestamp(val); - } - - void convert(Timestamp& val) const - { - Int64 tmp; - convertUnsignedToSigned(_val, tmp); - val = Timestamp(tmp); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const UInt64& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<UInt64>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<UInt64>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<UInt64>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - UInt64 _val; -}; - - -template <> -class VarHolderImpl<bool>: public VarHolder -{ -public: - VarHolderImpl(bool val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(bool); - } - - void convert(Int8& val) const - { - val = static_cast<Int8>(_val ? 1 : 0); - } - - void convert(Int16& val) const - { - val = static_cast<Int16>(_val ? 1 : 0); - } - - void convert(Int32& val) const - { - val = static_cast<Int32>(_val ? 1 : 0); - } - - void convert(Int64& val) const - { - val = static_cast<Int64>(_val ? 1 : 0); - } - - void convert(UInt8& val) const - { - val = static_cast<UInt8>(_val ? 1 : 0); - } - - void convert(UInt16& val) const - { - val = static_cast<UInt16>(_val ? 1 : 0); - } - - void convert(UInt32& val) const - { - val = static_cast<UInt32>(_val ? 1 : 0); - } - - void convert(UInt64& val) const - { - val = static_cast<UInt64>(_val ? 1 : 0); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = static_cast<long long>(_val ? 1 : 0); - } - - void convert(unsigned long long& val) const - { - val = static_cast<unsigned long long>(_val ? 1 : 0); - } - -#endif - - void convert(bool& val) const - { - val = _val; - } - - void convert(float& val) const - { - val = (_val ? 1.0f : 0.0f); - } - - void convert(double& val) const - { - val = (_val ? 1.0 : 0.0); - } - - void convert(char& val) const - { - val = static_cast<char>(_val ? 1 : 0); - } - - void convert(std::string& val) const - { - val = (_val ? "true" : "false"); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const bool& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<bool>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<bool>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<bool>::is_specialized; - } - - bool isBoolean() const - { - return true; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - bool _val; -}; - - -template <> -class VarHolderImpl<float>: public VarHolder -{ -public: - VarHolderImpl(float val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(float); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int64& val) const - { - convertToSmaller(_val, val); - } - - void convert(UInt8& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - convertToSmaller(_val, val); - } - - void convert(unsigned long long& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - -#endif - - void convert(bool& val) const - { - val = !(_val <= std::numeric_limits<float>::min() && - _val >= -1 * std::numeric_limits<float>::min()); - } - - void convert(float& val) const - { - val = _val; - } - - void convert(double& val) const - { - val = _val; - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const float& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<float>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<float>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<float>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - float _val; -}; - - -template <> -class VarHolderImpl<double>: public VarHolder -{ -public: - VarHolderImpl(double val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(double); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int64& val) const - { - convertToSmaller(_val, val); - } - - void convert(UInt8& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - convertToSmaller(_val, val); - } - - void convert(unsigned long long& val) const - { - convertSignedFloatToUnsigned(_val, val); - } - -#endif - - void convert(bool& val) const - { - val = !(_val <= std::numeric_limits<double>::min() && - _val >= -1 * std::numeric_limits<double>::min()); - } - - void convert(float& val) const - { - double fMin = -1 * std::numeric_limits<float>::max(); - double fMax = std::numeric_limits<float>::max(); - - if (_val < fMin) throw RangeException("Value too small."); - if (_val > fMax) throw RangeException("Value too large."); - - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = _val; - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const double& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<double>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<double>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<double>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - double _val; -}; - - -template <> -class VarHolderImpl<char>: public VarHolder -{ -public: - VarHolderImpl(char val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(char); - } - - void convert(Int8& val) const - { - val = static_cast<Int8>(_val); - } - - void convert(Int16& val) const - { - val = static_cast<UInt8>(_val); - } - - void convert(Int32& val) const - { - val = static_cast<UInt8>(_val); - } - - void convert(Int64& val) const - { - val = static_cast<UInt8>(_val); - } - - void convert(UInt8& val) const - { - val = static_cast<UInt8>(_val); - } - - void convert(UInt16& val) const - { - val = static_cast<UInt8>(_val); - } - - void convert(UInt32& val) const - { - val = static_cast<UInt8>(_val); - } - - void convert(UInt64& val) const - { - val = static_cast<UInt8>(_val); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = static_cast<long long>(_val); - } - - void convert(unsigned long long& val) const - { - val = static_cast<unsigned long long>(_val); - } - -#endif - - void convert(bool& val) const - { - val = (_val != '\0'); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - val = _val; - } - - void convert(std::string& val) const - { - val = std::string(1, _val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const char& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<char>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<char>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<char>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - char _val; -}; - - -template <> -class VarHolderImpl<std::string>: public VarHolder -{ -public: - VarHolderImpl(const char* pVal): _val(pVal) - { - } - - VarHolderImpl(const std::string& val) : _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(std::string); - } - - void convert(Int8& val) const - { - int v = NumberParser::parse(_val); - convertToSmaller(v, val); - } - - void convert(Int16& val) const - { - int v = NumberParser::parse(_val); - convertToSmaller(v, val); - } - - void convert(Int32& val) const - { - val = NumberParser::parse(_val); - } - - void convert(Int64& val) const - { - val = NumberParser::parse64(_val); - } - - void convert(UInt8& val) const - { - unsigned int v = NumberParser::parseUnsigned(_val); - convertToSmallerUnsigned(v, val); - } - - void convert(UInt16& val) const - { - unsigned int v = NumberParser::parseUnsigned(_val); - convertToSmallerUnsigned(v, val); - } - - void convert(UInt32& val) const - { - val = NumberParser::parseUnsigned(_val); - } - - void convert(UInt64& val) const - { - val = NumberParser::parseUnsigned64(_val); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = NumberParser::parse64(_val); - } - - void convert(unsigned long long& val) const - { - val = NumberParser::parseUnsigned64(_val); - } - -#endif - - void convert(bool& val) const - { - if (_val.empty()) - { - val = false; - return; - } - - static const std::string VAL_FALSE("false"); - static const std::string VAL_INT_FALSE("0"); - val = (_val != VAL_INT_FALSE && - (icompare(_val, VAL_FALSE) != 0)); - } - - void convert(float& val) const - { - double v = NumberParser::parseFloat(_val); - convertToSmaller(v, val); - } - - void convert(double& val) const - { - val = NumberParser::parseFloat(_val); - } - - void convert(char& val) const - { - if (_val.empty()) - val = '\0'; - else - val = _val[0]; - } - - void convert(std::string& val) const - { - val = _val; - } - - void convert(Poco::UTF16String& val) const - { - Poco::UnicodeConverter::convert(_val, val); - } - - void convert(DateTime& val) const - { - int tzd = 0; - if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, val, tzd)) - throw BadCastException("string -> DateTime"); - } - - void convert(LocalDateTime& ldt) const - { - int tzd = 0; - DateTime tmp; - if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, tmp, tzd)) - throw BadCastException("string -> LocalDateTime"); - - ldt = LocalDateTime(tzd, tmp, false); - } - - void convert(Timestamp& ts) const - { - int tzd = 0; - DateTime tmp; - if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, tmp, tzd)) - throw BadCastException("string -> Timestamp"); - - ts = tmp.timestamp(); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const std:: string& value() const - { - return _val; - } - - bool isString() const - { - return true; - } - - std::size_t size() const - { - return _val.length(); - } - - char& operator[](std::string::size_type n) - { - if (n < size()) return _val.operator[](n); - - throw RangeException("String index out of range"); - } - - const char& operator[](std::string::size_type n) const - { - if (n < size()) return _val.operator[](n); - - throw RangeException("String index out of range"); - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - std::string _val; -}; - - -template <> -class VarHolderImpl<UTF16String>: public VarHolder -{ -public: - VarHolderImpl(const char* pVal) : _val(Poco::UnicodeConverter::to<UTF16String>(pVal)) - { - } - - VarHolderImpl(const Poco::UTF16String& val) : _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Poco::UTF16String); - } - - void convert(Int8& val) const - { - int v = NumberParser::parse(toStdString()); - convertToSmaller(v, val); - } - - void convert(Int16& val) const - { - int v = NumberParser::parse(toStdString()); - convertToSmaller(v, val); - } - - void convert(Int32& val) const - { - val = NumberParser::parse(toStdString()); - } - - void convert(Int64& val) const - { - val = NumberParser::parse64(toStdString()); - } - - void convert(UInt8& val) const - { - unsigned int v = NumberParser::parseUnsigned(toStdString()); - convertToSmallerUnsigned(v, val); - } - - void convert(UInt16& val) const - { - unsigned int v = NumberParser::parseUnsigned(toStdString()); - convertToSmallerUnsigned(v, val); - } - - void convert(UInt32& val) const - { - val = NumberParser::parseUnsigned(toStdString()); - } - - void convert(UInt64& val) const - { - val = NumberParser::parseUnsigned64(toStdString()); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = NumberParser::parse64(toStdString()); - } - - void convert(unsigned long long& val) const - { - val = NumberParser::parseUnsigned64(toStdString()); - } - -#endif - - void convert(bool& val) const - { - static const std::string VAL_FALSE("false"); - static const std::string VAL_INT_FALSE("0"); - - if (_val.empty()) val = false; - - std::string str; - UnicodeConverter::convert(_val, str); - val = (str != VAL_INT_FALSE && - (icompare(str, VAL_FALSE) != 0)); - } - - void convert(float& val) const - { - double v = NumberParser::parseFloat(toStdString()); - convertToSmaller(v, val); - } - - void convert(double& val) const - { - val = NumberParser::parseFloat(toStdString()); - } - - void convert(char& val) const - { - if (_val.empty()) - val = '\0'; - else - { - std::string s; - UnicodeConverter::convert(_val, s); - val = s[0]; - } - } - - void convert(Poco::UTF16String& val) const - { - val = _val; - } - - void convert(std::string& val) const - { - UnicodeConverter::convert(_val, val); - } - - void convert(DateTime& val) const - { - int tzd = 0; - if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, toStdString(), val, tzd)) - throw BadCastException("string -> DateTime"); - } - - void convert(LocalDateTime& ldt) const - { - int tzd = 0; - DateTime tmp; - if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, toStdString(), tmp, tzd)) - throw BadCastException("string -> LocalDateTime"); - - ldt = LocalDateTime(tzd, tmp, false); - } - - void convert(Timestamp& ts) const - { - int tzd = 0; - DateTime tmp; - if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, toStdString(), tmp, tzd)) - throw BadCastException("string -> Timestamp"); - - ts = tmp.timestamp(); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const Poco::UTF16String& value() const - { - return _val; - } - - bool isString() const - { - return true; - } - - std::size_t size() const - { - return _val.length(); - } - - UTF16Char& operator[](Poco::UTF16String::size_type n) - { - if (n < size()) return _val.operator[](n); - - throw RangeException("String index out of range"); - } - - const UTF16Char& operator[](Poco::UTF16String::size_type n) const - { - if (n < size()) return _val.operator[](n); - - throw RangeException("String index out of range"); - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - std::string toStdString() const - { - std::string str; - UnicodeConverter::convert(_val, str); - return str; - } - - Poco::UTF16String _val; -}; - - -#ifndef POCO_LONG_IS_64_BIT - - -template <> -class VarHolderImpl<long>: public VarHolder -{ -public: - VarHolderImpl(long val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(long); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - val = static_cast<Int32>(_val); - } - - void convert(Int64& val) const - { - val = static_cast<Int64>(_val); - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const long& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<long>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<long>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<long>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - long _val; -}; - - -template <> -class VarHolderImpl<unsigned long>: public VarHolder -{ -public: - VarHolderImpl(unsigned long val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(unsigned long); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int64& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(UInt8& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - val = static_cast<UInt64>(_val); - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const unsigned long& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<unsigned long>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<unsigned long>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<unsigned long>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - unsigned long _val; -}; - - -#else // if defined (POCO_LONG_IS_64_BIT) - - -template <> -class VarHolderImpl<long long>: public VarHolder -{ -public: - VarHolderImpl(long long val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(long long); - } - - void convert(Int8& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int16& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int32& val) const - { - convertToSmaller(_val, val); - } - - void convert(Int64& val) const - { - val = static_cast<Int64>(_val); - } - - void convert(UInt8& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(long long& val) const - { - val = _val; - } - - void convert(unsigned long long& val) const - { - convertSignedToUnsigned(_val, val); - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const long long& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<long long>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<long long>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<long long>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - long long _val; -}; - - -template <> -class VarHolderImpl<unsigned long long>: public VarHolder -{ -public: - VarHolderImpl(unsigned long long val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(unsigned long long); - } - - void convert(Int8& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int16& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int32& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(Int64& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(UInt8& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt16& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt32& val) const - { - convertToSmallerUnsigned(_val, val); - } - - void convert(UInt64& val) const - { - val = static_cast<UInt64>(_val); - } - - void convert(long long& val) const - { - convertUnsignedToSigned(_val, val); - } - - void convert(unsigned long long& val) const - { - val = _val; - } - - void convert(bool& val) const - { - val = (_val != 0); - } - - void convert(float& val) const - { - val = static_cast<float>(_val); - } - - void convert(double& val) const - { - val = static_cast<double>(_val); - } - - void convert(char& val) const - { - UInt8 tmp; - convert(tmp); - val = static_cast<char>(tmp); - } - - void convert(std::string& val) const - { - val = NumberFormatter::format(_val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const unsigned long long& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return std::numeric_limits<unsigned long long>::is_integer; - } - - bool isSigned() const - { - return std::numeric_limits<unsigned long long>::is_signed; - } - - bool isNumeric() const - { - return std::numeric_limits<unsigned long long>::is_specialized; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - unsigned long long _val; -}; - - -#endif // 64bit - - -template <typename T> -class VarHolderImpl<std::vector<T> >: public VarHolder -{ -public: - VarHolderImpl(const std::vector<T>& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(std::vector<T>); - } - - void convert(std::string& val) const - { - Impl::containerToJSON(_val, val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const std::vector<T>& value() const - { - return _val; - } - - bool isVector() const - { - return true; - } - - std::size_t size() const - { - return _val.size(); - } - - T& operator[](typename std::vector<T>::size_type n) - { - if (n < size()) return _val.operator[](n); - - throw RangeException("List index out of range"); - } - - const T& operator[](typename std::vector<T>::size_type n) const - { - if (n < size()) return _val.operator[](n); - - throw RangeException("List index out of range"); - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - std::vector<T> _val; -}; - - -template <typename T> -class VarHolderImpl<std::list<T> >: public VarHolder -{ -public: - VarHolderImpl(const std::list<T>& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(std::list<T>); - } - - void convert(std::string& val) const - { - Impl::containerToJSON(_val, val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const std::list<T>& value() const - { - return _val; - } - - bool isList() const - { - return true; - } - - std::size_t size() const - { - return _val.size(); - } - - T& operator[](typename std::list<T>::size_type n) - { - if (n >= size()) - throw RangeException("List index out of range"); - - typename std::list<T>::size_type counter = 0; - typename std::list<T>::iterator it = _val.begin(); - for (; counter < n; ++counter) ++it; - - return *it; - } - - const T& operator[](typename std::list<T>::size_type n) const - { - if (n >= size()) - throw RangeException("List index out of range"); - - typename std::list<T>::size_type counter = 0; - typename std::list<T>::const_iterator it = _val.begin(); - for (; counter < n; ++counter) ++it; - - return *it; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - std::list<T> _val; -}; - - -template <typename T> -class VarHolderImpl<std::deque<T> >: public VarHolder -{ -public: - VarHolderImpl(const std::deque<T>& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(std::deque<T>); - } - - void convert(std::string& val) const - { - Impl::containerToJSON(_val, val); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const std::deque<T>& value() const - { - return _val; - } - - bool isDeque() const - { - return true; - } - - std::size_t size() const - { - return _val.size(); - } - - T& operator[](typename std::deque<T>::size_type n) - { - if (n < size()) return _val.operator[](n); - - throw RangeException("List index out of range"); - } - - const T& operator[](typename std::deque<T>::size_type n) const - { - if (n < size()) return _val.operator[](n); - - throw RangeException("List index out of range"); - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - std::deque<T> _val; -}; - - -template <> -class VarHolderImpl<DateTime>: public VarHolder -{ -public: - VarHolderImpl(const DateTime& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(DateTime); - } - - void convert(Int8& /*val*/) const - { - throw BadCastException(); - } - - void convert(Int16& /*val*/) const - { - throw BadCastException(); - } - - void convert(Int32& /*val*/) const - { - throw BadCastException(); - } - - void convert(Int64& val) const - { - val = _val.timestamp().epochMicroseconds(); - } - - void convert(UInt64& val) const - { - val = _val.timestamp().epochMicroseconds(); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = _val.timestamp().epochMicroseconds(); - } - - void convert(unsigned long long& val) const - { - val = _val.timestamp().epochMicroseconds(); - } - -#endif - - void convert(std::string& val) const - { - val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT); - } - - void convert(DateTime& val) const - { - val = _val; - } - - void convert(LocalDateTime& ldt) const - { - ldt = _val.timestamp(); - } - - void convert(Timestamp& ts) const - { - ts = _val.timestamp(); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const DateTime& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - - bool isDate() const - { - return true; - } - - bool isTime() const - { - return true; - } - - bool isDateTime() const - { - return true; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - DateTime _val; -}; - - -template <> -class VarHolderImpl<LocalDateTime>: public VarHolder -{ -public: - VarHolderImpl(const LocalDateTime& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(LocalDateTime); - } - - void convert(Int64& val) const - { - val = _val.timestamp().epochMicroseconds(); - } - - void convert(UInt64& val) const - { - val = _val.timestamp().epochMicroseconds(); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = _val.timestamp().epochMicroseconds(); - } - - void convert(unsigned long long& val) const - { - val = _val.timestamp().epochMicroseconds(); - } - -#endif - - void convert(std::string& val) const - { - val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT); - } - - void convert(DateTime& val) const - { - val = _val.timestamp(); - } - - void convert(LocalDateTime& ldt) const - { - ldt = _val; - } - - void convert(Timestamp& ts) const - { - ts = _val.timestamp(); - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const LocalDateTime& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - - bool isDate() const - { - return true; - } - - bool isTime() const - { - return true; - } - - bool isDateTime() const - { - return true; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - LocalDateTime _val; -}; - - -template <> -class VarHolderImpl<Timestamp>: public VarHolder -{ -public: - VarHolderImpl(const Timestamp& val): _val(val) - { - } - - ~VarHolderImpl() - { - } - - const std::type_info& type() const - { - return typeid(Timestamp); - } - - void convert(Int64& val) const - { - val = _val.epochMicroseconds(); - } - - void convert(UInt64& val) const - { - val = _val.epochMicroseconds(); - } - -#ifdef POCO_LONG_IS_64_BIT - - void convert(long long& val) const - { - val = _val.epochMicroseconds(); - } - - void convert(unsigned long long& val) const - { - val = _val.epochMicroseconds(); - } - -#endif - - void convert(std::string& val) const - { - val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT); - } - - void convert(DateTime& val) const - { - val = _val; - } - - void convert(LocalDateTime& ldt) const - { - ldt = _val; - } - - void convert(Timestamp& ts) const - { - ts = _val; - } - - VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const - { - return cloneHolder(pVarHolder, _val); - } - - const Timestamp& value() const - { - return _val; - } - - bool isArray() const - { - return false; - } - - bool isStruct() const - { - return false; - } - - bool isInteger() const - { - return false; - } - - bool isSigned() const - { - return false; - } - - bool isNumeric() const - { - return false; - } - - bool isBoolean() const - { - return false; - } - - bool isString() const - { - return false; - } - - bool isDate() const - { - return true; - } - - bool isTime() const - { - return true; - } - - bool isDateTime() const - { - return true; - } - -private: - VarHolderImpl(); - VarHolderImpl(const VarHolderImpl&); - VarHolderImpl& operator = (const VarHolderImpl&); - - Timestamp _val; -}; - - -typedef std::vector<Var> Vector; -typedef std::deque<Var> Deque; -typedef std::list<Var> List; -typedef Vector Array; - - -} } // namespace Poco::Dynamic - - -#endif // Foundation_VarHolder_INCLUDED + to = static_cast<T>(from); + } + + template <typename F, typename T> + void convertSignedToUnsigned(const F& from, T& to) const + /// This function is meant for converting signed integral data types to + /// unsigned data types. Negative values can not be converted and if one + /// is encountered, RangeException is thrown. + /// If upper limit is within the target data type limits, the conversion is performed. + { + poco_static_assert (std::numeric_limits<F>::is_specialized); + poco_static_assert (std::numeric_limits<T>::is_specialized); + poco_static_assert (std::numeric_limits<F>::is_signed); + poco_static_assert (!std::numeric_limits<T>::is_signed); + + if (from < 0) + throw RangeException("Value too small."); + checkUpperLimit<F,T>(from); + to = static_cast<T>(from); + } + + template <typename F, typename T> + void convertSignedFloatToUnsigned(const F& from, T& to) const + /// This function is meant for converting floating point data types to + /// unsigned integral data types. Negative values can not be converted and if one + /// is encountered, RangeException is thrown. + /// If upper limit is within the target data type limits, the conversion is performed. + { + poco_static_assert (std::numeric_limits<F>::is_specialized); + poco_static_assert (std::numeric_limits<T>::is_specialized); + poco_static_assert (!std::numeric_limits<F>::is_integer); + poco_static_assert (std::numeric_limits<T>::is_integer); + poco_static_assert (!std::numeric_limits<T>::is_signed); + + if (from < 0) + throw RangeException("Value too small."); + checkUpperLimitFloat<F,T>(from); + to = static_cast<T>(from); + } + + template <typename F, typename T> + void convertUnsignedToSigned(const F& from, T& to) const + /// This function is meant for converting unsigned integral data types to + /// signed integral data types. Negative values can not be converted and if one + /// is encountered, RangeException is thrown. + /// If upper limit is within the target data type limits, the conversion is performed. + { + poco_static_assert (std::numeric_limits<F>::is_specialized); + poco_static_assert (std::numeric_limits<T>::is_specialized); + poco_static_assert (!std::numeric_limits<F>::is_signed); + poco_static_assert (std::numeric_limits<T>::is_signed); + + checkUpperLimit<F,T>(from); + to = static_cast<T>(from); + } + +private: + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable : 4127 ) +#pragma warning( disable : 4018 ) +#endif + + template <typename F, typename T> + void checkUpperLimit(const F& from) const + { + // casting to type of smaller size AND + // 'from' is greater than 'T' max value + if ((sizeof(T) < sizeof(F)) && + (from > static_cast<F>(std::numeric_limits<T>::max()))) + { + throw RangeException("Value too large."); + } + // casting to type of equal/bigger size AND + // 'F' is signed AND + // 'T' is unsigned AND + // 'from' is negative + else if (std::numeric_limits<F>::is_signed && + !std::numeric_limits<T>::is_signed && from < 0) + { + throw RangeException("Value too small."); + } + // casting to type of equal/bigger size AND + // 'F' is unsigned AND + // 'T' is signed AND + // 'from' is greater than 'T' max value + else if (!std::numeric_limits<F>::is_signed && + std::numeric_limits<T>::is_signed && + static_cast<Poco::UInt64>(from) > std::numeric_limits<T>::max()) + { + throw RangeException("Value too large."); + } + } + +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + + template <typename F, typename T> + void checkUpperLimitFloat(const F& from) const + { + if (from > std::numeric_limits<T>::max()) + throw RangeException("Value too large."); + } + + template <typename F, typename T> + void checkLowerLimitFloat(const F& from) const + { + if (from < -std::numeric_limits<T>::max()) + throw RangeException("Value too small."); + } + + template <typename F, typename T> + void checkLowerLimit(const F& from) const + { + if (from < std::numeric_limits<T>::min()) + throw RangeException("Value too small."); + } +}; + + +// +// inlines +// + + +inline void VarHolder::convert(Int8& /*val*/) const +{ + throw BadCastException("Can not convert to Int8"); +} + + +inline void VarHolder::convert(Int16& /*val*/) const +{ + throw BadCastException("Can not convert to Int16"); +} + + +inline void VarHolder::convert(Int32& /*val*/) const +{ + throw BadCastException("Can not convert to Int32"); +} + + +inline void VarHolder::convert(Int64& /*val*/) const +{ + throw BadCastException("Can not convert to Int64"); +} + + +inline void VarHolder::convert(UInt8& /*val*/) const +{ + throw BadCastException("Can not convert to UInt8"); +} + + +inline void VarHolder::convert(UInt16& /*val*/) const +{ + throw BadCastException("Can not convert to UInt16"); +} + + +inline void VarHolder::convert(UInt32& /*val*/) const +{ + throw BadCastException("Can not convert to UInt32"); +} + + +inline void VarHolder::convert(UInt64& /*val*/) const +{ + throw BadCastException("Can not convert to UInt64"); +} + + +inline void VarHolder::convert(DateTime& /*val*/) const +{ + throw BadCastException("Can not convert to DateTime"); +} + + +inline void VarHolder::convert(LocalDateTime& /*val*/) const +{ + throw BadCastException("Can not convert to LocalDateTime"); +} + + +inline void VarHolder::convert(Timestamp& /*val*/) const +{ + throw BadCastException("Can not convert to Timestamp"); +} + +#ifndef POCO_LONG_IS_64_BIT + +inline void VarHolder::convert(long& val) const +{ + Int32 tmp; + convert(tmp); + val = tmp; +} + + +inline void VarHolder::convert(unsigned long& val) const +{ + UInt32 tmp; + convert(tmp); + val = tmp; +} + +#else + +inline void VarHolder::convert(long long& /*val*/) const +{ + throw BadCastException("Can not convert to long long"); +} + + +inline void VarHolder::convert(unsigned long long& /*val*/) const +{ + throw BadCastException("Can not convert to unsigned long long"); +} + +#endif + +inline void VarHolder::convert(bool& /*val*/) const +{ + throw BadCastException("Can not convert to bool"); +} + + +inline void VarHolder::convert(float& /*val*/) const +{ + throw BadCastException("Can not convert to float"); +} + + +inline void VarHolder::convert(double& /*val*/) const +{ + throw BadCastException("Can not convert to double"); +} + + +inline void VarHolder::convert(char& /*val*/) const +{ + throw BadCastException("Can not convert to char"); +} + + +inline void VarHolder::convert(std::string& /*val*/) const +{ + throw BadCastException("Can not convert to std::string"); +} + + +inline void VarHolder::convert(Poco::UTF16String& /*val*/) const +{ + throw BadCastException("Can not convert to Poco::UTF16String"); +} + + +inline bool VarHolder::isArray() const +{ + return true; +} + + +inline bool VarHolder::isVector() const +{ + return false; +} + + +inline bool VarHolder::isList() const +{ + return false; +} + + +inline bool VarHolder::isDeque() const +{ + return false; +} + + +inline bool VarHolder::isStruct() const +{ + return false; +} + +inline bool VarHolder::isInteger() const +{ + return false; +} + + +inline bool VarHolder::isSigned() const +{ + return false; +} + + +inline bool VarHolder::isNumeric() const +{ + return false; +} + + +inline bool VarHolder::isBoolean() const +{ + return false; +} + + +inline bool VarHolder::isString() const +{ + return false; +} + + +inline bool VarHolder::isDate() const +{ + return false; +} + + +inline bool VarHolder::isTime() const +{ + return false; +} + + +inline bool VarHolder::isDateTime() const +{ + return false; +} + +inline std::size_t VarHolder::size() const +{ + return 1u; +} + + +template <typename T> +class VarHolderImpl: public VarHolder + /// Template based implementation of a VarHolder. + /// This class provides type storage for user-defined types + /// that do not have VarHolderImpl specialization. + /// + /// The actual conversion work happens in the template specializations + /// of this class. + /// + /// VarHolderImpl throws following exceptions: + /// BadCastException (if the requested conversion is not implemented) + /// RangeException (if an attempt is made to assign a numeric value outside of the target min/max limits + /// SyntaxException (if an attempt is made to convert a string containing non-numeric characters to number) + /// + /// In order to support efficient direct extraction of the held value, + /// all specializations must additionally implement a public member function: + /// + /// const T& value() const + /// + /// returning a const reference to the actual stored value. +{ +public: + VarHolderImpl(const T& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(T); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const T& value() const + { + return _val; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + T _val; +}; + + +template <> +class VarHolderImpl<Int8>: public VarHolder +{ +public: + VarHolderImpl(Int8 val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Int8); + } + + void convert(Int8& val) const + { + val = _val; + } + + void convert(Int16& val) const + { + val = _val; + } + + void convert(Int32& val) const + { + val = _val; + } + + void convert(Int64& val) const + { + val = _val; + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = _val; + } + + void convert(unsigned long long& val) const + { + convertSignedToUnsigned(_val, val); + } + +#endif + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + val = static_cast<char>(_val); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + void convert(Poco::UTF16String& val) const + { + std::string str = NumberFormatter::format(_val); + Poco::UnicodeConverter::convert(str, val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const Int8& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<Int8>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<Int8>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<Int8>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + Int8 _val; +}; + + +template <> +class VarHolderImpl<Int16>: public VarHolder +{ +public: + VarHolderImpl(Int16 val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Int16); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + val = _val; + } + + void convert(Int32& val) const + { + val = _val; + } + + void convert(Int64& val) const + { + val = _val; + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = _val; + } + + void convert(unsigned long long& val) const + { + convertSignedToUnsigned(_val, val); + } + +#endif + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + void convert(Poco::UTF16String& val) const + { + std::string str = NumberFormatter::format(_val); + Poco::UnicodeConverter::convert(str, val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const Int16& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<Int16>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<Int16>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<Int16>::is_specialized; + } + + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + Int16 _val; +}; + + +template <> +class VarHolderImpl<Int32>: public VarHolder +{ +public: + VarHolderImpl(Int32 val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Int32); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + val = _val; + } + + void convert(Int64& val) const + { + val = _val; + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = _val; + } + + void convert(unsigned long long& val) const + { + convertSignedToUnsigned(_val, val); + } + +#endif + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const Int32& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<Int32>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<Int32>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<Int32>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + Int32 _val; +}; + + +template <> +class VarHolderImpl<Int64>: public VarHolder +{ +public: + VarHolderImpl(Int64 val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Int64); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int64& val) const + { + val = _val; + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = _val; + } + + void convert(unsigned long long& val) const + { + convertSignedToUnsigned(_val, val); + } + +#endif + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + void convert(DateTime& dt) const + { + dt = Timestamp(_val); + } + + void convert(LocalDateTime& ldt) const + { + ldt = Timestamp(_val); + } + + void convert(Timestamp& val) const + { + val = Timestamp(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const Int64& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<Int64>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<Int64>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<Int64>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + Int64 _val; +}; + + +template <> +class VarHolderImpl<UInt8>: public VarHolder +{ +public: + VarHolderImpl(UInt8 val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(UInt8); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + val = static_cast<Int32>(_val); + } + + void convert(Int64& val) const + { + val = static_cast<Int64>(_val); + } + + void convert(UInt8& val) const + { + val = _val; + } + + void convert(UInt16& val) const + { + val = _val; + } + + void convert(UInt32& val) const + { + val = _val; + } + + void convert(UInt64& val) const + { + val = _val; + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = static_cast<long long>(_val); + } + + void convert(unsigned long long& val) const + { + val = _val; + } + +#endif + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const UInt8& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<UInt8>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<UInt8>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<UInt8>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + UInt8 _val; +}; + + +template <> +class VarHolderImpl<UInt16>: public VarHolder +{ +public: + VarHolderImpl(UInt16 val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(UInt16); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int64& val) const + { + val = static_cast<Int64>(_val); + } + + void convert(UInt8& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + val = _val; + } + + void convert(UInt32& val) const + { + val = _val; + } + + void convert(UInt64& val) const + { + val = _val; + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = static_cast<long long>(_val); + } + + void convert(unsigned long long& val) const + { + val = _val; + } + +#endif + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const UInt16& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<UInt16>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<UInt16>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<UInt16>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + UInt16 _val; +}; + + +template <> +class VarHolderImpl<UInt32>: public VarHolder +{ +public: + VarHolderImpl(UInt32 val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(UInt32); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int64& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(UInt8& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + val = _val; + } + + void convert(UInt64& val) const + { + val = _val; + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(unsigned long long& val) const + { + val = _val; + } + +#endif + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const UInt32& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<UInt32>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<UInt32>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<UInt32>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + UInt32 _val; +}; + + +template <> +class VarHolderImpl<UInt64>: public VarHolder +{ +public: + VarHolderImpl(UInt64 val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(UInt64); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int64& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(UInt8& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + val = _val; + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(unsigned long long& val) const + { + val = _val; + } + +#endif + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + void convert(DateTime& dt) const + { + Int64 val; + convertUnsignedToSigned(_val, val); + dt = Timestamp(val); + } + + void convert(LocalDateTime& ldt) const + { + Int64 val; + convertUnsignedToSigned(_val, val); + ldt = Timestamp(val); + } + + void convert(Timestamp& val) const + { + Int64 tmp; + convertUnsignedToSigned(_val, tmp); + val = Timestamp(tmp); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const UInt64& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<UInt64>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<UInt64>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<UInt64>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + UInt64 _val; +}; + + +template <> +class VarHolderImpl<bool>: public VarHolder +{ +public: + VarHolderImpl(bool val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(bool); + } + + void convert(Int8& val) const + { + val = static_cast<Int8>(_val ? 1 : 0); + } + + void convert(Int16& val) const + { + val = static_cast<Int16>(_val ? 1 : 0); + } + + void convert(Int32& val) const + { + val = static_cast<Int32>(_val ? 1 : 0); + } + + void convert(Int64& val) const + { + val = static_cast<Int64>(_val ? 1 : 0); + } + + void convert(UInt8& val) const + { + val = static_cast<UInt8>(_val ? 1 : 0); + } + + void convert(UInt16& val) const + { + val = static_cast<UInt16>(_val ? 1 : 0); + } + + void convert(UInt32& val) const + { + val = static_cast<UInt32>(_val ? 1 : 0); + } + + void convert(UInt64& val) const + { + val = static_cast<UInt64>(_val ? 1 : 0); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = static_cast<long long>(_val ? 1 : 0); + } + + void convert(unsigned long long& val) const + { + val = static_cast<unsigned long long>(_val ? 1 : 0); + } + +#endif + + void convert(bool& val) const + { + val = _val; + } + + void convert(float& val) const + { + val = (_val ? 1.0f : 0.0f); + } + + void convert(double& val) const + { + val = (_val ? 1.0 : 0.0); + } + + void convert(char& val) const + { + val = static_cast<char>(_val ? 1 : 0); + } + + void convert(std::string& val) const + { + val = (_val ? "true" : "false"); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const bool& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<bool>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<bool>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<bool>::is_specialized; + } + + bool isBoolean() const + { + return true; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + bool _val; +}; + + +template <> +class VarHolderImpl<float>: public VarHolder +{ +public: + VarHolderImpl(float val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(float); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int64& val) const + { + convertToSmaller(_val, val); + } + + void convert(UInt8& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + convertToSmaller(_val, val); + } + + void convert(unsigned long long& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + +#endif + + void convert(bool& val) const + { + val = !(_val <= std::numeric_limits<float>::min() && + _val >= -1 * std::numeric_limits<float>::min()); + } + + void convert(float& val) const + { + val = _val; + } + + void convert(double& val) const + { + val = _val; + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const float& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<float>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<float>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<float>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + float _val; +}; + + +template <> +class VarHolderImpl<double>: public VarHolder +{ +public: + VarHolderImpl(double val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(double); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int64& val) const + { + convertToSmaller(_val, val); + } + + void convert(UInt8& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + convertToSmaller(_val, val); + } + + void convert(unsigned long long& val) const + { + convertSignedFloatToUnsigned(_val, val); + } + +#endif + + void convert(bool& val) const + { + val = !(_val <= std::numeric_limits<double>::min() && + _val >= -1 * std::numeric_limits<double>::min()); + } + + void convert(float& val) const + { + double fMin = -1 * std::numeric_limits<float>::max(); + double fMax = std::numeric_limits<float>::max(); + + if (_val < fMin) throw RangeException("Value too small."); + if (_val > fMax) throw RangeException("Value too large."); + + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = _val; + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const double& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<double>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<double>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<double>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + double _val; +}; + + +template <> +class VarHolderImpl<char>: public VarHolder +{ +public: + VarHolderImpl(char val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(char); + } + + void convert(Int8& val) const + { + val = static_cast<Int8>(_val); + } + + void convert(Int16& val) const + { + val = static_cast<UInt8>(_val); + } + + void convert(Int32& val) const + { + val = static_cast<UInt8>(_val); + } + + void convert(Int64& val) const + { + val = static_cast<UInt8>(_val); + } + + void convert(UInt8& val) const + { + val = static_cast<UInt8>(_val); + } + + void convert(UInt16& val) const + { + val = static_cast<UInt8>(_val); + } + + void convert(UInt32& val) const + { + val = static_cast<UInt8>(_val); + } + + void convert(UInt64& val) const + { + val = static_cast<UInt8>(_val); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = static_cast<long long>(_val); + } + + void convert(unsigned long long& val) const + { + val = static_cast<unsigned long long>(_val); + } + +#endif + + void convert(bool& val) const + { + val = (_val != '\0'); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + val = _val; + } + + void convert(std::string& val) const + { + val = std::string(1, _val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const char& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<char>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<char>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<char>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + char _val; +}; + + +template <> +class VarHolderImpl<std::string>: public VarHolder +{ +public: + VarHolderImpl(const char* pVal): _val(pVal) + { + } + + VarHolderImpl(const std::string& val) : _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(std::string); + } + + void convert(Int8& val) const + { + int v = NumberParser::parse(_val); + convertToSmaller(v, val); + } + + void convert(Int16& val) const + { + int v = NumberParser::parse(_val); + convertToSmaller(v, val); + } + + void convert(Int32& val) const + { + val = NumberParser::parse(_val); + } + + void convert(Int64& val) const + { + val = NumberParser::parse64(_val); + } + + void convert(UInt8& val) const + { + unsigned int v = NumberParser::parseUnsigned(_val); + convertToSmallerUnsigned(v, val); + } + + void convert(UInt16& val) const + { + unsigned int v = NumberParser::parseUnsigned(_val); + convertToSmallerUnsigned(v, val); + } + + void convert(UInt32& val) const + { + val = NumberParser::parseUnsigned(_val); + } + + void convert(UInt64& val) const + { + val = NumberParser::parseUnsigned64(_val); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = NumberParser::parse64(_val); + } + + void convert(unsigned long long& val) const + { + val = NumberParser::parseUnsigned64(_val); + } + +#endif + + void convert(bool& val) const + { + if (_val.empty()) + { + val = false; + return; + } + + static const std::string VAL_FALSE("false"); + static const std::string VAL_INT_FALSE("0"); + val = (_val != VAL_INT_FALSE && + (icompare(_val, VAL_FALSE) != 0)); + } + + void convert(float& val) const + { + double v = NumberParser::parseFloat(_val); + convertToSmaller(v, val); + } + + void convert(double& val) const + { + val = NumberParser::parseFloat(_val); + } + + void convert(char& val) const + { + if (_val.empty()) + val = '\0'; + else + val = _val[0]; + } + + void convert(std::string& val) const + { + val = _val; + } + + void convert(Poco::UTF16String& val) const + { + Poco::UnicodeConverter::convert(_val, val); + } + + void convert(DateTime& val) const + { + int tzd = 0; + if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, val, tzd)) + throw BadCastException("string -> DateTime"); + } + + void convert(LocalDateTime& ldt) const + { + int tzd = 0; + DateTime tmp; + if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, tmp, tzd)) + throw BadCastException("string -> LocalDateTime"); + + ldt = LocalDateTime(tzd, tmp, false); + } + + void convert(Timestamp& ts) const + { + int tzd = 0; + DateTime tmp; + if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, _val, tmp, tzd)) + throw BadCastException("string -> Timestamp"); + + ts = tmp.timestamp(); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const std:: string& value() const + { + return _val; + } + + bool isString() const + { + return true; + } + + std::size_t size() const + { + return _val.length(); + } + + char& operator[](std::string::size_type n) + { + if (n < size()) return _val.operator[](n); + + throw RangeException("String index out of range"); + } + + const char& operator[](std::string::size_type n) const + { + if (n < size()) return _val.operator[](n); + + throw RangeException("String index out of range"); + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + std::string _val; +}; + + +template <> +class VarHolderImpl<UTF16String>: public VarHolder +{ +public: + VarHolderImpl(const char* pVal) : _val(Poco::UnicodeConverter::to<UTF16String>(pVal)) + { + } + + VarHolderImpl(const Poco::UTF16String& val) : _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Poco::UTF16String); + } + + void convert(Int8& val) const + { + int v = NumberParser::parse(toStdString()); + convertToSmaller(v, val); + } + + void convert(Int16& val) const + { + int v = NumberParser::parse(toStdString()); + convertToSmaller(v, val); + } + + void convert(Int32& val) const + { + val = NumberParser::parse(toStdString()); + } + + void convert(Int64& val) const + { + val = NumberParser::parse64(toStdString()); + } + + void convert(UInt8& val) const + { + unsigned int v = NumberParser::parseUnsigned(toStdString()); + convertToSmallerUnsigned(v, val); + } + + void convert(UInt16& val) const + { + unsigned int v = NumberParser::parseUnsigned(toStdString()); + convertToSmallerUnsigned(v, val); + } + + void convert(UInt32& val) const + { + val = NumberParser::parseUnsigned(toStdString()); + } + + void convert(UInt64& val) const + { + val = NumberParser::parseUnsigned64(toStdString()); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = NumberParser::parse64(toStdString()); + } + + void convert(unsigned long long& val) const + { + val = NumberParser::parseUnsigned64(toStdString()); + } + +#endif + + void convert(bool& val) const + { + static const std::string VAL_FALSE("false"); + static const std::string VAL_INT_FALSE("0"); + + if (_val.empty()) val = false; + + std::string str; + UnicodeConverter::convert(_val, str); + val = (str != VAL_INT_FALSE && + (icompare(str, VAL_FALSE) != 0)); + } + + void convert(float& val) const + { + double v = NumberParser::parseFloat(toStdString()); + convertToSmaller(v, val); + } + + void convert(double& val) const + { + val = NumberParser::parseFloat(toStdString()); + } + + void convert(char& val) const + { + if (_val.empty()) + val = '\0'; + else + { + std::string s; + UnicodeConverter::convert(_val, s); + val = s[0]; + } + } + + void convert(Poco::UTF16String& val) const + { + val = _val; + } + + void convert(std::string& val) const + { + UnicodeConverter::convert(_val, val); + } + + void convert(DateTime& val) const + { + int tzd = 0; + if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, toStdString(), val, tzd)) + throw BadCastException("string -> DateTime"); + } + + void convert(LocalDateTime& ldt) const + { + int tzd = 0; + DateTime tmp; + if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, toStdString(), tmp, tzd)) + throw BadCastException("string -> LocalDateTime"); + + ldt = LocalDateTime(tzd, tmp, false); + } + + void convert(Timestamp& ts) const + { + int tzd = 0; + DateTime tmp; + if (!DateTimeParser::tryParse(DateTimeFormat::ISO8601_FORMAT, toStdString(), tmp, tzd)) + throw BadCastException("string -> Timestamp"); + + ts = tmp.timestamp(); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const Poco::UTF16String& value() const + { + return _val; + } + + bool isString() const + { + return true; + } + + std::size_t size() const + { + return _val.length(); + } + + UTF16Char& operator[](Poco::UTF16String::size_type n) + { + if (n < size()) return _val.operator[](n); + + throw RangeException("String index out of range"); + } + + const UTF16Char& operator[](Poco::UTF16String::size_type n) const + { + if (n < size()) return _val.operator[](n); + + throw RangeException("String index out of range"); + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + std::string toStdString() const + { + std::string str; + UnicodeConverter::convert(_val, str); + return str; + } + + Poco::UTF16String _val; +}; + + +#ifndef POCO_LONG_IS_64_BIT + + +template <> +class VarHolderImpl<long>: public VarHolder +{ +public: + VarHolderImpl(long val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(long); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + val = static_cast<Int32>(_val); + } + + void convert(Int64& val) const + { + val = static_cast<Int64>(_val); + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const long& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<long>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<long>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<long>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + long _val; +}; + + +template <> +class VarHolderImpl<unsigned long>: public VarHolder +{ +public: + VarHolderImpl(unsigned long val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(unsigned long); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int64& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(UInt8& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + val = static_cast<UInt64>(_val); + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const unsigned long& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<unsigned long>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<unsigned long>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<unsigned long>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + unsigned long _val; +}; + + +#else // if defined (POCO_LONG_IS_64_BIT) + + +template <> +class VarHolderImpl<long long>: public VarHolder +{ +public: + VarHolderImpl(long long val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(long long); + } + + void convert(Int8& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int16& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int32& val) const + { + convertToSmaller(_val, val); + } + + void convert(Int64& val) const + { + val = static_cast<Int64>(_val); + } + + void convert(UInt8& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(long long& val) const + { + val = _val; + } + + void convert(unsigned long long& val) const + { + convertSignedToUnsigned(_val, val); + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const long long& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<long long>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<long long>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<long long>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + long long _val; +}; + + +template <> +class VarHolderImpl<unsigned long long>: public VarHolder +{ +public: + VarHolderImpl(unsigned long long val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(unsigned long long); + } + + void convert(Int8& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int16& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int32& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(Int64& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(UInt8& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt16& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt32& val) const + { + convertToSmallerUnsigned(_val, val); + } + + void convert(UInt64& val) const + { + val = static_cast<UInt64>(_val); + } + + void convert(long long& val) const + { + convertUnsignedToSigned(_val, val); + } + + void convert(unsigned long long& val) const + { + val = _val; + } + + void convert(bool& val) const + { + val = (_val != 0); + } + + void convert(float& val) const + { + val = static_cast<float>(_val); + } + + void convert(double& val) const + { + val = static_cast<double>(_val); + } + + void convert(char& val) const + { + UInt8 tmp; + convert(tmp); + val = static_cast<char>(tmp); + } + + void convert(std::string& val) const + { + val = NumberFormatter::format(_val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const unsigned long long& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return std::numeric_limits<unsigned long long>::is_integer; + } + + bool isSigned() const + { + return std::numeric_limits<unsigned long long>::is_signed; + } + + bool isNumeric() const + { + return std::numeric_limits<unsigned long long>::is_specialized; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + unsigned long long _val; +}; + + +#endif // 64bit + + +template <typename T> +class VarHolderImpl<std::vector<T> >: public VarHolder +{ +public: + VarHolderImpl(const std::vector<T>& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(std::vector<T>); + } + + void convert(std::string& val) const + { + Impl::containerToJSON(_val, val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const std::vector<T>& value() const + { + return _val; + } + + bool isVector() const + { + return true; + } + + std::size_t size() const + { + return _val.size(); + } + + T& operator[](typename std::vector<T>::size_type n) + { + if (n < size()) return _val.operator[](n); + + throw RangeException("List index out of range"); + } + + const T& operator[](typename std::vector<T>::size_type n) const + { + if (n < size()) return _val.operator[](n); + + throw RangeException("List index out of range"); + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + std::vector<T> _val; +}; + + +template <typename T> +class VarHolderImpl<std::list<T> >: public VarHolder +{ +public: + VarHolderImpl(const std::list<T>& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(std::list<T>); + } + + void convert(std::string& val) const + { + Impl::containerToJSON(_val, val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const std::list<T>& value() const + { + return _val; + } + + bool isList() const + { + return true; + } + + std::size_t size() const + { + return _val.size(); + } + + T& operator[](typename std::list<T>::size_type n) + { + if (n >= size()) + throw RangeException("List index out of range"); + + typename std::list<T>::size_type counter = 0; + typename std::list<T>::iterator it = _val.begin(); + for (; counter < n; ++counter) ++it; + + return *it; + } + + const T& operator[](typename std::list<T>::size_type n) const + { + if (n >= size()) + throw RangeException("List index out of range"); + + typename std::list<T>::size_type counter = 0; + typename std::list<T>::const_iterator it = _val.begin(); + for (; counter < n; ++counter) ++it; + + return *it; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + std::list<T> _val; +}; + + +template <typename T> +class VarHolderImpl<std::deque<T> >: public VarHolder +{ +public: + VarHolderImpl(const std::deque<T>& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(std::deque<T>); + } + + void convert(std::string& val) const + { + Impl::containerToJSON(_val, val); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const std::deque<T>& value() const + { + return _val; + } + + bool isDeque() const + { + return true; + } + + std::size_t size() const + { + return _val.size(); + } + + T& operator[](typename std::deque<T>::size_type n) + { + if (n < size()) return _val.operator[](n); + + throw RangeException("List index out of range"); + } + + const T& operator[](typename std::deque<T>::size_type n) const + { + if (n < size()) return _val.operator[](n); + + throw RangeException("List index out of range"); + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + std::deque<T> _val; +}; + + +template <> +class VarHolderImpl<DateTime>: public VarHolder +{ +public: + VarHolderImpl(const DateTime& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(DateTime); + } + + void convert(Int8& /*val*/) const + { + throw BadCastException(); + } + + void convert(Int16& /*val*/) const + { + throw BadCastException(); + } + + void convert(Int32& /*val*/) const + { + throw BadCastException(); + } + + void convert(Int64& val) const + { + val = _val.timestamp().epochMicroseconds(); + } + + void convert(UInt64& val) const + { + val = _val.timestamp().epochMicroseconds(); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = _val.timestamp().epochMicroseconds(); + } + + void convert(unsigned long long& val) const + { + val = _val.timestamp().epochMicroseconds(); + } + +#endif + + void convert(std::string& val) const + { + val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT); + } + + void convert(DateTime& val) const + { + val = _val; + } + + void convert(LocalDateTime& ldt) const + { + ldt = _val.timestamp(); + } + + void convert(Timestamp& ts) const + { + ts = _val.timestamp(); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const DateTime& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + + bool isDate() const + { + return true; + } + + bool isTime() const + { + return true; + } + + bool isDateTime() const + { + return true; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + DateTime _val; +}; + + +template <> +class VarHolderImpl<LocalDateTime>: public VarHolder +{ +public: + VarHolderImpl(const LocalDateTime& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(LocalDateTime); + } + + void convert(Int64& val) const + { + val = _val.timestamp().epochMicroseconds(); + } + + void convert(UInt64& val) const + { + val = _val.timestamp().epochMicroseconds(); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = _val.timestamp().epochMicroseconds(); + } + + void convert(unsigned long long& val) const + { + val = _val.timestamp().epochMicroseconds(); + } + +#endif + + void convert(std::string& val) const + { + val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT); + } + + void convert(DateTime& val) const + { + val = _val.timestamp(); + } + + void convert(LocalDateTime& ldt) const + { + ldt = _val; + } + + void convert(Timestamp& ts) const + { + ts = _val.timestamp(); + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const LocalDateTime& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + + bool isDate() const + { + return true; + } + + bool isTime() const + { + return true; + } + + bool isDateTime() const + { + return true; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + LocalDateTime _val; +}; + + +template <> +class VarHolderImpl<Timestamp>: public VarHolder +{ +public: + VarHolderImpl(const Timestamp& val): _val(val) + { + } + + ~VarHolderImpl() + { + } + + const std::type_info& type() const + { + return typeid(Timestamp); + } + + void convert(Int64& val) const + { + val = _val.epochMicroseconds(); + } + + void convert(UInt64& val) const + { + val = _val.epochMicroseconds(); + } + +#ifdef POCO_LONG_IS_64_BIT + + void convert(long long& val) const + { + val = _val.epochMicroseconds(); + } + + void convert(unsigned long long& val) const + { + val = _val.epochMicroseconds(); + } + +#endif + + void convert(std::string& val) const + { + val = DateTimeFormatter::format(_val, Poco::DateTimeFormat::ISO8601_FORMAT); + } + + void convert(DateTime& val) const + { + val = _val; + } + + void convert(LocalDateTime& ldt) const + { + ldt = _val; + } + + void convert(Timestamp& ts) const + { + ts = _val; + } + + VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const + { + return cloneHolder(pVarHolder, _val); + } + + const Timestamp& value() const + { + return _val; + } + + bool isArray() const + { + return false; + } + + bool isStruct() const + { + return false; + } + + bool isInteger() const + { + return false; + } + + bool isSigned() const + { + return false; + } + + bool isNumeric() const + { + return false; + } + + bool isBoolean() const + { + return false; + } + + bool isString() const + { + return false; + } + + bool isDate() const + { + return true; + } + + bool isTime() const + { + return true; + } + + bool isDateTime() const + { + return true; + } + +private: + VarHolderImpl(); + VarHolderImpl(const VarHolderImpl&); + VarHolderImpl& operator = (const VarHolderImpl&); + + Timestamp _val; +}; + + +typedef std::vector<Var> Vector; +typedef std::deque<Var> Deque; +typedef std::list<Var> List; +typedef Vector Array; + + +} } // namespace Poco::Dynamic + + +#endif // Foundation_VarHolder_INCLUDED diff --git a/contrib/libs/poco/Foundation/include/Poco/Dynamic/VarIterator.h b/contrib/libs/poco/Foundation/include/Poco/Dynamic/VarIterator.h index 20d18dd34c..a91bb3a6a2 100644 --- a/contrib/libs/poco/Foundation/include/Poco/Dynamic/VarIterator.h +++ b/contrib/libs/poco/Foundation/include/Poco/Dynamic/VarIterator.h @@ -1,150 +1,150 @@ -// -// VarIterator.h -// -// Library: Foundation -// Package: Dynamic -// Module: VarIterator -// -// Definition of the VarIterator class. -// -// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#ifndef Foundation_VarIterator_INCLUDED -#define Foundation_VarIterator_INCLUDED - - -#include "Poco/Exception.h" -#include <iterator> -#include <algorithm> - - -namespace Poco { -namespace Dynamic { - - -class Var; - - -class Foundation_API VarIterator - /// VarIterator class. -{ -public: - typedef std::bidirectional_iterator_tag iterator_category; - typedef Var value_type; - typedef std::ptrdiff_t difference_type; - typedef Var* pointer; - typedef Var& reference; - - static const std::size_t POSITION_END; - /// End position indicator. - - VarIterator(Var* pVar, bool positionEnd); - /// Creates the VarIterator and positions it at the end of - /// the recordset if positionEnd is true. Otherwise, it is - /// positioned at the beginning. - - VarIterator(const VarIterator& other); - /// Creates a copy of other VarIterator. - - ~VarIterator(); - /// Destroys the VarIterator. - - VarIterator& operator = (const VarIterator& other); - /// Assigns the other VarIterator. - - bool operator == (const VarIterator& other) const; - /// Equality operator. - - bool operator != (const VarIterator& other) const; - /// Inequality operator. - - Var& operator * () const; - /// Returns value at the current position. - - Var* operator -> () const; - /// Returns pointer to the value at current position. - - const VarIterator& operator ++ () const; - /// Advances by one position and returns current position. - - VarIterator operator ++ (int) const; - /// Advances by one position and returns copy of the iterator with - /// previous current position. - - const VarIterator& operator -- () const; - /// Goes back by one position and returns copy of the iterator with - /// previous current position. - - VarIterator operator -- (int) const; - /// Goes back by one position and returns previous current position. - - VarIterator operator + (std::size_t diff) const; - /// Returns a copy the VarIterator advanced by diff positions. - - VarIterator operator - (std::size_t diff) const; - /// Returns a copy the VarIterator backed by diff positions. - /// Throws RangeException if diff is larger than current position. - - void swap(VarIterator& other); - /// Swaps the VarIterator with another one. - -private: - VarIterator(); - - void increment() const; - /// Increments the iterator position by one. - /// Throws RangeException if position is out of range. - - void decrement() const; - /// Decrements the iterator position by one. - /// Throws RangeException if position is out of range. - - void setPosition(std::size_t pos) const; - /// Sets the iterator position. - /// Throws RangeException if position is out of range. - - Var* _pVar; - mutable std::size_t _position; - - friend class Var; -}; - - -/// -/// inlines -/// - - -inline bool VarIterator::operator == (const VarIterator& other) const -{ - return _pVar == other._pVar && _position == other._position; -} - - -inline bool VarIterator::operator != (const VarIterator& other) const -{ - return _pVar != other._pVar || _position != other._position; -} - - -} } // namespace Poco::Dynamic - - -namespace std -{ - template<> - inline void swap<Poco::Dynamic::VarIterator>(Poco::Dynamic::VarIterator& s1, - Poco::Dynamic::VarIterator& s2) - /// Full template specialization of std:::swap for VarIterator - { - s1.swap(s2); - } -} - - -#endif // Foundation_VarIterator_INCLUDED +// +// VarIterator.h +// +// Library: Foundation +// Package: Dynamic +// Module: VarIterator +// +// Definition of the VarIterator class. +// +// Copyright (c) 2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#ifndef Foundation_VarIterator_INCLUDED +#define Foundation_VarIterator_INCLUDED + + +#include "Poco/Exception.h" +#include <iterator> +#include <algorithm> + + +namespace Poco { +namespace Dynamic { + + +class Var; + + +class Foundation_API VarIterator + /// VarIterator class. +{ +public: + typedef std::bidirectional_iterator_tag iterator_category; + typedef Var value_type; + typedef std::ptrdiff_t difference_type; + typedef Var* pointer; + typedef Var& reference; + + static const std::size_t POSITION_END; + /// End position indicator. + + VarIterator(Var* pVar, bool positionEnd); + /// Creates the VarIterator and positions it at the end of + /// the recordset if positionEnd is true. Otherwise, it is + /// positioned at the beginning. + + VarIterator(const VarIterator& other); + /// Creates a copy of other VarIterator. + + ~VarIterator(); + /// Destroys the VarIterator. + + VarIterator& operator = (const VarIterator& other); + /// Assigns the other VarIterator. + + bool operator == (const VarIterator& other) const; + /// Equality operator. + + bool operator != (const VarIterator& other) const; + /// Inequality operator. + + Var& operator * () const; + /// Returns value at the current position. + + Var* operator -> () const; + /// Returns pointer to the value at current position. + + const VarIterator& operator ++ () const; + /// Advances by one position and returns current position. + + VarIterator operator ++ (int) const; + /// Advances by one position and returns copy of the iterator with + /// previous current position. + + const VarIterator& operator -- () const; + /// Goes back by one position and returns copy of the iterator with + /// previous current position. + + VarIterator operator -- (int) const; + /// Goes back by one position and returns previous current position. + + VarIterator operator + (std::size_t diff) const; + /// Returns a copy the VarIterator advanced by diff positions. + + VarIterator operator - (std::size_t diff) const; + /// Returns a copy the VarIterator backed by diff positions. + /// Throws RangeException if diff is larger than current position. + + void swap(VarIterator& other); + /// Swaps the VarIterator with another one. + +private: + VarIterator(); + + void increment() const; + /// Increments the iterator position by one. + /// Throws RangeException if position is out of range. + + void decrement() const; + /// Decrements the iterator position by one. + /// Throws RangeException if position is out of range. + + void setPosition(std::size_t pos) const; + /// Sets the iterator position. + /// Throws RangeException if position is out of range. + + Var* _pVar; + mutable std::size_t _position; + + friend class Var; +}; + + +/// +/// inlines +/// + + +inline bool VarIterator::operator == (const VarIterator& other) const +{ + return _pVar == other._pVar && _position == other._position; +} + + +inline bool VarIterator::operator != (const VarIterator& other) const +{ + return _pVar != other._pVar || _position != other._position; +} + + +} } // namespace Poco::Dynamic + + +namespace std +{ + template<> + inline void swap<Poco::Dynamic::VarIterator>(Poco::Dynamic::VarIterator& s1, + Poco::Dynamic::VarIterator& s2) + /// Full template specialization of std:::swap for VarIterator + { + s1.swap(s2); + } +} + + +#endif // Foundation_VarIterator_INCLUDED |