mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-16 07:07:13 +02:00
Update POCO library.
This commit is contained in:
@ -67,7 +67,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
Pair& swap(Pair& other)
|
||||
Pair& swap(Pair& other) noexcept
|
||||
/// Swaps the content of the two Pairs.
|
||||
{
|
||||
std::swap(_data, other._data);
|
||||
|
134
vendor/POCO/Foundation/include/Poco/Dynamic/Struct.h
vendored
134
vendor/POCO/Foundation/include/Poco/Dynamic/Struct.h
vendored
@ -32,6 +32,37 @@ namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
|
||||
template <typename S, typename I = typename S::ConstIterator>
|
||||
std::string structToString(const S& data, bool wrap = true)
|
||||
/// Utility function for converting DynamicStruct to std::string.
|
||||
/// Set wrap to false in order to prevent string values wrapping
|
||||
/// (useful to prevent JSON fragments from being treated as strings).
|
||||
{
|
||||
std::string val;
|
||||
val.append("{ ");
|
||||
I it = data.begin();
|
||||
I itEnd = data.end();
|
||||
if (!data.empty())
|
||||
{
|
||||
Var key(it->first);
|
||||
Impl::appendJSONKey(val, key);
|
||||
val.append(": ");
|
||||
Impl::appendJSONValue(val, it->second, wrap);
|
||||
++it;
|
||||
}
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
val.append(", ");
|
||||
Var key(it->first);
|
||||
Impl::appendJSONKey(val, key);
|
||||
val.append(": ");
|
||||
Impl::appendJSONValue(val, it->second, wrap);
|
||||
}
|
||||
val.append(" }");
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
template <typename K, typename M = std::map<K, Var>, typename S = std::set<K>>
|
||||
class Struct
|
||||
/// Struct allows to define a named collection of Var objects.
|
||||
@ -173,7 +204,7 @@ public:
|
||||
_data.clear();
|
||||
}
|
||||
|
||||
inline void swap(Struct& other)
|
||||
inline void swap(Struct& other) noexcept
|
||||
/// Swap content of Struct with another Struct
|
||||
{
|
||||
_data.swap(other._data);
|
||||
@ -226,11 +257,20 @@ public:
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::string toString() const
|
||||
std::string toString(bool wrap = true) const
|
||||
/// Returns the DynamicStruct as string.
|
||||
///
|
||||
/// To prevent unwanted string wrapping
|
||||
/// (eg. when a value is JSON string),
|
||||
/// `wrap` should be false. Note, however,
|
||||
/// that wrap argument is of a limited utility
|
||||
/// because it applies to the entire Struct,
|
||||
/// so it should not be relied on when mixed content
|
||||
/// (ie. plain string, which should be wrapped,
|
||||
/// and JSON-as-string entries, which shouldn't)
|
||||
/// is held.
|
||||
{
|
||||
std::string str;
|
||||
Var(*this).template convert<std::string>(str);
|
||||
return str;
|
||||
return structToString<Data, ConstIterator>(_data, wrap);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -332,26 +372,7 @@ public:
|
||||
|
||||
void convert(std::string& val) const
|
||||
{
|
||||
val.append("{ ");
|
||||
ValueType::ConstIterator it = _val.begin();
|
||||
ValueType::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(" }");
|
||||
val = structToString(_val);
|
||||
}
|
||||
|
||||
void convert(Poco::DateTime&) const
|
||||
@ -518,26 +539,7 @@ public:
|
||||
|
||||
void convert(std::string& val) const
|
||||
{
|
||||
val.append("{ ");
|
||||
ValueType::ConstIterator it = _val.begin();
|
||||
ValueType::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(" }");
|
||||
val = structToString(_val);
|
||||
}
|
||||
|
||||
void convert(Poco::DateTime&) const
|
||||
@ -704,26 +706,7 @@ public:
|
||||
|
||||
void convert(std::string& val) const
|
||||
{
|
||||
val.append("{ ");
|
||||
ValueType::ConstIterator it = _val.begin();
|
||||
ValueType::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(" }");
|
||||
val = structToString(_val);
|
||||
}
|
||||
|
||||
void convert(Poco::DateTime&) const
|
||||
@ -890,26 +873,7 @@ public:
|
||||
|
||||
void convert(std::string& val) const
|
||||
{
|
||||
val.append("{ ");
|
||||
ValueType::ConstIterator it = _val.begin();
|
||||
ValueType::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(" }");
|
||||
val = structToString(_val);
|
||||
}
|
||||
|
||||
void convert(Poco::DateTime&) const
|
||||
|
@ -91,15 +91,9 @@ public:
|
||||
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.
|
||||
@ -222,7 +216,7 @@ public:
|
||||
else if (!pHolder)
|
||||
throw InvalidAccessException("Can not extract empty value.");
|
||||
else
|
||||
throw BadCastException(format("Can not convert %s to %s.",
|
||||
throw BadCastException(Poco::format("Can not convert %s to %s.",
|
||||
std::string(pHolder->type().name()),
|
||||
std::string(typeid(T).name())));
|
||||
}
|
||||
@ -231,12 +225,8 @@ public:
|
||||
Var& operator = (const T& other)
|
||||
/// Assignment operator for assigning POD to Var
|
||||
{
|
||||
#ifdef POCO_NO_SOO
|
||||
Var tmp(other);
|
||||
swap(tmp);
|
||||
#else
|
||||
clear();
|
||||
construct(other);
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -612,79 +602,34 @@ private:
|
||||
return pStr->operator[](n);
|
||||
}
|
||||
|
||||
#ifdef POCO_NO_SOO
|
||||
|
||||
VarHolder* content() const
|
||||
{
|
||||
return _pHolder;
|
||||
}
|
||||
|
||||
void destruct()
|
||||
{
|
||||
if (!isEmpty()) delete content();
|
||||
}
|
||||
|
||||
VarHolder* _pHolder;
|
||||
|
||||
#else
|
||||
|
||||
VarHolder* content() const
|
||||
{
|
||||
return _placeholder.content();
|
||||
}
|
||||
|
||||
void destruct()
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
_placeholder.assign<VarHolderImpl<ValueType>, ValueType>(value);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
_placeholder.assign<VarHolderImpl<std::string>, std::string>(val);
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
@ -699,24 +644,17 @@ private:
|
||||
|
||||
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);
|
||||
_placeholder.swap(other._placeholder);
|
||||
}
|
||||
else
|
||||
{
|
||||
Var tmp(*this);
|
||||
try
|
||||
{
|
||||
if (_placeholder.isLocal()) destruct();
|
||||
construct(other);
|
||||
other = tmp;
|
||||
}
|
||||
@ -726,8 +664,6 @@ inline void Var::swap(Var& other)
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,10 +67,12 @@ void Foundation_API appendJSONString(std::string& val, const Var& any);
|
||||
/// regardless of the underlying type) and appends it to val.
|
||||
|
||||
|
||||
void Foundation_API appendJSONValue(std::string& val, const Var& any);
|
||||
void Foundation_API appendJSONValue(std::string& val, const Var& any, bool wrap = true);
|
||||
/// 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
|
||||
/// as string - see isJSONString() - it is wrapped into double quotes)
|
||||
/// and appends it to val.
|
||||
/// Wrapping can be prevented (useful for appending JSON fragments) by setting
|
||||
/// the wrap argument to false.
|
||||
|
||||
|
||||
template <typename C>
|
||||
@ -295,32 +297,18 @@ protected:
|
||||
|
||||
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
|
||||
/// Instantiates value holder wrapper.
|
||||
///
|
||||
/// Called from clone() member function of the implementation.
|
||||
///
|
||||
/// When the smal object optimization is enabled (POCO_NO_SOO not
|
||||
/// defined), 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
|
||||
return pVarHolder->assign<VarHolderImpl<T>, T>(val);
|
||||
}
|
||||
|
||||
template <typename F, typename T>
|
||||
@ -420,41 +408,52 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template <typename F, typename T>
|
||||
void checkUpperLimit(const F& from) const
|
||||
{
|
||||
if ((sizeof(T) < sizeof(F)) &&
|
||||
(from > static_cast<F>(std::numeric_limits<T>::max())))
|
||||
{
|
||||
throw RangeException("Value too large.");
|
||||
}
|
||||
else
|
||||
if (from > std::numeric_limits<T>::max())
|
||||
{
|
||||
throw RangeException("Value too large.");
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
template <typename F, typename T>
|
||||
void checkUpperLimitFloat(const F& from) const
|
||||
{
|
||||
if (std::is_floating_point<T>::value)
|
||||
{
|
||||
if (from > std::numeric_limits<T>::max())
|
||||
throw RangeException("Value too large.");
|
||||
}
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
template <typename F, typename T>
|
||||
void checkLowerLimitFloat(const F& from) const
|
||||
{
|
||||
if (std::is_floating_point<T>::value)
|
||||
{
|
||||
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.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -79,11 +79,11 @@ public:
|
||||
/// Advances by one position and returns current position.
|
||||
|
||||
VarIterator operator ++ (int) const;
|
||||
/// Advances by one position and returns copy of the iterator with
|
||||
/// 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
|
||||
/// Goes back by one position and returns copy of the iterator with
|
||||
/// previous current position.
|
||||
|
||||
VarIterator operator -- (int) const;
|
||||
@ -103,15 +103,15 @@ private:
|
||||
VarIterator();
|
||||
|
||||
void increment() const;
|
||||
/// Increments the iterator position by one.
|
||||
/// Increments the iterator position by one.
|
||||
/// Throws RangeException if position is out of range.
|
||||
|
||||
void decrement() const;
|
||||
/// Decrements the iterator position by one.
|
||||
/// 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.
|
||||
/// Sets the iterator position.
|
||||
/// Throws RangeException if position is out of range.
|
||||
|
||||
Var* _pVar;
|
||||
|
Reference in New Issue
Block a user