mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2026-11-21 19:27:09 +01:00
Update libraries and make it build on windows.
Still gets some warnings because compilers have changed. But should work.
This commit is contained in:
1 parent
520a5eacc5
commit
f2b7499f85
3038 files changed
+251668
-273857
No files matched your search
+25
-27
@@ -62,10 +62,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Pair()
|
||||
virtual ~Pair() = default;
|
||||
/// Destroys the Pair.
|
||||
{
|
||||
}
|
||||
|
||||
Pair& swap(Pair& other) noexcept
|
||||
/// Swaps the content of the two Pairs.
|
||||
@@ -122,62 +120,62 @@ public:
|
||||
return typeid(Pair<std::string>);
|
||||
}
|
||||
|
||||
void convert(Int8& val) const
|
||||
void convert(Int8&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to Int8");
|
||||
}
|
||||
|
||||
void convert(Int16& val) const
|
||||
void convert(Int16&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to Int16");
|
||||
}
|
||||
|
||||
void convert(Int32& val) const
|
||||
void convert(Int32&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to Int32");
|
||||
}
|
||||
|
||||
void convert(Int64& val) const
|
||||
void convert(Int64&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to Int64");
|
||||
}
|
||||
|
||||
void convert(UInt8& val) const
|
||||
void convert(UInt8&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to UInt8");
|
||||
}
|
||||
|
||||
void convert(UInt16& val) const
|
||||
void convert(UInt16&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to UInt16");
|
||||
}
|
||||
|
||||
void convert(UInt32& val) const
|
||||
void convert(UInt32&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to UInt32");
|
||||
}
|
||||
|
||||
void convert(UInt64& val) const
|
||||
void convert(UInt64&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to UInt64");
|
||||
}
|
||||
|
||||
void convert(bool& val) const
|
||||
void convert(bool&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to bool");
|
||||
}
|
||||
|
||||
void convert(float& val) const
|
||||
void convert(float&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to float");
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
void convert(double&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to double");
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
void convert(char&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to char");
|
||||
}
|
||||
@@ -271,62 +269,62 @@ public:
|
||||
return typeid(Pair<int>);
|
||||
}
|
||||
|
||||
void convert(Int8& val) const
|
||||
void convert(Int8&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to Int8");
|
||||
}
|
||||
|
||||
void convert(Int16& val) const
|
||||
void convert(Int16&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to Int16");
|
||||
}
|
||||
|
||||
void convert(Int32& val) const
|
||||
void convert(Int32&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to Int32");
|
||||
}
|
||||
|
||||
void convert(Int64& val) const
|
||||
void convert(Int64&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to Int64");
|
||||
}
|
||||
|
||||
void convert(UInt8& val) const
|
||||
void convert(UInt8&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to UInt8");
|
||||
}
|
||||
|
||||
void convert(UInt16& val) const
|
||||
void convert(UInt16&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to UInt16");
|
||||
}
|
||||
|
||||
void convert(UInt32& val) const
|
||||
void convert(UInt32&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to UInt32");
|
||||
}
|
||||
|
||||
void convert(UInt64& val) const
|
||||
void convert(UInt64&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to UInt64");
|
||||
}
|
||||
|
||||
void convert(bool& val) const
|
||||
void convert(bool&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to bool");
|
||||
}
|
||||
|
||||
void convert(float& val) const
|
||||
void convert(float&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to float");
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
void convert(double&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to double");
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
void convert(char&) const
|
||||
{
|
||||
throw BadCastException("Cannot cast Pair type to char");
|
||||
}
|
||||
|
||||
+21
-2
@@ -288,6 +288,25 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
|
||||
extern template class Struct<std::string>;
|
||||
extern template class Struct<int>;
|
||||
|
||||
extern template class Struct<std::string, Poco::OrderedMap<std::string, Var>, Poco::OrderedSet<std::string>>;
|
||||
extern template class Struct<int, OrderedMap<int, Var>, OrderedSet<int>>;
|
||||
|
||||
#else
|
||||
|
||||
extern template class Foundation_API Struct<std::string>;
|
||||
extern template class Foundation_API Struct<int>;
|
||||
|
||||
extern template class Foundation_API Struct<std::string, Poco::OrderedMap<std::string, Var>, Poco::OrderedSet<std::string>>;
|
||||
extern template class Foundation_API Struct<int, OrderedMap<int, Var>, OrderedSet<int>>;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
template <>
|
||||
class VarHolderImpl<Struct<std::string, std::map<std::string, Var>, std::set<std::string>>>: public VarHolder
|
||||
{
|
||||
@@ -959,8 +978,8 @@ private:
|
||||
} // namespace Dynamic
|
||||
|
||||
|
||||
typedef Dynamic::Struct<std::string> DynamicStruct;
|
||||
typedef Dynamic::Struct<std::string, Poco::OrderedMap<std::string, Dynamic::Var>, Poco::OrderedSet<std::string>> OrderedDynamicStruct;
|
||||
using DynamicStruct = Dynamic::Struct<std::string>;
|
||||
using OrderedDynamicStruct = Dynamic::Struct<std::string, Poco::OrderedMap<std::string, Dynamic::Var>, Poco::OrderedSet<std::string>>;
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
+33
-32
@@ -210,7 +210,7 @@ public:
|
||||
|
||||
if (pHolder && pHolder->type() == typeid(T))
|
||||
{
|
||||
VarHolderImpl<T>* pHolderImpl = static_cast<VarHolderImpl<T>*>(pHolder);
|
||||
auto* pHolderImpl = static_cast<VarHolderImpl<T>*>(pHolder);
|
||||
return pHolderImpl->value();
|
||||
}
|
||||
else if (!pHolder)
|
||||
@@ -475,7 +475,12 @@ public:
|
||||
const std::type_info& type() const;
|
||||
/// Returns the type information of the stored content.
|
||||
|
||||
//@ deprecated
|
||||
std::string typeName(bool demangle = true) const;
|
||||
/// Returns the type name of the stored content.
|
||||
/// If demangling is available and emangle is true,
|
||||
/// the returnsed string will be demangled.
|
||||
|
||||
POCO_DEPRECATED("Use clear() instead")
|
||||
void empty();
|
||||
/// Empties Var.
|
||||
/// This function is deprecated and will be removed.
|
||||
@@ -521,23 +526,8 @@ public:
|
||||
/// This function returns 0 when Var is empty, 1 for POD or the size (i.e. length)
|
||||
/// for held container.
|
||||
|
||||
std::string toString() const
|
||||
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
|
||||
@@ -617,17 +607,8 @@ private:
|
||||
_placeholder.assign<VarHolderImpl<ValueType>, ValueType>(value);
|
||||
}
|
||||
|
||||
void construct(const char* value)
|
||||
{
|
||||
std::string val(value);
|
||||
_placeholder.assign<VarHolderImpl<std::string>, std::string>(val);
|
||||
}
|
||||
|
||||
void construct(const Var& other)
|
||||
{
|
||||
if (!other.isEmpty())
|
||||
other.content()->clone(&_placeholder);
|
||||
}
|
||||
void construct(const char* value);
|
||||
void construct(const Var& other);
|
||||
|
||||
Placeholder<VarHolder> _placeholder;
|
||||
};
|
||||
@@ -642,6 +623,20 @@ private:
|
||||
/// Var members
|
||||
///
|
||||
|
||||
inline void Var::construct(const char* value)
|
||||
{
|
||||
std::string val(value);
|
||||
_placeholder.assign<VarHolderImpl<std::string>, std::string>(val);
|
||||
}
|
||||
|
||||
|
||||
inline void Var::construct(const Var& other)
|
||||
{
|
||||
if (!other.isEmpty())
|
||||
other.content()->clone(&_placeholder);
|
||||
}
|
||||
|
||||
|
||||
inline void Var::swap(Var& other)
|
||||
{
|
||||
if (this == &other) return;
|
||||
@@ -674,6 +669,13 @@ inline const std::type_info& Var::type() const
|
||||
}
|
||||
|
||||
|
||||
inline std::string Var::typeName(bool demangle) const
|
||||
{
|
||||
VarHolder* pHolder = content();
|
||||
return pHolder ? demangle ? Poco::demangle(pHolder->type().name()) : pHolder->type().name() : std::string();
|
||||
}
|
||||
|
||||
|
||||
inline Var::ConstIterator Var::begin() const
|
||||
{
|
||||
if (size() == 0) return ConstIterator(const_cast<Var*>(this), true);
|
||||
@@ -731,7 +733,7 @@ inline bool Var::operator ! () const
|
||||
|
||||
inline bool Var::isEmpty() const
|
||||
{
|
||||
return 0 == content();
|
||||
return nullptr == content();
|
||||
}
|
||||
|
||||
|
||||
@@ -2286,8 +2288,7 @@ inline bool operator >= (const unsigned long& other, const Var& da)
|
||||
} // namespace Dynamic
|
||||
|
||||
|
||||
//@ deprecated
|
||||
typedef Dynamic::Var DynamicAny;
|
||||
using DynamicAny POCO_DEPRECATED("") = Dynamic::Var;
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
+503
-118
@@ -33,16 +33,27 @@
|
||||
#include "Poco/UTF8String.h"
|
||||
#include "Poco/UUID.h"
|
||||
#include "Poco/Any.h"
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Debugger.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
#include <typeinfo>
|
||||
#include <type_traits>
|
||||
#include <string_view>
|
||||
#undef min
|
||||
#undef max
|
||||
#include <limits>
|
||||
|
||||
|
||||
#define POCO_VAR_RANGE_EXCEPTION(str, from) \
|
||||
throw RangeException(Poco::format("%v ((%s/%d) %s > (%s/%d) %s) @ %s.", \
|
||||
std::string_view(#str), Poco::demangle<F>(), numValDigits(from), std::to_string(from), \
|
||||
Poco::demangle<T>(), numTypeDigits<T>(), std::to_string(static_cast<T>(from)), \
|
||||
poco_src_loc))
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
@@ -120,12 +131,12 @@ class Foundation_API VarHolder
|
||||
/// throw BadCastException.
|
||||
{
|
||||
public:
|
||||
typedef Var ArrayValueType;
|
||||
using ArrayValueType = Var;
|
||||
|
||||
virtual ~VarHolder();
|
||||
/// Destroys the VarHolder.
|
||||
|
||||
virtual VarHolder* clone(Placeholder<VarHolder>* pHolder = 0) const = 0;
|
||||
virtual VarHolder* clone(Placeholder<VarHolder>* pHolder = nullptr) const = 0;
|
||||
/// Implementation must implement this function to
|
||||
/// deep-copy the VarHolder.
|
||||
/// If small object optimization is enabled (i.e. if
|
||||
@@ -311,148 +322,241 @@ protected:
|
||||
return pVarHolder->assign<VarHolderImpl<T>, T>(val);
|
||||
}
|
||||
|
||||
template <typename F, typename T>
|
||||
void convertToSmaller(const F& from, T& to) const
|
||||
/// This function is meant to convert signed numeric values from
|
||||
template <typename F, typename T,
|
||||
std::enable_if_t<(std::is_integral_v<F> && std::is_signed_v<F>) ||
|
||||
std::is_floating_point_v<F>, F>* = nullptr,
|
||||
std::enable_if_t<(std::is_integral_v<T> && std::is_signed_v<T>) ||
|
||||
std::is_floating_point_v<F>, T>* = nullptr>
|
||||
static void convertToSmaller(const F& from, T& to)
|
||||
/// Converts signed integral, as well as floating-point, 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)
|
||||
if constexpr((std::is_integral_v<F>) && (std::is_floating_point_v<T>))
|
||||
{
|
||||
checkUpperLimit<F,T>(from);
|
||||
checkLowerLimit<F,T>(from);
|
||||
if (isPrecisionLost<F, T>(from))
|
||||
POCO_VAR_RANGE_EXCEPTION ("Lost precision", from);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkUpperLimitFloat<F,T>(from);
|
||||
checkLowerLimitFloat<F,T>(from);
|
||||
}
|
||||
|
||||
checkUpperLimit<F,T>(from);
|
||||
checkLowerLimit<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.
|
||||
template <typename F, typename T,
|
||||
std::enable_if_t<std::is_integral_v<F> && std::is_signed_v<T>, F>* = nullptr,
|
||||
std::enable_if_t<std::is_floating_point_v<T>, T>* = nullptr>
|
||||
static void convertToSmaller(const F& from, T& to)
|
||||
/// Converts signed integral values from integral to floating-point type. Checks for
|
||||
/// the loss of precision 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 (isPrecisionLost<F, T>(from))
|
||||
POCO_VAR_RANGE_EXCEPTION ("Lost precision", from);
|
||||
to = static_cast<T>(from);
|
||||
}
|
||||
|
||||
template <typename F, typename T,
|
||||
std::enable_if_t<std::is_same_v<F, bool>>* = nullptr,
|
||||
std::enable_if_t<std::is_floating_point_v<T>, T>* = nullptr>
|
||||
static void convertToSmaller(const F& from, T& to)
|
||||
/// Converts boolean values to floating-point type.
|
||||
{
|
||||
to = static_cast<T>(from);
|
||||
}
|
||||
|
||||
template <typename F, typename T,
|
||||
std::enable_if_t<std::is_integral_v<F> && !std::is_signed_v<F>, F>* = nullptr,
|
||||
std::enable_if_t<(std::is_integral_v<T> && !std::is_signed<T>::value) || std::is_floating_point<T>::value, T>* = nullptr>
|
||||
static void convertToSmallerUnsigned(const F& from, T& to)
|
||||
/// Converts unsigned integral data types from larger to smaller, as well as to floating-point, types.
|
||||
/// 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.
|
||||
{
|
||||
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.
|
||||
template <typename F, typename T,
|
||||
std::enable_if_t<std::is_integral_v<F> && std::is_signed_v<F>, F>* = nullptr,
|
||||
std::enable_if_t<std::is_integral_v<T> && !std::is_signed_v<T>, T>* = nullptr>
|
||||
static void convertSignedToUnsigned(const F& from, T& to)
|
||||
/// Converts 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);
|
||||
POCO_VAR_RANGE_EXCEPTION ("Value too small", from);
|
||||
checkUpperLimit<std::make_unsigned_t<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.
|
||||
template <typename F, typename T, std::enable_if_t<std::is_floating_point_v<F>, bool> = true,
|
||||
std::enable_if_t<std::is_integral_v<T> && !std::is_signed_v<T>, T>* = nullptr>
|
||||
static void convertSignedFloatToUnsigned(const F& from, T& to)
|
||||
/// Converts 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);
|
||||
POCO_VAR_RANGE_EXCEPTION ("Value too small", from);
|
||||
checkUpperLimit<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.
|
||||
template <typename F, typename T,
|
||||
std::enable_if_t<std::is_integral_v<F> && !std::is_signed_v<F>, F>* = nullptr,
|
||||
std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>, T>* = nullptr>
|
||||
static void convertUnsignedToSigned(const F& from, T& to)
|
||||
/// Converts unsigned integral data types to signed integral data types.
|
||||
/// 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);
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::enable_if_t<std::is_signed_v<F> && std::is_signed_v<T> && (sizeof(F) <= sizeof(T))>* = nullptr>
|
||||
void convertToSigned(const F& from, T& to) const
|
||||
{
|
||||
to = static_cast<T>(from);
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::enable_if_t<std::is_signed_v<F> && std::is_signed_v<T> && (sizeof(F) > sizeof(T))>* = nullptr>
|
||||
void convertToSigned(const F& from, T& to) const
|
||||
{
|
||||
convertToSmaller(from, to);
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::enable_if_t<!std::is_signed_v<F> && std::is_signed_v<T>>* = nullptr>
|
||||
void convertToSigned(const F& from, T& to) const
|
||||
{
|
||||
convertUnsignedToSigned(from, to);
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::enable_if_t<!std::is_signed_v<F> && !std::is_signed_v<T> && (sizeof(F) <= sizeof(T))>* = nullptr>
|
||||
void convertToUnsigned(const F& from, T& to) const
|
||||
{
|
||||
to = static_cast<T>(from);
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::enable_if_t<!std::is_signed_v<F> && !std::is_signed_v<T> && (sizeof(F) > sizeof(T))>* = nullptr>
|
||||
void convertToUnsigned(const F& from, T& to) const
|
||||
{
|
||||
convertToSmallerUnsigned(from, to);
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::enable_if_t<std::is_signed_v<F> && !std::is_signed_v<T>>* = nullptr>
|
||||
void convertToUnsigned(const F& from, T& to) const
|
||||
{
|
||||
convertSignedToUnsigned(from, to);
|
||||
}
|
||||
|
||||
template <typename F, typename T,
|
||||
std::enable_if_t<std::is_integral_v<F>, bool> = true,
|
||||
std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
|
||||
static void convertToFP(F& from, T& to)
|
||||
/// Converts unsigned integral data types to floating-point data types.
|
||||
/// If the number of significant digits used for the integer vaue exceeds the number
|
||||
/// of available digits in the floatinng-point destination (ie. if precision would be lost
|
||||
/// by casting the value), RangeException is thrown.
|
||||
{
|
||||
if (isPrecisionLost<F, T>(from))
|
||||
POCO_VAR_RANGE_EXCEPTION ("Lost precision", from);
|
||||
to = static_cast<T>(from);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template <typename F, typename T>
|
||||
void checkUpperLimit(const F& from) const
|
||||
template <typename T>
|
||||
static constexpr T unpreserveSign(const T& value)
|
||||
{
|
||||
if (from > std::numeric_limits<T>::max())
|
||||
throw RangeException("Value too large.");
|
||||
}
|
||||
|
||||
template <typename F, typename T>
|
||||
void checkLowerLimit(const F& from) const
|
||||
{
|
||||
if (from < std::numeric_limits<T>::min())
|
||||
throw RangeException("Value too small.");
|
||||
}
|
||||
|
||||
template <typename F, typename T>
|
||||
void checkUpperLimitFloat(const F& from) const
|
||||
{
|
||||
if (std::is_floating_point<T>::value)
|
||||
if constexpr (std::is_signed_v<T>)
|
||||
{
|
||||
if (from > std::numeric_limits<T>::max())
|
||||
throw RangeException("Value too large.");
|
||||
return (value < 0) ? -value : value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Avoid clang -Wimplicit-int-float-conversion warning with an explicit cast.
|
||||
if (from > static_cast<F>(std::numeric_limits<T>::max()))
|
||||
throw RangeException("Value too large.");
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename F, typename T>
|
||||
void checkLowerLimitFloat(const F& from) const
|
||||
template <typename T, std::enable_if_t<std::is_same_v<T, bool>, bool> = true>
|
||||
static constexpr int numValDigits(const T& value)
|
||||
{
|
||||
if (std::is_floating_point<T>::value)
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_integral_v<T> && !std::is_same_v<T, bool>, bool> = true>
|
||||
static constexpr int numValDigits(const T& value)
|
||||
{
|
||||
using U = std::make_unsigned_t<T>;
|
||||
if (value == 0) return 0;
|
||||
int digitCount = 0;
|
||||
U locVal = static_cast<U>(unpreserveSign(value)); // to prevent sign preservation
|
||||
while (locVal >>= 1) ++digitCount;
|
||||
return digitCount;
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
|
||||
static constexpr int numValDigits(T value)
|
||||
{
|
||||
return numValDigits<int64_t>(static_cast<int64_t>(value));
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
|
||||
static constexpr int numTypeDigits()
|
||||
{
|
||||
return std::numeric_limits<T>::digits;
|
||||
}
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
|
||||
static constexpr int numTypeDigits()
|
||||
{
|
||||
return numValDigits(std::numeric_limits<T>::max());
|
||||
}
|
||||
|
||||
template <typename F, typename T,
|
||||
std::enable_if_t<std::is_integral_v<F>, bool> = true,
|
||||
std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
|
||||
static bool isPrecisionLost(const F& from)
|
||||
// Checks for loss of precision in integral -> floating point conversion.
|
||||
{
|
||||
return numValDigits(from) > numTypeDigits<T>();
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::enable_if_t<std::is_integral_v<F>, bool> = true>
|
||||
static void checkUpperLimit(const F& from)
|
||||
{
|
||||
if (from > static_cast<F>(std::numeric_limits<T>::max()))
|
||||
POCO_VAR_RANGE_EXCEPTION ("Value too big", from);
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::enable_if_t<std::is_integral_v<F>, bool> = true>
|
||||
static void checkLowerLimit(const F& from)
|
||||
{
|
||||
if (from < static_cast<F>(std::numeric_limits<T>::min()))
|
||||
POCO_VAR_RANGE_EXCEPTION ("Value too small", from);
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::enable_if_t<std::is_floating_point_v<F>, bool> = true>
|
||||
static void checkUpperLimit(const F& from)
|
||||
{
|
||||
if ((from > static_cast<F>(std::numeric_limits<T>::max())))
|
||||
POCO_VAR_RANGE_EXCEPTION ("Value too big", from);
|
||||
}
|
||||
|
||||
template <typename F, typename T, std::enable_if_t<std::is_floating_point_v<F>, bool> = true>
|
||||
static void checkLowerLimit(const F& from)
|
||||
{
|
||||
if constexpr(std::is_floating_point_v<T>)
|
||||
{
|
||||
if (from < -std::numeric_limits<T>::max())
|
||||
throw RangeException("Value too small.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Avoid clang -Wimplicit-int-float-conversion warning with an explicit cast.
|
||||
if (from < static_cast<F>(std::numeric_limits<T>::min()))
|
||||
throw RangeException("Value too small.");
|
||||
if (static_cast<F>(-std::numeric_limits<T>::max()) > from)
|
||||
POCO_VAR_RANGE_EXCEPTION ("Value too small", from);
|
||||
}
|
||||
else if (from < static_cast<F>(std::numeric_limits<T>::min()))
|
||||
POCO_VAR_RANGE_EXCEPTION ("Value too small", from);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -738,6 +842,287 @@ public:
|
||||
return typeid(T);
|
||||
}
|
||||
|
||||
void convert(Int8& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
convertToSigned(std::underlying_type_t<T>(_val), val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(Int16& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
convertToSigned(std::underlying_type_t<T>(_val), val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(Int32& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
convertToSigned(std::underlying_type_t<T>(_val), val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(Int64& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
convertToSigned(std::underlying_type_t<T>(_val), val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(UInt8& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
convertToUnsigned(std::underlying_type_t<T>(_val), val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(UInt16& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
convertToUnsigned(std::underlying_type_t<T>(_val), val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(UInt32& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
convertToUnsigned(std::underlying_type_t<T>(_val), val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(UInt64& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
convertToUnsigned(std::underlying_type_t<T>(_val), val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef POCO_INT64_IS_LONG
|
||||
|
||||
void convert(long long& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
convertToSigned(std::underlying_type_t<T>(_val), val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(unsigned long long& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
convertToUnsigned(std::underlying_type_t<T>(_val), val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void convert(bool& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
val = (std::underlying_type_t<T>(_val) != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
val = static_cast<float>(_val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
val = static_cast<double>(_val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
val = static_cast<char>(_val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(std::string& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
val = NumberFormatter::format(std::underlying_type_t<T>(_val));
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
void convert(Poco::UTF16String& val) const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
std::string str = NumberFormatter::format(std::underlying_type_t<T>(_val));
|
||||
Poco::UnicodeConverter::convert(str, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
VarHolder::convert(val);
|
||||
}
|
||||
}
|
||||
|
||||
bool isArray() const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return VarHolder::isArray();
|
||||
}
|
||||
}
|
||||
|
||||
bool isStruct() const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return VarHolder::isStruct();
|
||||
}
|
||||
}
|
||||
|
||||
bool isInteger() const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
return std::numeric_limits<std::underlying_type_t<T>>::is_integer;
|
||||
}
|
||||
else
|
||||
{
|
||||
return VarHolder::isInteger();
|
||||
}
|
||||
}
|
||||
|
||||
bool isSigned() const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
return std::numeric_limits<std::underlying_type_t<T>>::is_signed;
|
||||
}
|
||||
else
|
||||
{
|
||||
return VarHolder::isSigned();
|
||||
}
|
||||
}
|
||||
|
||||
bool isNumeric() const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
return std::numeric_limits<std::underlying_type_t<T>>::is_specialized;
|
||||
}
|
||||
else
|
||||
{
|
||||
return VarHolder::isNumeric();
|
||||
}
|
||||
}
|
||||
|
||||
bool isBoolean() const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return VarHolder::isBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
bool isString() const
|
||||
{
|
||||
if constexpr (std::is_enum_v<T>)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return VarHolder::isString();
|
||||
}
|
||||
}
|
||||
|
||||
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
|
||||
{
|
||||
return cloneHolder(pVarHolder, _val);
|
||||
@@ -835,12 +1220,12 @@ public:
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
val = static_cast<float>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
val = static_cast<double>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
@@ -991,12 +1376,12 @@ public:
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
val = static_cast<float>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
val = static_cast<double>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
@@ -1144,12 +1529,12 @@ public:
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
val = static_cast<float>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
val = static_cast<double>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
@@ -1296,12 +1681,12 @@ public:
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
val = static_cast<float>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
val = static_cast<double>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
@@ -1463,12 +1848,12 @@ public:
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
val = static_cast<float>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
val = static_cast<double>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
@@ -1615,12 +2000,12 @@ public:
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
val = static_cast<float>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
val = static_cast<double>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
@@ -1767,12 +2152,12 @@ public:
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
val = static_cast<float>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
val = static_cast<double>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
@@ -1919,12 +2304,12 @@ public:
|
||||
|
||||
void convert(float& val) const
|
||||
{
|
||||
val = static_cast<float>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(double& val) const
|
||||
{
|
||||
val = static_cast<double>(_val);
|
||||
convertToFP(_val, val);
|
||||
}
|
||||
|
||||
void convert(char& val) const
|
||||
@@ -4327,10 +4712,10 @@ private:
|
||||
};
|
||||
|
||||
|
||||
typedef std::vector<Var> Vector;
|
||||
typedef std::deque<Var> Deque;
|
||||
typedef std::list<Var> List;
|
||||
typedef Vector Array;
|
||||
using Vector = std::vector<Var>;
|
||||
using Deque = std::deque<Var>;
|
||||
using List = std::list<Var>;
|
||||
using Array = Vector;
|
||||
|
||||
|
||||
} } // namespace Poco::Dynamic
|
||||
|
||||
@@ -69,6 +69,18 @@ public:
|
||||
bool operator != (const VarIterator& other) const;
|
||||
/// Inequality operator.
|
||||
|
||||
bool operator < (const VarIterator& other) const;
|
||||
/// Less than operator.
|
||||
|
||||
bool operator > (const VarIterator& other) const;
|
||||
/// Greater than operator.
|
||||
|
||||
bool operator <= (const VarIterator& other) const;
|
||||
/// Less than or equal to operator.
|
||||
|
||||
bool operator >= (const VarIterator& other) const;
|
||||
/// Greater than or equal to operator.
|
||||
|
||||
Var& operator * () const;
|
||||
/// Returns value at the current position.
|
||||
|
||||
@@ -138,6 +150,30 @@ inline bool VarIterator::operator != (const VarIterator& other) const
|
||||
}
|
||||
|
||||
|
||||
inline bool VarIterator::operator < (const VarIterator& other) const
|
||||
{
|
||||
return _position < other._position;
|
||||
}
|
||||
|
||||
|
||||
inline bool VarIterator::operator > (const VarIterator& other) const
|
||||
{
|
||||
return _position > other._position;
|
||||
}
|
||||
|
||||
|
||||
inline bool VarIterator::operator <= (const VarIterator& other) const
|
||||
{
|
||||
return _position <= other._position;
|
||||
}
|
||||
|
||||
|
||||
inline bool VarIterator::operator >= (const VarIterator& other) const
|
||||
{
|
||||
return _position >= other._position;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Dynamic
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// VarVisitor.h
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Dynamic
|
||||
// Module: VarVisitor
|
||||
//
|
||||
// Definition of the VarVisitor class.
|
||||
//
|
||||
// Copyright (c) 2023, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_VarVisitor_INCLUDED
|
||||
#define Foundation_VarVisitor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Details {
|
||||
|
||||
|
||||
#ifndef POCO_DOC
|
||||
|
||||
|
||||
struct TypeInfoHash
|
||||
{
|
||||
inline std::size_t operator()(std::type_info const& t) const { return t.hash_code(); }
|
||||
};
|
||||
|
||||
|
||||
struct EqualRef
|
||||
{
|
||||
template <typename T>
|
||||
bool operator()(std::reference_wrapper<T> a, std::reference_wrapper<T> b) const
|
||||
{
|
||||
return a.get() == b.get();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
using TypeInfoRef = std::reference_wrapper<std::type_info const>;
|
||||
using HandlerCaller = std::function<void(const Poco::Dynamic::Var&)>;
|
||||
|
||||
|
||||
template <typename T>
|
||||
using HandlerPointer = void (*)(const T&);
|
||||
|
||||
|
||||
template <typename T>
|
||||
using Handler = std::function<void(const T&)>;
|
||||
|
||||
|
||||
#endif // POCO_DOC
|
||||
|
||||
|
||||
} // Details
|
||||
|
||||
|
||||
namespace Dynamic {
|
||||
|
||||
|
||||
class Foundation_API Visitor
|
||||
/// VarVisitor class.
|
||||
{
|
||||
std::unordered_map<Details::TypeInfoRef,
|
||||
Details::HandlerCaller,
|
||||
Details::TypeInfoHash,
|
||||
Details::EqualRef> _handlers;
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
bool addHandler(const Details::Handler<T>& f)
|
||||
/// Add handler for specific type T which holds in Var.
|
||||
/// This method is more safe, because it saves copy of handler : lambda or std::function.
|
||||
/// Returns true if handler was added.
|
||||
{
|
||||
auto result = _handlers.emplace(std::ref(typeid(T)),
|
||||
Details::HandlerCaller([handler = f](const Poco::Dynamic::Var& x)
|
||||
{
|
||||
handler(x.extract<T>());
|
||||
}));
|
||||
return result.second;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool addHandler(Details::HandlerPointer<T> f)
|
||||
/// Add handler for specific type T which holds in Var.
|
||||
/// This method is less safe, because it saves only copy of function pointer.
|
||||
/// Returns true if handler was added.
|
||||
{
|
||||
auto result = _handlers.emplace(std::ref(typeid(T)),
|
||||
Details::HandlerCaller([handlerPointer = f](const Poco::Dynamic::Var& x)
|
||||
{
|
||||
handlerPointer(x.extract<T>());
|
||||
}));
|
||||
return result.second;
|
||||
}
|
||||
|
||||
bool visit(const Poco::Dynamic::Var& x) const;
|
||||
/// Find handler for held type and if it exists call handler.
|
||||
/// Returns true if hanlder was found othrewise returns false.
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Dynamic
|
||||
|
||||
|
||||
#endif // Foundation_VarVisitor_INCLUDED
|
||||
Reference in new issue
Block a user