enh(Poco::Dynamic): Modernised code to use C++17 features.

This commit is contained in:
Matej Kenda
2025-01-08 12:50:09 +01:00
parent 4ca735d7d8
commit 7495f0592c
7 changed files with 942 additions and 1013 deletions

View File

@@ -44,7 +44,7 @@ std::string structToString(const S& data, bool wrap = true)
I itEnd = data.end();
if (!data.empty())
{
Var key(it->first);
const Var key(it->first);
Impl::appendJSONKey(val, key);
val.append(": ");
Impl::appendJSONValue(val, it->second, wrap);
@@ -53,7 +53,7 @@ std::string structToString(const S& data, bool wrap = true)
for (; it != itEnd; ++it)
{
val.append(", ");
Var key(it->first);
const Var key(it->first);
Impl::appendJSONKey(val, key);
val.append(": ");
Impl::appendJSONValue(val, it->second, wrap);
@@ -68,14 +68,14 @@ class Struct
/// Struct allows to define a named collection of Var objects.
{
public:
typedef M Data;
typedef S 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, M, S>::Iterator, bool> InsRetVal;
typedef typename Poco::SharedPtr<Struct<K, M, S>> Ptr;
using Data = M;
using NameSet = S;
using Iterator = typename Data::iterator;
using ConstIterator = typename Data::const_iterator;
using ValueType = typename Struct<K>::Data::value_type;
using SizeType = typename Struct<K>::Data::size_type;
using InsRetVal = typename std::pair<typename Struct<K, M, S>::Iterator, bool>;
using Ptr = typename Poco::SharedPtr<Struct<K, M, S>>;
Struct(): _data()
/// Creates an empty Struct
@@ -99,10 +99,8 @@ public:
assignMap(val);
}
virtual ~Struct()
virtual ~Struct() = default;
/// Destroys the Struct.
{
}
inline Var& operator [] (const K& name)
/// Returns the Var with the given name, creates an entry if not found.
@@ -114,7 +112,7 @@ public:
/// Returns the Var with the given name, throws a
/// NotFoundException if the data member is not found.
{
ConstIterator it = find(name);
const auto it = find(name);
if (it == end()) throw NotFoundException(name);
return it->second;
}
@@ -277,7 +275,7 @@ private:
template <typename T>
void assignMap(const T& map)
{
typedef typename T::const_iterator MapConstIterator;
using MapConstIterator = typename T::const_iterator;
MapConstIterator it = map.begin();
MapConstIterator end = map.end();
@@ -311,105 +309,103 @@ template <>
class VarHolderImpl<Struct<std::string, std::map<std::string, Var>, std::set<std::string>>>: public VarHolder
{
public:
typedef std::string KeyType;
typedef std::map<KeyType, Var> MapType;
typedef std::set<KeyType> SetType;
typedef Struct<KeyType, MapType, SetType> ValueType;
using KeyType = std::string;
using MapType = std::map<KeyType, Var>;
using SetType = std::set<KeyType>;
using ValueType = Struct<KeyType, MapType, SetType>;
VarHolderImpl(const ValueType& val): _val(val)
{
}
~VarHolderImpl()
{
}
~VarHolderImpl() override = default;
const std::type_info& type() const
const std::type_info& type() const override
{
return typeid(ValueType);
}
void convert(Int8&) const
void convert(Int8&) const override
{
throw BadCastException("Cannot cast Struct type to Int8");
}
void convert(Int16&) const
void convert(Int16&) const override
{
throw BadCastException("Cannot cast Struct type to Int16");
}
void convert(Int32&) const
void convert(Int32&) const override
{
throw BadCastException("Cannot cast Struct type to Int32");
}
void convert(Int64&) const
void convert(Int64&) const override
{
throw BadCastException("Cannot cast Struct type to Int64");
}
void convert(UInt8&) const
void convert(UInt8&) const override
{
throw BadCastException("Cannot cast Struct type to UInt8");
}
void convert(UInt16&) const
void convert(UInt16&) const override
{
throw BadCastException("Cannot cast Struct type to UInt16");
}
void convert(UInt32&) const
void convert(UInt32&) const override
{
throw BadCastException("Cannot cast Struct type to UInt32");
}
void convert(UInt64&) const
void convert(UInt64&) const override
{
throw BadCastException("Cannot cast Struct type to UInt64");
}
void convert(bool&) const
void convert(bool&) const override
{
throw BadCastException("Cannot cast Struct type to bool");
}
void convert(float&) const
void convert(float&) const override
{
throw BadCastException("Cannot cast Struct type to float");
}
void convert(double&) const
void convert(double&) const override
{
throw BadCastException("Cannot cast Struct type to double");
}
void convert(char&) const
void convert(char&) const override
{
throw BadCastException("Cannot cast Struct type to char");
}
void convert(std::string& val) const
void convert(std::string& val) const override
{
val = structToString(_val);
}
void convert(Poco::DateTime&) const
void convert(Poco::DateTime&) const override
{
throw BadCastException("Struct -> Poco::DateTime");
}
void convert(Poco::LocalDateTime&) const
void convert(Poco::LocalDateTime&) const override
{
throw BadCastException("Struct -> Poco::LocalDateTime");
}
void convert(Poco::Timestamp&) const
void convert(Poco::Timestamp&) const override
{
throw BadCastException("Struct -> Poco::Timestamp");
}
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = nullptr) const override
{
return cloneHolder(pVarHolder, _val);
}
@@ -419,42 +415,42 @@ public:
return _val;
}
bool isArray() const
bool isArray() const override
{
return false;
}
bool isStruct() const
bool isStruct() const override
{
return true;
}
bool isOrdered() const
bool isOrdered() const override
{
return false;
}
bool isInteger() const
bool isInteger() const override
{
return false;
}
bool isSigned() const
bool isSigned() const override
{
return false;
}
bool isNumeric() const
bool isNumeric() const override
{
return false;
}
bool isString() const
bool isString() const override
{
return false;
}
std::size_t size() const
std::size_t size() const override
{
return _val.size();
}
@@ -478,105 +474,103 @@ template <>
class VarHolderImpl<Struct<int, std::map<int, Var>, std::set<int>>> : public VarHolder
{
public:
typedef int KeyType;
typedef std::map<KeyType, Var> MapType;
typedef std::set<KeyType> SetType;
typedef Struct<KeyType, MapType, SetType> ValueType;
using KeyType = int;
using MapType = std::map<KeyType, Var>;
using SetType = std::set<KeyType>;
using ValueType = Struct<KeyType, MapType, SetType>;
VarHolderImpl(const ValueType& val) : _val(val)
{
}
~VarHolderImpl()
{
}
~VarHolderImpl() override = default;
const std::type_info& type() const
const std::type_info& type() const override
{
return typeid(ValueType);
}
void convert(Int8&) const
void convert(Int8&) const override
{
throw BadCastException("Cannot cast Struct type to Int8");
}
void convert(Int16&) const
void convert(Int16&) const override
{
throw BadCastException("Cannot cast Struct type to Int16");
}
void convert(Int32&) const
void convert(Int32&) const override
{
throw BadCastException("Cannot cast Struct type to Int32");
}
void convert(Int64&) const
void convert(Int64&) const override
{
throw BadCastException("Cannot cast Struct type to Int64");
}
void convert(UInt8&) const
void convert(UInt8&) const override
{
throw BadCastException("Cannot cast Struct type to UInt8");
}
void convert(UInt16&) const
void convert(UInt16&) const override
{
throw BadCastException("Cannot cast Struct type to UInt16");
}
void convert(UInt32&) const
void convert(UInt32&) const override
{
throw BadCastException("Cannot cast Struct type to UInt32");
}
void convert(UInt64&) const
void convert(UInt64&) const override
{
throw BadCastException("Cannot cast Struct type to UInt64");
}
void convert(bool&) const
void convert(bool&) const override
{
throw BadCastException("Cannot cast Struct type to bool");
}
void convert(float&) const
void convert(float&) const override
{
throw BadCastException("Cannot cast Struct type to float");
}
void convert(double&) const
void convert(double&) const override
{
throw BadCastException("Cannot cast Struct type to double");
}
void convert(char&) const
void convert(char&) const override
{
throw BadCastException("Cannot cast Struct type to char");
}
void convert(std::string& val) const
void convert(std::string& val) const override
{
val = structToString(_val);
}
void convert(Poco::DateTime&) const
void convert(Poco::DateTime&) const override
{
throw BadCastException("Struct -> Poco::DateTime");
}
void convert(Poco::LocalDateTime&) const
void convert(Poco::LocalDateTime&) const override
{
throw BadCastException("Struct -> Poco::LocalDateTime");
}
void convert(Poco::Timestamp&) const
void convert(Poco::Timestamp&) const override
{
throw BadCastException("Struct -> Poco::Timestamp");
}
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = nullptr) const override
{
return cloneHolder(pVarHolder, _val);
}
@@ -586,42 +580,42 @@ public:
return _val;
}
bool isArray() const
bool isArray() const override
{
return false;
}
bool isStruct() const
bool isStruct() const override
{
return true;
}
bool isOrdered() const
bool isOrdered() const override
{
return false;
}
bool isInteger() const
bool isInteger() const override
{
return false;
}
bool isSigned() const
bool isSigned() const override
{
return false;
}
bool isNumeric() const
bool isNumeric() const override
{
return false;
}
bool isString() const
bool isString() const override
{
return false;
}
std::size_t size() const
std::size_t size() const override
{
return _val.size();
}
@@ -645,105 +639,103 @@ template <>
class VarHolderImpl<Struct<std::string, Poco::OrderedMap<std::string, Var>, Poco::OrderedSet<std::string>>> : public VarHolder
{
public:
typedef std::string KeyType;
typedef Poco::OrderedMap<KeyType, Var> MapType;
typedef Poco::OrderedSet<KeyType> SetType;
typedef Struct<KeyType, MapType, SetType> ValueType;
using KeyType = std::string;
using MapType = Poco::OrderedMap<KeyType, Var>;
using SetType = Poco::OrderedSet<KeyType>;
using ValueType = Struct<KeyType, MapType, SetType>;
VarHolderImpl(const ValueType& val) : _val(val)
{
}
~VarHolderImpl()
{
}
~VarHolderImpl() override = default;
const std::type_info& type() const
const std::type_info& type() const override
{
return typeid(ValueType);
}
void convert(Int8&) const
void convert(Int8&) const override
{
throw BadCastException("Cannot cast Struct type to Int8");
}
void convert(Int16&) const
void convert(Int16&) const override
{
throw BadCastException("Cannot cast Struct type to Int16");
}
void convert(Int32&) const
void convert(Int32&) const override
{
throw BadCastException("Cannot cast Struct type to Int32");
}
void convert(Int64&) const
void convert(Int64&) const override
{
throw BadCastException("Cannot cast Struct type to Int64");
}
void convert(UInt8&) const
void convert(UInt8&) const override
{
throw BadCastException("Cannot cast Struct type to UInt8");
}
void convert(UInt16&) const
void convert(UInt16&) const override
{
throw BadCastException("Cannot cast Struct type to UInt16");
}
void convert(UInt32&) const
void convert(UInt32&) const override
{
throw BadCastException("Cannot cast Struct type to UInt32");
}
void convert(UInt64&) const
void convert(UInt64&) const override
{
throw BadCastException("Cannot cast Struct type to UInt64");
}
void convert(bool&) const
void convert(bool&) const override
{
throw BadCastException("Cannot cast Struct type to bool");
}
void convert(float&) const
void convert(float&) const override
{
throw BadCastException("Cannot cast Struct type to float");
}
void convert(double&) const
void convert(double&) const override
{
throw BadCastException("Cannot cast Struct type to double");
}
void convert(char&) const
void convert(char&) const override
{
throw BadCastException("Cannot cast Struct type to char");
}
void convert(std::string& val) const
void convert(std::string&val) const override
{
val = structToString(_val);
}
void convert(Poco::DateTime&) const
void convert(Poco::DateTime&) const override
{
throw BadCastException("Struct -> Poco::DateTime");
}
void convert(Poco::LocalDateTime&) const
void convert(Poco::LocalDateTime&) const override
{
throw BadCastException("Struct -> Poco::LocalDateTime");
}
void convert(Poco::Timestamp&) const
void convert(Poco::Timestamp&) const override
{
throw BadCastException("Struct -> Poco::Timestamp");
}
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = nullptr) const override
{
return cloneHolder(pVarHolder, _val);
}
@@ -753,42 +745,42 @@ public:
return _val;
}
bool isArray() const
bool isArray() const override
{
return false;
}
bool isStruct() const
bool isStruct() const override
{
return true;
}
bool isOrdered() const
bool isOrdered() const override
{
return true;
}
bool isInteger() const
bool isInteger() const override
{
return false;
}
bool isSigned() const
bool isSigned() const override
{
return false;
}
bool isNumeric() const
bool isNumeric() const override
{
return false;
}
bool isString() const
bool isString() const override
{
return false;
}
std::size_t size() const
std::size_t size() const override
{
return _val.size();
}
@@ -812,105 +804,103 @@ template <>
class VarHolderImpl<Struct<int, Poco::OrderedMap<int, Var>, Poco::OrderedSet<int>>> : public VarHolder
{
public:
typedef int KeyType;
typedef Poco::OrderedMap<KeyType, Var> MapType;
typedef Poco::OrderedSet<KeyType> SetType;
typedef Struct<KeyType, MapType, SetType> ValueType;
using KeyType = int;
using MapType = Poco::OrderedMap<KeyType, Var>;
using SetType = Poco::OrderedSet<KeyType>;
using ValueType = Struct<KeyType, MapType, SetType>;
VarHolderImpl(const ValueType& val) : _val(val)
{
}
~VarHolderImpl()
{
}
~VarHolderImpl() override = default;
const std::type_info& type() const
const std::type_info&type() const override
{
return typeid(ValueType);
}
void convert(Int8&) const
void convert(Int8&) const override
{
throw BadCastException("Cannot cast Struct type to Int8");
}
void convert(Int16&) const
void convert(Int16&) const override
{
throw BadCastException("Cannot cast Struct type to Int16");
}
void convert(Int32&) const
void convert(Int32&) const override
{
throw BadCastException("Cannot cast Struct type to Int32");
}
void convert(Int64&) const
void convert(Int64&) const override
{
throw BadCastException("Cannot cast Struct type to Int64");
}
void convert(UInt8&) const
void convert(UInt8&) const override
{
throw BadCastException("Cannot cast Struct type to UInt8");
}
void convert(UInt16&) const
void convert(UInt16&) const override
{
throw BadCastException("Cannot cast Struct type to UInt16");
}
void convert(UInt32&) const
void convert(UInt32&) const override
{
throw BadCastException("Cannot cast Struct type to UInt32");
}
void convert(UInt64&) const
void convert(UInt64&) const override
{
throw BadCastException("Cannot cast Struct type to UInt64");
}
void convert(bool&) const
void convert(bool&) const override
{
throw BadCastException("Cannot cast Struct type to bool");
}
void convert(float&) const
void convert(float&) const override
{
throw BadCastException("Cannot cast Struct type to float");
}
void convert(double&) const
void convert(double&) const override
{
throw BadCastException("Cannot cast Struct type to double");
}
void convert(char&) const
void convert(char&) const override
{
throw BadCastException("Cannot cast Struct type to char");
}
void convert(std::string& val) const
void convert(std::string& val) const override
{
val = structToString(_val);
}
void convert(Poco::DateTime&) const
void convert(Poco::DateTime&) const override
{
throw BadCastException("Struct -> Poco::DateTime");
}
void convert(Poco::LocalDateTime&) const
void convert(Poco::LocalDateTime&) const override
{
throw BadCastException("Struct -> Poco::LocalDateTime");
}
void convert(Poco::Timestamp&) const
void convert(Poco::Timestamp&) const override
{
throw BadCastException("Struct -> Poco::Timestamp");
}
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
VarHolder *clone(Placeholder<VarHolder>* pVarHolder = nullptr) const override
{
return cloneHolder(pVarHolder, _val);
}
@@ -920,42 +910,42 @@ public:
return _val;
}
bool isArray() const
bool isArray() const override
{
return false;
}
bool isStruct() const
bool isStruct() const override
{
return true;
}
bool isOrdered() const
bool isOrdered() const override
{
return true;
}
bool isInteger() const
bool isInteger() const override
{
return false;
}
bool isSigned() const
bool isSigned() const override
{
return false;
}
bool isNumeric() const
bool isNumeric() const override
{
return false;
}
bool isString() const
bool isString() const override
{
return false;
}
std::size_t size() const
std::size_t size() const override
{
return _val.size();
}