initial commit

This commit is contained in:
2025-09-01 20:47:58 +08:00
commit 12c51b5ddb
843 changed files with 475321 additions and 0 deletions
+412
View File
@@ -0,0 +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
+567
View File
@@ -0,0 +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 end = val.end();
for (; it != end; ++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
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +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