mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 17:30:44 +02:00
merge some changes from develop branch; modernize and clean-up code; remove support for compiling without POCO_WIN32_UTF8
This commit is contained in:
@@ -33,7 +33,7 @@ class Pair
|
||||
/// Pair allows to define a pair of values.
|
||||
{
|
||||
public:
|
||||
typedef typename std::pair<K, Var> Data;
|
||||
using Data = typename std::pair<K, Var>;
|
||||
|
||||
Pair(): _data()
|
||||
/// Creates an empty Pair
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
std::string toString()
|
||||
{
|
||||
std::string str;
|
||||
Var(*this).convert<std::string>(str);
|
||||
Var(*this).template convert<std::string>(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ private:
|
||||
|
||||
|
||||
template <>
|
||||
class VarHolderImpl<Pair<std::string> >: public VarHolder
|
||||
class VarHolderImpl<Pair<std::string>>: public VarHolder
|
||||
{
|
||||
public:
|
||||
VarHolderImpl(const Pair<std::string>& val): _val(val)
|
||||
@@ -255,7 +255,7 @@ private:
|
||||
|
||||
|
||||
template <>
|
||||
class VarHolderImpl<Pair<int> >: public VarHolder
|
||||
class VarHolderImpl<Pair<int>>: public VarHolder
|
||||
{
|
||||
public:
|
||||
VarHolderImpl(const Pair<int>& val): _val(val)
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Poco {
|
||||
namespace Dynamic {
|
||||
|
||||
|
||||
template <typename K, typename M = std::map<K, Var>, typename S = std::set<K> >
|
||||
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.
|
||||
{
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
typedef typename Struct<K>::Data::value_type ValueType;
|
||||
typedef typename Struct<K>::Data::size_type SizeType;
|
||||
typedef typename std::pair<typename Struct<K, M, S>::Iterator, bool> InsRetVal;
|
||||
typedef typename Poco::SharedPtr<Struct<K, M, S> > Ptr;
|
||||
typedef typename Poco::SharedPtr<Struct<K, M, S>> Ptr;
|
||||
|
||||
Struct(): _data()
|
||||
/// Creates an empty Struct
|
||||
@@ -62,16 +62,12 @@ public:
|
||||
assignMap(val);
|
||||
}
|
||||
|
||||
#ifdef POCO_ENABLE_CPP11
|
||||
|
||||
template <typename T>
|
||||
Struct(const OrderedMap<K, T>& val)
|
||||
{
|
||||
assignMap(val);
|
||||
}
|
||||
|
||||
#endif // POCO_ENABLE_CPP11
|
||||
|
||||
virtual ~Struct()
|
||||
/// Destroys the Struct.
|
||||
{
|
||||
@@ -171,18 +167,24 @@ public:
|
||||
_data.erase(it);
|
||||
}
|
||||
|
||||
inline void clear()
|
||||
/// Remove all elements from the struct
|
||||
{
|
||||
_data.clear();
|
||||
}
|
||||
|
||||
inline void swap(Struct& other)
|
||||
/// Swap content of Struct with another Struct
|
||||
{
|
||||
_data.swap(other._data);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
@@ -199,10 +201,35 @@ public:
|
||||
return keys;
|
||||
}
|
||||
|
||||
inline Var getVar(const K& key) const
|
||||
/// Returns the var value of the element with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
{
|
||||
ConstIterator it = find(key);
|
||||
if(it == end())
|
||||
{
|
||||
throw NotFoundException("Key not found in Struct");
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
template<typename DefT = Var>
|
||||
inline Var getVar(const K& key, const DefT& defaultValue) const
|
||||
/// Returns the var value of the element with the given name.
|
||||
/// or defaultValue if none is found.
|
||||
{
|
||||
ConstIterator it = find(key);
|
||||
if(it == end())
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
std::string str;
|
||||
Var(*this).convert<std::string>(str);
|
||||
Var(*this).template convert<std::string>(str);
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -222,7 +249,7 @@ private:
|
||||
|
||||
|
||||
template <>
|
||||
class VarHolderImpl<Struct<std::string, std::map<std::string, Var>, std::set<std::string> > >: public VarHolder
|
||||
class VarHolderImpl<Struct<std::string, std::map<std::string, Var>, std::set<std::string>>>: public VarHolder
|
||||
{
|
||||
public:
|
||||
typedef std::string KeyType;
|
||||
@@ -408,7 +435,7 @@ private:
|
||||
|
||||
|
||||
template <>
|
||||
class VarHolderImpl<Struct<int, std::map<int, Var>, std::set<int> > > : public VarHolder
|
||||
class VarHolderImpl<Struct<int, std::map<int, Var>, std::set<int>>> : public VarHolder
|
||||
{
|
||||
public:
|
||||
typedef int KeyType;
|
||||
@@ -593,11 +620,8 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#ifdef POCO_ENABLE_CPP11
|
||||
|
||||
|
||||
template <>
|
||||
class VarHolderImpl<Struct<std::string, Poco::OrderedMap<std::string, Var>, Poco::OrderedSet<std::string> > > : public VarHolder
|
||||
class VarHolderImpl<Struct<std::string, Poco::OrderedMap<std::string, Var>, Poco::OrderedSet<std::string>>> : public VarHolder
|
||||
{
|
||||
public:
|
||||
typedef std::string KeyType;
|
||||
@@ -783,7 +807,7 @@ private:
|
||||
|
||||
|
||||
template <>
|
||||
class VarHolderImpl<Struct<int, Poco::OrderedMap<int, Var>, Poco::OrderedSet<int> > > : public VarHolder
|
||||
class VarHolderImpl<Struct<int, Poco::OrderedMap<int, Var>, Poco::OrderedSet<int>>> : public VarHolder
|
||||
{
|
||||
public:
|
||||
typedef int KeyType;
|
||||
@@ -968,17 +992,12 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif // POCO_ENABLE_CPP11
|
||||
|
||||
|
||||
} // namespace Dynamic
|
||||
|
||||
|
||||
typedef Dynamic::Struct<std::string> DynamicStruct;
|
||||
typedef Dynamic::Struct<std::string, Poco::OrderedMap<std::string, Dynamic::Var>, Poco::OrderedSet<std::string>> OrderedDynamicStruct;
|
||||
|
||||
#ifdef POCO_ENABLE_CPP11
|
||||
typedef Dynamic::Struct<std::string, Poco::OrderedMap<std::string, Dynamic::Var>, Poco::OrderedSet<std::string> > OrderedDynamicStruct;
|
||||
#endif // POCO_ENABLE_CPP11
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
@@ -81,9 +81,9 @@ class Foundation_API Var
|
||||
/// VarHolderImpl is available. For supported types, see VarHolder documentation.
|
||||
{
|
||||
public:
|
||||
typedef SharedPtr<Var> Ptr;
|
||||
typedef Poco::Dynamic::VarIterator Iterator;
|
||||
typedef const VarIterator ConstIterator;
|
||||
using Ptr = SharedPtr<Var>;
|
||||
using Iterator = Poco::Dynamic::VarIterator;
|
||||
using ConstIterator = const VarIterator;
|
||||
|
||||
Var();
|
||||
/// Creates an empty Var.
|
||||
@@ -798,8 +798,7 @@ inline bool Var::isEmpty() const
|
||||
|
||||
inline bool Var::isArray() const
|
||||
{
|
||||
if (isEmpty() ||
|
||||
isString()) return false;
|
||||
if (isEmpty() || isString()) return false;
|
||||
|
||||
VarHolder* pHolder = content();
|
||||
return pHolder ? pHolder->isArray() : false;
|
||||
@@ -2231,6 +2230,110 @@ inline bool operator >= (const long& other, const Var& da)
|
||||
}
|
||||
|
||||
|
||||
inline unsigned long operator + (const unsigned long& other, const Var& da)
|
||||
/// Addition operator for adding Var to unsigned long
|
||||
{
|
||||
return other + da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline unsigned long operator - (const unsigned long& other, const Var& da)
|
||||
/// Subtraction operator for subtracting Var from unsigned long
|
||||
{
|
||||
return other - da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline unsigned long operator * (const unsigned long& other, const Var& da)
|
||||
/// Multiplication operator for multiplying Var with unsigned long
|
||||
{
|
||||
return other * da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline unsigned long operator / (const unsigned long& other, const Var& da)
|
||||
/// Division operator for dividing Var with unsigned long
|
||||
{
|
||||
return other / da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline unsigned long operator += (unsigned long& other, const Var& da)
|
||||
/// Addition assignment operator for adding Var to unsigned long
|
||||
{
|
||||
return other += da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline unsigned long operator -= (unsigned long& other, const Var& da)
|
||||
/// Subtraction assignment operator for subtracting Var from unsigned long
|
||||
{
|
||||
return other -= da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline unsigned long operator *= (unsigned long& other, const Var& da)
|
||||
/// Multiplication assignment operator for multiplying Var with unsigned long
|
||||
{
|
||||
return other *= da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline unsigned long operator /= (unsigned long& other, const Var& da)
|
||||
/// Division assignment operator for dividing Var with unsigned long
|
||||
{
|
||||
return other /= da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline bool operator == (const unsigned long& other, const Var& da)
|
||||
/// Equality operator for comparing Var with unsigned long
|
||||
{
|
||||
if (da.isEmpty()) return false;
|
||||
return other == da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline bool operator != (const unsigned long& other, const Var& da)
|
||||
/// Inequality operator for comparing Var with unsigned long
|
||||
{
|
||||
if (da.isEmpty()) return true;
|
||||
return other != da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline bool operator < (const unsigned long& other, const Var& da)
|
||||
/// Less than operator for comparing Var with unsigned long
|
||||
{
|
||||
if (da.isEmpty()) return false;
|
||||
return other < da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline bool operator <= (const unsigned long& other, const Var& da)
|
||||
/// Less than or equal operator for comparing Var with unsigned long
|
||||
{
|
||||
if (da.isEmpty()) return false;
|
||||
return other <= da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline bool operator > (const unsigned long& other, const Var& da)
|
||||
/// Greater than operator for comparing Var with unsigned long
|
||||
{
|
||||
if (da.isEmpty()) return false;
|
||||
return other > da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
inline bool operator >= (const unsigned long& other, const Var& da)
|
||||
/// Greater than or equal operator for comparing Var with unsigned long
|
||||
{
|
||||
if (da.isEmpty()) return false;
|
||||
return other >= da.convert<unsigned long>();
|
||||
}
|
||||
|
||||
|
||||
#endif // POCO_LONG_IS_64_BIT
|
||||
|
||||
|
||||
|
||||
@@ -670,6 +670,7 @@ inline bool VarHolder::isDateTime() const
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t VarHolder::size() const
|
||||
{
|
||||
return 1u;
|
||||
@@ -3576,7 +3577,7 @@ private:
|
||||
|
||||
|
||||
template <typename T>
|
||||
class VarHolderImpl<std::vector<T> >: public VarHolder
|
||||
class VarHolderImpl<std::vector<T>>: public VarHolder
|
||||
{
|
||||
public:
|
||||
VarHolderImpl(const std::vector<T>& val): _val(val)
|
||||
@@ -3641,7 +3642,7 @@ private:
|
||||
|
||||
|
||||
template <typename T>
|
||||
class VarHolderImpl<std::list<T> >: public VarHolder
|
||||
class VarHolderImpl<std::list<T>>: public VarHolder
|
||||
{
|
||||
public:
|
||||
VarHolderImpl(const std::list<T>& val): _val(val)
|
||||
@@ -3716,7 +3717,7 @@ private:
|
||||
|
||||
|
||||
template <typename T>
|
||||
class VarHolderImpl<std::deque<T> >: public VarHolder
|
||||
class VarHolderImpl<std::deque<T>>: public VarHolder
|
||||
{
|
||||
public:
|
||||
VarHolderImpl(const std::deque<T>& val): _val(val)
|
||||
|
||||
Reference in New Issue
Block a user