mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-16 23:12:57 +02:00
Usage modern C++ features on JSON modules (enhanced) (#4613)
This commit is contained in:
parent
891c1e03bf
commit
5117e27515
@ -217,7 +217,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void resetDynArray() const;
|
void resetDynArray() const;
|
||||||
|
|
||||||
typedef SharedPtr<Poco::Dynamic::Array> ArrayPtr;
|
using ArrayPtr = SharedPtr<Poco::Dynamic::Array>;
|
||||||
|
|
||||||
ValueVec _values;
|
ValueVec _values;
|
||||||
mutable ArrayPtr _pArray;
|
mutable ArrayPtr _pArray;
|
||||||
@ -340,98 +340,96 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~VarHolderImpl()
|
~VarHolderImpl() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::type_info& type() const
|
const std::type_info& type() const override
|
||||||
{
|
{
|
||||||
return typeid(JSON::Array::Ptr);
|
return typeid(JSON::Array::Ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int8&) const
|
void convert(Int8&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int16&) const
|
void convert(Int16&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int32&) const
|
void convert(Int32&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int64&) const
|
void convert(Int64&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt8&) const
|
void convert(UInt8&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt16&) const
|
void convert(UInt16&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt32&) const
|
void convert(UInt32&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt64&) const
|
void convert(UInt64&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(bool& value) const
|
void convert(bool& value) const override
|
||||||
{
|
{
|
||||||
value = !_val.isNull() && _val->size() > 0;
|
value = !_val.isNull() && _val->size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(float&) const
|
void convert(float&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(double&) const
|
void convert(double&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(char&) const
|
void convert(char&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(std::string& s) const
|
void convert(std::string& s) const override
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
_val->stringify(oss);
|
_val->stringify(oss);
|
||||||
s = oss.str();
|
s = oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(DateTime& /*val*/) const
|
void convert(DateTime& /*val*/) const override
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot convert Array to DateTime");
|
throw BadCastException("Cannot convert Array to DateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(LocalDateTime& /*ldt*/) const
|
void convert(LocalDateTime& /*ldt*/) const override
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot convert Array to LocalDateTime");
|
throw BadCastException("Cannot convert Array to LocalDateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Timestamp& /*ts*/) const
|
void convert(Timestamp& /*ts*/) const override
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot convert Array to Timestamp");
|
throw BadCastException("Cannot convert Array to Timestamp");
|
||||||
}
|
}
|
||||||
|
|
||||||
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
|
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = nullptr) const override
|
||||||
{
|
{
|
||||||
return cloneHolder(pVarHolder, _val);
|
return cloneHolder(pVarHolder, _val);
|
||||||
}
|
}
|
||||||
@ -441,22 +439,22 @@ public:
|
|||||||
return _val;
|
return _val;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInteger() const
|
bool isInteger() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSigned() const
|
bool isSigned() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNumeric() const
|
bool isNumeric() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isString() const
|
bool isString() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -474,98 +472,96 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~VarHolderImpl()
|
~VarHolderImpl() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::type_info& type() const
|
const std::type_info& type() const override
|
||||||
{
|
{
|
||||||
return typeid(JSON::Array);
|
return typeid(JSON::Array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int8&) const
|
void convert(Int8&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int16&) const
|
void convert(Int16&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int32&) const
|
void convert(Int32&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int64&) const
|
void convert(Int64&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt8&) const
|
void convert(UInt8&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt16&) const
|
void convert(UInt16&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt32&) const
|
void convert(UInt32&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt64&) const
|
void convert(UInt64&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(bool& value) const
|
void convert(bool& value) const override
|
||||||
{
|
{
|
||||||
value = _val.size() > 0;
|
value = _val.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(float&) const
|
void convert(float&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(double&) const
|
void convert(double&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(char&) const
|
void convert(char&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(std::string& s) const
|
void convert(std::string& s) const override
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
_val.stringify(oss);
|
_val.stringify(oss);
|
||||||
s = oss.str();
|
s = oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(DateTime& /*val*/) const
|
void convert(DateTime& /*val*/) const override
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot convert Array to DateTime");
|
throw BadCastException("Cannot convert Array to DateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(LocalDateTime& /*ldt*/) const
|
void convert(LocalDateTime& /*ldt*/) const override
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot convert Array to LocalDateTime");
|
throw BadCastException("Cannot convert Array to LocalDateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Timestamp& /*ts*/) const
|
void convert(Timestamp& /*ts*/) const override
|
||||||
{
|
{
|
||||||
throw BadCastException("Cannot convert Array to Timestamp");
|
throw BadCastException("Cannot convert Array to Timestamp");
|
||||||
}
|
}
|
||||||
|
|
||||||
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
|
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = nullptr) const override
|
||||||
{
|
{
|
||||||
return cloneHolder(pVarHolder, _val);
|
return cloneHolder(pVarHolder, _val);
|
||||||
}
|
}
|
||||||
@ -575,22 +571,22 @@ public:
|
|||||||
return _val;
|
return _val;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInteger() const
|
bool isInteger() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSigned() const
|
bool isSigned() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNumeric() const
|
bool isNumeric() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isString() const
|
bool isString() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ public:
|
|||||||
bool isArray(const std::string& key) const;
|
bool isArray(const std::string& key) const;
|
||||||
/// Returns true when the given property contains an array.
|
/// Returns true when the given property contains an array.
|
||||||
|
|
||||||
bool isArray(ConstIterator& it) const;
|
bool isArray(const ConstIterator& it) const;
|
||||||
/// Returns true when the given property contains an array.
|
/// Returns true when the given property contains an array.
|
||||||
|
|
||||||
bool isNull(const std::string& key) const;
|
bool isNull(const std::string& key) const;
|
||||||
@ -197,7 +197,7 @@ public:
|
|||||||
bool isObject(const std::string& key) const;
|
bool isObject(const std::string& key) const;
|
||||||
/// Returns true when the given property contains an object.
|
/// Returns true when the given property contains an object.
|
||||||
|
|
||||||
bool isObject(ConstIterator& it) const;
|
bool isObject(const ConstIterator& it) const;
|
||||||
/// Returns true when the given property contains an object.
|
/// Returns true when the given property contains an object.
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -207,7 +207,7 @@ public:
|
|||||||
/// def will be returned.
|
/// def will be returned.
|
||||||
{
|
{
|
||||||
T value = def;
|
T value = def;
|
||||||
ValueMap::const_iterator it = _values.find(key);
|
auto it = _values.find(key);
|
||||||
if (it != _values.end() && ! it->second.isEmpty())
|
if (it != _values.end() && ! it->second.isEmpty())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -255,9 +255,9 @@ public:
|
|||||||
/// Insertion order preservation property is left intact.
|
/// Insertion order preservation property is left intact.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::deque<ValueMap::const_iterator> KeyList;
|
using KeyList = std::deque<ValueMap::const_iterator>;
|
||||||
typedef Poco::DynamicStruct::Ptr StructPtr;
|
using StructPtr = Poco::DynamicStruct::Ptr;
|
||||||
typedef Poco::OrderedDynamicStruct::Ptr OrdStructPtr;
|
using OrdStructPtr = Poco::OrderedDynamicStruct::Ptr;
|
||||||
|
|
||||||
void syncKeys(const KeyList& keys);
|
void syncKeys(const KeyList& keys);
|
||||||
|
|
||||||
@ -311,30 +311,28 @@ private:
|
|||||||
|
|
||||||
if (obj->_preserveInsOrder)
|
if (obj->_preserveInsOrder)
|
||||||
{
|
{
|
||||||
KeyList::const_iterator it = obj->_keys.begin();
|
for (const auto& it: obj->_keys)
|
||||||
KeyList::const_iterator end = obj->_keys.end();
|
|
||||||
for (; it != end; ++it)
|
|
||||||
{
|
{
|
||||||
if (obj->isObject((*it)->first))
|
if (obj->isObject(it->first))
|
||||||
{
|
{
|
||||||
Object::Ptr pObj = obj->getObject((*it)->first);
|
Object::Ptr pObj = obj->getObject(it->first);
|
||||||
S str = makeStructImpl<S>(pObj);
|
S str = makeStructImpl<S>(pObj);
|
||||||
ds.insert((*it)->first, str);
|
ds.insert(it->first, str);
|
||||||
}
|
}
|
||||||
else if (obj->isArray((*it)->first))
|
else if (obj->isArray(it->first))
|
||||||
{
|
{
|
||||||
Array::Ptr pArr = obj->getArray((*it)->first);
|
Array::Ptr pArr = obj->getArray(it->first);
|
||||||
std::vector<Poco::Dynamic::Var> v = Poco::JSON::Array::makeArray(pArr);
|
std::vector<Poco::Dynamic::Var> v = Poco::JSON::Array::makeArray(pArr);
|
||||||
ds.insert((*it)->first, v);
|
ds.insert(it->first, v);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ds.insert((*it)->first, (*it)->second);
|
ds.insert(it->first, it->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ConstIterator it = obj->begin();
|
auto it = obj->begin();
|
||||||
ConstIterator end = obj->end();
|
const auto end = obj->end();
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
{
|
{
|
||||||
if (obj->isObject(it))
|
if (obj->isObject(it))
|
||||||
@ -430,19 +428,19 @@ inline Object::ConstIterator Object::end() const
|
|||||||
|
|
||||||
inline bool Object::has(const std::string& key) const
|
inline bool Object::has(const std::string& key) const
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator it = _values.find(key);
|
const auto it = _values.find(key);
|
||||||
return it != _values.end();
|
return it != _values.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Object::isArray(const std::string& key) const
|
inline bool Object::isArray(const std::string& key) const
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator it = _values.find(key);
|
const auto it = _values.find(key);
|
||||||
return isArray(it);
|
return isArray(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Object::isArray(ConstIterator& it) const
|
inline bool Object::isArray(const ConstIterator& it) const
|
||||||
{
|
{
|
||||||
return it != _values.end() && (it->second.type() == typeid(Array::Ptr) || it->second.type() == typeid(Array));
|
return it != _values.end() && (it->second.type() == typeid(Array::Ptr) || it->second.type() == typeid(Array));
|
||||||
}
|
}
|
||||||
@ -450,19 +448,19 @@ inline bool Object::isArray(ConstIterator& it) const
|
|||||||
|
|
||||||
inline bool Object::isNull(const std::string& key) const
|
inline bool Object::isNull(const std::string& key) const
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator it = _values.find(key);
|
const auto it = _values.find(key);
|
||||||
return it == _values.end() || it->second.isEmpty();
|
return it == _values.end() || it->second.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Object::isObject(const std::string& key) const
|
inline bool Object::isObject(const std::string& key) const
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator it = _values.find(key);
|
const auto it = _values.find(key);
|
||||||
return isObject(it);
|
return isObject(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Object::isObject(ConstIterator& it) const
|
inline bool Object::isObject(const ConstIterator& it) const
|
||||||
{
|
{
|
||||||
return it != _values.end() && (it->second.type() == typeid(Object::Ptr) || it->second.type() == typeid(Object));
|
return it != _values.end() && (it->second.type() == typeid(Object::Ptr) || it->second.type() == typeid(Object));
|
||||||
}
|
}
|
||||||
@ -478,8 +476,8 @@ inline void Object::remove(const std::string& key)
|
|||||||
{
|
{
|
||||||
if (_preserveInsOrder)
|
if (_preserveInsOrder)
|
||||||
{
|
{
|
||||||
KeyList::iterator it = _keys.begin();
|
auto it = _keys.begin();
|
||||||
KeyList::iterator end = _keys.end();
|
const auto end = _keys.end();
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
{
|
{
|
||||||
if (key == (*it)->first)
|
if (key == (*it)->first)
|
||||||
@ -508,7 +506,7 @@ inline const Dynamic::Var& Object::getValue(ValueMap::const_iterator& it) const
|
|||||||
|
|
||||||
inline const Dynamic::Var& Object::getValue(KeyList::const_iterator& it) const
|
inline const Dynamic::Var& Object::getValue(KeyList::const_iterator& it) const
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator itv = _values.find((*it)->first);
|
const auto itv = _values.find((*it)->first);
|
||||||
if (itv != _values.end())
|
if (itv != _values.end())
|
||||||
return itv->second;
|
return itv->second;
|
||||||
else
|
else
|
||||||
@ -531,101 +529,99 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~VarHolderImpl()
|
~VarHolderImpl() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::type_info& type() const
|
const std::type_info& type() const override
|
||||||
{
|
{
|
||||||
return typeid(JSON::Object::Ptr);
|
return typeid(JSON::Object::Ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int8&) const
|
void convert(Int8&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int16&) const
|
void convert(Int16&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int32&) const
|
void convert(Int32&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int64&) const
|
void convert(Int64&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt8&) const
|
void convert(UInt8&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt16&) const
|
void convert(UInt16&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt32&) const
|
void convert(UInt32&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt64&) const
|
void convert(UInt64&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(bool& value) const
|
void convert(bool& value) const override
|
||||||
{
|
{
|
||||||
value = !_val.isNull() && _val->size() > 0;
|
value = !_val.isNull() && _val->size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(float&) const
|
void convert(float&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(double&) const
|
void convert(double&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(char&) const
|
void convert(char&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(std::string& s) const
|
void convert(std::string& s) const override
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
_val->stringify(oss);
|
_val->stringify(oss);
|
||||||
s = oss.str();
|
s = oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(DateTime& /*val*/) const
|
void convert(DateTime& /*val*/) const override
|
||||||
{
|
{
|
||||||
//TODO: val = _val;
|
//TODO: val = _val;
|
||||||
throw NotImplementedException("Conversion not implemented: JSON:Object => DateTime");
|
throw NotImplementedException("Conversion not implemented: JSON:Object => DateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(LocalDateTime& /*ldt*/) const
|
void convert(LocalDateTime& /*ldt*/) const override
|
||||||
{
|
{
|
||||||
//TODO: ldt = _val.timestamp();
|
//TODO: ldt = _val.timestamp();
|
||||||
throw NotImplementedException("Conversion not implemented: JSON:Object => LocalDateTime");
|
throw NotImplementedException("Conversion not implemented: JSON:Object => LocalDateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Timestamp& /*ts*/) const
|
void convert(Timestamp& /*ts*/) const override
|
||||||
{
|
{
|
||||||
//TODO: ts = _val.timestamp();
|
//TODO: ts = _val.timestamp();
|
||||||
throw NotImplementedException("Conversion not implemented: JSON:Object => Timestamp");
|
throw NotImplementedException("Conversion not implemented: JSON:Object => Timestamp");
|
||||||
}
|
}
|
||||||
|
|
||||||
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
|
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = nullptr) const override
|
||||||
{
|
{
|
||||||
return cloneHolder(pVarHolder, _val);
|
return cloneHolder(pVarHolder, _val);
|
||||||
}
|
}
|
||||||
@ -635,27 +631,27 @@ public:
|
|||||||
return _val;
|
return _val;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isArray() const
|
bool isArray() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInteger() const
|
bool isInteger() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSigned() const
|
bool isSigned() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNumeric() const
|
bool isNumeric() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isString() const
|
bool isString() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -673,101 +669,99 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~VarHolderImpl()
|
~VarHolderImpl() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::type_info& type() const
|
const std::type_info& type() const override
|
||||||
{
|
{
|
||||||
return typeid(JSON::Object);
|
return typeid(JSON::Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int8&) const
|
void convert(Int8&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int16&) const
|
void convert(Int16&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int32&) const
|
void convert(Int32&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Int64&) const
|
void convert(Int64&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt8&) const
|
void convert(UInt8&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt16&) const
|
void convert(UInt16&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt32&) const
|
void convert(UInt32&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(UInt64&) const
|
void convert(UInt64&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(bool& value) const
|
void convert(bool& value) const override
|
||||||
{
|
{
|
||||||
value = _val.size() > 0;
|
value = _val.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(float&) const
|
void convert(float&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(double&) const
|
void convert(double&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(char&) const
|
void convert(char&) const override
|
||||||
{
|
{
|
||||||
throw BadCastException();
|
throw BadCastException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(std::string& s) const
|
void convert(std::string& s) const override
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
_val.stringify(oss);
|
_val.stringify(oss);
|
||||||
s = oss.str();
|
s = oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(DateTime& /*val*/) const
|
void convert(DateTime& /*val*/) const override
|
||||||
{
|
{
|
||||||
//TODO: val = _val;
|
//TODO: val = _val;
|
||||||
throw NotImplementedException("Conversion not implemented: JSON:Object => DateTime");
|
throw NotImplementedException("Conversion not implemented: JSON:Object => DateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(LocalDateTime& /*ldt*/) const
|
void convert(LocalDateTime& /*ldt*/) const override
|
||||||
{
|
{
|
||||||
//TODO: ldt = _val.timestamp();
|
//TODO: ldt = _val.timestamp();
|
||||||
throw NotImplementedException("Conversion not implemented: JSON:Object => LocalDateTime");
|
throw NotImplementedException("Conversion not implemented: JSON:Object => LocalDateTime");
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert(Timestamp& /*ts*/) const
|
void convert(Timestamp& /*ts*/) const override
|
||||||
{
|
{
|
||||||
//TODO: ts = _val.timestamp();
|
//TODO: ts = _val.timestamp();
|
||||||
throw NotImplementedException("Conversion not implemented: JSON:Object => Timestamp");
|
throw NotImplementedException("Conversion not implemented: JSON:Object => Timestamp");
|
||||||
}
|
}
|
||||||
|
|
||||||
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
|
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = nullptr) const override
|
||||||
{
|
{
|
||||||
return cloneHolder(pVarHolder, _val);
|
return cloneHolder(pVarHolder, _val);
|
||||||
}
|
}
|
||||||
@ -777,27 +771,27 @@ public:
|
|||||||
return _val;
|
return _val;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isArray() const
|
bool isArray() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInteger() const
|
bool isInteger() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSigned() const
|
bool isSigned() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNumeric() const
|
bool isNumeric() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isString() const
|
bool isString() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -40,61 +40,61 @@ public:
|
|||||||
/// inside objects is preserved. Otherwise, items
|
/// inside objects is preserved. Otherwise, items
|
||||||
/// will be sorted by keys.
|
/// will be sorted by keys.
|
||||||
|
|
||||||
virtual ~ParseHandler();
|
~ParseHandler() override;
|
||||||
/// Destroys the ParseHandler.
|
/// Destroys the ParseHandler.
|
||||||
|
|
||||||
virtual void reset();
|
void reset() override;
|
||||||
/// Resets the handler state.
|
/// Resets the handler state.
|
||||||
|
|
||||||
void startObject();
|
void startObject() override;
|
||||||
/// Handles a '{'; a new object is started.
|
/// Handles a '{'; a new object is started.
|
||||||
|
|
||||||
void endObject();
|
void endObject() override;
|
||||||
/// Handles a '}'; the object is closed.
|
/// Handles a '}'; the object is closed.
|
||||||
|
|
||||||
void startArray();
|
void startArray() override;
|
||||||
/// Handles a '['; a new array is started.
|
/// Handles a '['; a new array is started.
|
||||||
|
|
||||||
void endArray();
|
void endArray() override;
|
||||||
/// Handles a ']'; the array is closed.
|
/// Handles a ']'; the array is closed.
|
||||||
|
|
||||||
void key(const std::string& k);
|
void key(const std::string& k) override;
|
||||||
/// A key is read
|
/// A key is read
|
||||||
|
|
||||||
Dynamic::Var asVar() const;
|
Dynamic::Var asVar() const override;
|
||||||
/// Returns the result of the parser (an object or an array).
|
/// Returns the result of the parser (an object or an array).
|
||||||
|
|
||||||
virtual void value(int v);
|
void value(int v) override;
|
||||||
/// An integer value is read
|
/// An integer value is read
|
||||||
|
|
||||||
virtual void value(unsigned v);
|
void value(unsigned v) override;
|
||||||
/// An unsigned value is read. This will only be triggered if the
|
/// An unsigned value is read. This will only be triggered if the
|
||||||
/// value cannot fit into a signed int.
|
/// value cannot fit into a signed int.
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
virtual void value(Int64 v);
|
void value(Int64 v) override;
|
||||||
/// A 64-bit integer value is read
|
/// A 64-bit integer value is read
|
||||||
|
|
||||||
virtual void value(UInt64 v);
|
void value(UInt64 v) override;
|
||||||
/// An unsigned 64-bit integer value is read. This will only be
|
/// An unsigned 64-bit integer value is read. This will only be
|
||||||
/// triggered if the value cannot fit into a signed 64-bit integer.
|
/// triggered if the value cannot fit into a signed 64-bit integer.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virtual void value(const std::string& s);
|
void value(const std::string& s) override;
|
||||||
/// A string value is read.
|
/// A string value is read.
|
||||||
|
|
||||||
virtual void value(double d);
|
void value(double d) override;
|
||||||
/// A double value is read.
|
/// A double value is read.
|
||||||
|
|
||||||
virtual void value(bool b);
|
void value(bool b) override;
|
||||||
/// A boolean value is read.
|
/// A boolean value is read.
|
||||||
|
|
||||||
virtual void null();
|
void null() override;
|
||||||
/// A null value is read.
|
/// A null value is read.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setValue(const Poco::Dynamic::Var& value);
|
void setValue(const Poco::Dynamic::Var& value);
|
||||||
typedef std::stack<Dynamic::Var> Stack;
|
using Stack = std::stack<Dynamic::Var>;
|
||||||
|
|
||||||
Stack _stack;
|
Stack _stack;
|
||||||
std::string _key;
|
std::string _key;
|
||||||
|
@ -20,11 +20,7 @@
|
|||||||
|
|
||||||
#include "Poco/JSON/JSON.h"
|
#include "Poco/JSON/JSON.h"
|
||||||
#include "Poco/JSON/ParserImpl.h"
|
#include "Poco/JSON/ParserImpl.h"
|
||||||
#include "Poco/JSON/Object.h"
|
|
||||||
#include "Poco/JSON/Array.h"
|
|
||||||
#include "Poco/JSON/ParseHandler.h"
|
#include "Poco/JSON/ParseHandler.h"
|
||||||
#include "Poco/JSON/JSONException.h"
|
|
||||||
#include "Poco/UTF8Encoding.h"
|
|
||||||
#include "Poco/Dynamic/Var.h"
|
#include "Poco/Dynamic/Var.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -68,7 +64,7 @@ public:
|
|||||||
Parser(const Handler::Ptr& pHandler = new ParseHandler);
|
Parser(const Handler::Ptr& pHandler = new ParseHandler);
|
||||||
/// Creates JSON Parser, using the given Handler and buffer size.
|
/// Creates JSON Parser, using the given Handler and buffer size.
|
||||||
|
|
||||||
virtual ~Parser();
|
~Parser() override;
|
||||||
/// Destroys JSON Parser.
|
/// Destroys JSON Parser.
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
@ -19,11 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/JSON/JSON.h"
|
#include "Poco/JSON/JSON.h"
|
||||||
#include "Poco/JSON/Object.h"
|
|
||||||
#include "Poco/JSON/Array.h"
|
|
||||||
#include "Poco/JSON/ParseHandler.h"
|
#include "Poco/JSON/ParseHandler.h"
|
||||||
#include "Poco/JSON/JSONException.h"
|
|
||||||
#include "Poco/UTF8Encoding.h"
|
|
||||||
#include "Poco/Dynamic/Var.h"
|
#include "Poco/Dynamic/Var.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -183,7 +179,7 @@ inline Dynamic::Var ParserImpl::asVarImpl() const
|
|||||||
{
|
{
|
||||||
if (_pHandler) return _pHandler->asVar();
|
if (_pHandler) return _pHandler->asVar();
|
||||||
|
|
||||||
return Dynamic::Var();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,56 +44,56 @@ public:
|
|||||||
PrintHandler(std::ostream& out, unsigned indent = 0, int options = Poco::JSON_WRAP_STRINGS);
|
PrintHandler(std::ostream& out, unsigned indent = 0, int options = Poco::JSON_WRAP_STRINGS);
|
||||||
/// Creates the PrintHandler.
|
/// Creates the PrintHandler.
|
||||||
|
|
||||||
~PrintHandler();
|
~PrintHandler() override;
|
||||||
/// Destroys the PrintHandler.
|
/// Destroys the PrintHandler.
|
||||||
|
|
||||||
void reset();
|
void reset() override;
|
||||||
/// Resets the handler state.
|
/// Resets the handler state.
|
||||||
|
|
||||||
void startObject();
|
void startObject() override;
|
||||||
/// The parser has read a '{'; a new object is started.
|
/// The parser has read a '{'; a new object is started.
|
||||||
/// If indent is greater than zero, a newline will be appended.
|
/// If indent is greater than zero, a newline will be appended.
|
||||||
|
|
||||||
void endObject();
|
void endObject() override;
|
||||||
/// The parser has read a '}'; the object is closed.
|
/// The parser has read a '}'; the object is closed.
|
||||||
|
|
||||||
void startArray();
|
void startArray() override;
|
||||||
/// The parser has read a [; a new array will be started.
|
/// The parser has read a [; a new array will be started.
|
||||||
/// If indent is greater than zero, a newline will be appended.
|
/// If indent is greater than zero, a newline will be appended.
|
||||||
|
|
||||||
void endArray();
|
void endArray() override;
|
||||||
/// The parser has read a ]; the array is closed.
|
/// The parser has read a ]; the array is closed.
|
||||||
|
|
||||||
void key(const std::string& k);
|
void key(const std::string& k) override;
|
||||||
/// A key of an object is read; it will be written to the output,
|
/// A key of an object is read; it will be written to the output,
|
||||||
/// followed by a ':'. If indent is greater than zero, the colon
|
/// followed by a ':'. If indent is greater than zero, the colon
|
||||||
/// is padded by a space before and after.
|
/// is padded by a space before and after.
|
||||||
|
|
||||||
void null();
|
void null() override;
|
||||||
/// A null value is read; "null" will be written to the output.
|
/// A null value is read; "null" will be written to the output.
|
||||||
|
|
||||||
void value(int v);
|
void value(int v) override;
|
||||||
/// An integer value is read.
|
/// An integer value is read.
|
||||||
|
|
||||||
void value(unsigned v);
|
void value(unsigned v) override;
|
||||||
/// An unsigned value is read. This will only be triggered if the
|
/// An unsigned value is read. This will only be triggered if the
|
||||||
/// value cannot fit into a signed int.
|
/// value cannot fit into a signed int.
|
||||||
|
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
void value(Int64 v);
|
void value(Int64 v) override;
|
||||||
/// A 64-bit integer value is read; it will be written to the output.
|
/// A 64-bit integer value is read; it will be written to the output.
|
||||||
|
|
||||||
void value(UInt64 v);
|
void value(UInt64 v) override;
|
||||||
/// An unsigned 64-bit integer value is read; it will be written to the output.
|
/// An unsigned 64-bit integer value is read; it will be written to the output.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void value(const std::string& value);
|
void value(const std::string& value) override;
|
||||||
/// A string value is read; it will be formatted and written to the output.
|
/// A string value is read; it will be formatted and written to the output.
|
||||||
|
|
||||||
void value(double d);
|
void value(double d) override;
|
||||||
/// A double value is read; it will be written to the output.
|
/// A double value is read; it will be written to the output.
|
||||||
|
|
||||||
void value(bool b);
|
void value(bool b) override;
|
||||||
/// A boolean value is read; it will be written to the output.
|
/// A boolean value is read; it will be written to the output.
|
||||||
|
|
||||||
void comma();
|
void comma();
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "Poco/JSON/JSON.h"
|
#include "Poco/JSON/JSON.h"
|
||||||
#include "Poco/JSON/Template.h"
|
#include "Poco/JSON/Template.h"
|
||||||
#include "Poco/Path.h"
|
#include "Poco/Path.h"
|
||||||
#include "Poco/SharedPtr.h"
|
|
||||||
#include "Poco/Logger.h"
|
#include "Poco/Logger.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/JSON/Parser.h"
|
#include "Poco/JSON/Parser.h"
|
||||||
#include "Poco/JSON/ParseHandler.h"
|
#include "Poco/JSON/Object.h"
|
||||||
#include "Poco/JSON/JSONException.h"
|
#include "Poco/JSON/JSONException.h"
|
||||||
#include "Poco/Environment.h"
|
#include "Poco/Environment.h"
|
||||||
#include "Poco/Path.h"
|
#include "Poco/Path.h"
|
||||||
@ -20,7 +20,7 @@
|
|||||||
#include "Poco/StreamCopier.h"
|
#include "Poco/StreamCopier.h"
|
||||||
#include "Poco/Stopwatch.h"
|
#include "Poco/Stopwatch.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
@ -42,14 +42,7 @@ Array::Array(int options):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Array::Array(const Array& other) :
|
Array::Array(const Array& other) = default;
|
||||||
_values(other._values),
|
|
||||||
_pArray(other._pArray),
|
|
||||||
_modified(other._modified),
|
|
||||||
_escapeUnicode(other._escapeUnicode),
|
|
||||||
_lowercaseHex(other._lowercaseHex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Array::Array(Array&& other) noexcept:
|
Array::Array(Array&& other) noexcept:
|
||||||
@ -88,9 +81,7 @@ Array& Array::operator = (Array&& other) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Array::~Array()
|
Array::~Array() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Var Array::get(unsigned int index) const
|
Var Array::get(unsigned int index) const
|
||||||
@ -176,7 +167,7 @@ void Array::stringify(std::ostream& out, unsigned int indent, int step) const
|
|||||||
|
|
||||||
if (indent > 0) out << std::endl;
|
if (indent > 0) out << std::endl;
|
||||||
|
|
||||||
for (ValueVec::const_iterator it = _values.begin(); it != _values.end();)
|
for (auto it = _values.begin(); it != _values.end();)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < indent; i++) out << ' ';
|
for (int i = 0; i < indent; i++) out << ' ';
|
||||||
|
|
||||||
@ -210,14 +201,14 @@ void Array::resetDynArray() const
|
|||||||
|
|
||||||
Array::operator const Poco::Dynamic::Array& () const
|
Array::operator const Poco::Dynamic::Array& () const
|
||||||
{
|
{
|
||||||
if (!_values.size())
|
if (_values.empty())
|
||||||
{
|
{
|
||||||
resetDynArray();
|
resetDynArray();
|
||||||
}
|
}
|
||||||
else if (_modified)
|
else if (_modified)
|
||||||
{
|
{
|
||||||
ValueVec::const_iterator it = _values.begin();
|
auto it = _values.begin();
|
||||||
ValueVec::const_iterator end = _values.end();
|
const auto end = _values.end();
|
||||||
resetDynArray();
|
resetDynArray();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (; it != end; ++it, ++index)
|
for (; it != end; ++it, ++index)
|
||||||
@ -246,8 +237,8 @@ Poco::Dynamic::Array Array::makeArray(const JSON::Array::Ptr& arr)
|
|||||||
{
|
{
|
||||||
Poco::Dynamic::Array vec;
|
Poco::Dynamic::Array vec;
|
||||||
|
|
||||||
JSON::Array::ConstIterator it = arr->begin();
|
auto it = arr->begin();
|
||||||
JSON::Array::ConstIterator end = arr->end();
|
const auto end = arr->end();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (; it != end; ++it, ++index)
|
for (; it != end; ++it, ++index)
|
||||||
{
|
{
|
||||||
@ -274,7 +265,7 @@ Poco::Dynamic::Array Array::makeArray(const JSON::Array::Ptr& arr)
|
|||||||
void Array::clear()
|
void Array::clear()
|
||||||
{
|
{
|
||||||
_values.clear();
|
_values.clear();
|
||||||
_pArray = 0;
|
_pArray = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,32 +13,27 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/JSON/Handler.h"
|
#include "Poco/JSON/Handler.h"
|
||||||
#include "Poco/JSON/Object.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
namespace JSON {
|
namespace JSON {
|
||||||
|
|
||||||
|
|
||||||
Handler::Handler()
|
Handler::Handler() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Handler::~Handler()
|
Handler::~Handler() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Dynamic::Var Handler::asVar() const
|
Dynamic::Var Handler::asVar() const
|
||||||
{
|
{
|
||||||
return Dynamic::Var();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Poco::DynamicStruct Handler::asStruct() const
|
Poco::DynamicStruct Handler::asStruct() const
|
||||||
{
|
{
|
||||||
return Poco::DynamicStruct();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
#include "Poco/JSON/Object.h"
|
#include "Poco/JSON/Object.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
|
|
||||||
using Poco::Dynamic::Var;
|
using Poco::Dynamic::Var;
|
||||||
@ -43,11 +42,12 @@ Object::Object(int options):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Object::Object(const Object& other) : _values(other._values),
|
Object::Object(const Object& other) :
|
||||||
|
_values(other._values),
|
||||||
_preserveInsOrder(other._preserveInsOrder),
|
_preserveInsOrder(other._preserveInsOrder),
|
||||||
_escapeUnicode(other._escapeUnicode),
|
_escapeUnicode(other._escapeUnicode),
|
||||||
_lowercaseHex(other._lowercaseHex),
|
_lowercaseHex(other._lowercaseHex),
|
||||||
_pStruct(!other._modified ? other._pStruct : 0),
|
_pStruct(!other._modified ? other._pStruct : nullptr),
|
||||||
_modified(other._modified)
|
_modified(other._modified)
|
||||||
{
|
{
|
||||||
syncKeys(other._keys);
|
syncKeys(other._keys);
|
||||||
@ -67,9 +67,7 @@ Object::Object(Object&& other) noexcept:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Object::~Object()
|
Object::~Object() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Object &Object::operator = (const Object &other)
|
Object &Object::operator = (const Object &other)
|
||||||
@ -81,7 +79,7 @@ Object &Object::operator = (const Object &other)
|
|||||||
_preserveInsOrder = other._preserveInsOrder;
|
_preserveInsOrder = other._preserveInsOrder;
|
||||||
_escapeUnicode = other._escapeUnicode;
|
_escapeUnicode = other._escapeUnicode;
|
||||||
_lowercaseHex = other._lowercaseHex;
|
_lowercaseHex = other._lowercaseHex;
|
||||||
_pStruct = !other._modified ? other._pStruct : 0;
|
_pStruct = !other._modified ? other._pStruct : nullptr;
|
||||||
_modified = other._modified;
|
_modified = other._modified;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@ -108,11 +106,10 @@ void Object::syncKeys(const KeyList& keys)
|
|||||||
if(_preserveInsOrder)
|
if(_preserveInsOrder)
|
||||||
{
|
{
|
||||||
// update iterators in _keys to point to copied _values
|
// update iterators in _keys to point to copied _values
|
||||||
for(KeyList::const_iterator it = keys.begin(); it != keys.end(); ++it)
|
for (const auto& key : keys) {
|
||||||
{
|
auto itv = _values.find(key->first);
|
||||||
ValueMap::const_iterator itv = _values.find((*it)->first);
|
poco_assert(itv != _values.end());
|
||||||
poco_assert (itv != _values.end());
|
_keys.emplace_back(itv);
|
||||||
_keys.push_back(itv);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,37 +117,37 @@ void Object::syncKeys(const KeyList& keys)
|
|||||||
|
|
||||||
Var Object::get(const std::string& key) const
|
Var Object::get(const std::string& key) const
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator it = _values.find(key);
|
auto it = _values.find(key);
|
||||||
if (it != _values.end())
|
if (it != _values.end())
|
||||||
{
|
{
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Var();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Array::Ptr Object::getArray(const std::string& key) const
|
Array::Ptr Object::getArray(const std::string& key) const
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator it = _values.find(key);
|
auto it = _values.find(key);
|
||||||
if ((it != _values.end()) && (it->second.type() == typeid(Array::Ptr)))
|
if ((it != _values.end()) && (it->second.type() == typeid(Array::Ptr)))
|
||||||
{
|
{
|
||||||
return it->second.extract<Array::Ptr>();
|
return it->second.extract<Array::Ptr>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Object::Ptr Object::getObject(const std::string& key) const
|
Object::Ptr Object::getObject(const std::string& key) const
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator it = _values.find(key);
|
auto it = _values.find(key);
|
||||||
if ((it != _values.end()) && (it->second.type() == typeid(Object::Ptr)))
|
if ((it != _values.end()) && (it->second.type() == typeid(Object::Ptr)))
|
||||||
{
|
{
|
||||||
return it->second.extract<Object::Ptr>();
|
return it->second.extract<Object::Ptr>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -159,16 +156,14 @@ void Object::getNames(NameList& names) const
|
|||||||
names.clear();
|
names.clear();
|
||||||
if (_preserveInsOrder)
|
if (_preserveInsOrder)
|
||||||
{
|
{
|
||||||
for(KeyList::const_iterator it = _keys.begin(); it != _keys.end(); ++it)
|
for (const auto& _key : _keys) {
|
||||||
{
|
names.push_back(_key->first);
|
||||||
names.push_back((*it)->first);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(ValueMap::const_iterator it = _values.begin(); it != _values.end(); ++it)
|
for (const auto& _value : _values) {
|
||||||
{
|
names.push_back(_value.first);
|
||||||
names.push_back(it->first);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,8 +190,8 @@ void Object::stringify(std::ostream& out, unsigned int indent, int step) const
|
|||||||
|
|
||||||
const std::string& Object::getKey(KeyList::const_iterator& iter) const
|
const std::string& Object::getKey(KeyList::const_iterator& iter) const
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator it = _values.begin();
|
auto it = _values.begin();
|
||||||
ValueMap::const_iterator end = _values.end();
|
auto end = _values.end();
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
{
|
{
|
||||||
if (it == *iter) return it->first;
|
if (it == *iter) return it->first;
|
||||||
@ -212,13 +207,13 @@ Object& Object::set(const std::string& key, const Dynamic::Var& value)
|
|||||||
if (!ret.second) ret.first->second = value;
|
if (!ret.second) ret.first->second = value;
|
||||||
if (_preserveInsOrder)
|
if (_preserveInsOrder)
|
||||||
{
|
{
|
||||||
KeyList::iterator it = _keys.begin();
|
auto it = _keys.begin();
|
||||||
KeyList::iterator end = _keys.end();
|
const auto end = _keys.end();
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
{
|
{
|
||||||
if (key == (*it)->first) return *this;
|
if (key == (*it)->first) return *this;
|
||||||
}
|
}
|
||||||
_keys.push_back(ret.first);
|
_keys.emplace_back(ret.first);
|
||||||
}
|
}
|
||||||
_modified = true;
|
_modified = true;
|
||||||
return *this;
|
return *this;
|
||||||
@ -259,14 +254,14 @@ void Object::resetDynStruct() const
|
|||||||
|
|
||||||
Object::operator const Poco::DynamicStruct& () const
|
Object::operator const Poco::DynamicStruct& () const
|
||||||
{
|
{
|
||||||
if (!_values.size())
|
if (_values.empty())
|
||||||
{
|
{
|
||||||
resetDynStruct(_pStruct);
|
resetDynStruct(_pStruct);
|
||||||
}
|
}
|
||||||
else if (_modified)
|
else if (_modified)
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator it = _values.begin();
|
auto it = _values.begin();
|
||||||
ValueMap::const_iterator end = _values.end();
|
const auto end = _values.end();
|
||||||
resetDynStruct(_pStruct);
|
resetDynStruct(_pStruct);
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
{
|
{
|
||||||
@ -291,7 +286,7 @@ Object::operator const Poco::DynamicStruct& () const
|
|||||||
|
|
||||||
Object::operator const Poco::OrderedDynamicStruct& () const
|
Object::operator const Poco::OrderedDynamicStruct& () const
|
||||||
{
|
{
|
||||||
if (!_values.size())
|
if (_values.empty())
|
||||||
{
|
{
|
||||||
resetDynStruct(_pOrdStruct);
|
resetDynStruct(_pOrdStruct);
|
||||||
}
|
}
|
||||||
@ -299,8 +294,8 @@ Object::operator const Poco::OrderedDynamicStruct& () const
|
|||||||
{
|
{
|
||||||
if (_preserveInsOrder)
|
if (_preserveInsOrder)
|
||||||
{
|
{
|
||||||
KeyList::const_iterator it = _keys.begin();
|
auto it = _keys.begin();
|
||||||
KeyList::const_iterator end = _keys.end();
|
const auto end = _keys.end();
|
||||||
resetDynStruct(_pOrdStruct);
|
resetDynStruct(_pOrdStruct);
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
{
|
{
|
||||||
@ -320,8 +315,8 @@ Object::operator const Poco::OrderedDynamicStruct& () const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ValueMap::const_iterator it = _values.begin();
|
auto it = _values.begin();
|
||||||
ValueMap::const_iterator end = _values.end();
|
const auto end = _values.end();
|
||||||
resetDynStruct(_pOrdStruct);
|
resetDynStruct(_pOrdStruct);
|
||||||
for (; it != end; ++it)
|
for (; it != end; ++it)
|
||||||
{
|
{
|
||||||
@ -349,7 +344,7 @@ void Object::clear()
|
|||||||
{
|
{
|
||||||
_values.clear();
|
_values.clear();
|
||||||
_keys.clear();
|
_keys.clear();
|
||||||
_pStruct = 0;
|
_pStruct = nullptr;
|
||||||
_modified = true;
|
_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +30,7 @@ ParseHandler::ParseHandler(bool preserveObjectOrder) : Handler(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ParseHandler::~ParseHandler()
|
ParseHandler::~ParseHandler() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ParseHandler::reset()
|
void ParseHandler::reset()
|
||||||
@ -67,7 +65,7 @@ void ParseHandler::startObject()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_stack.push(newObj);
|
_stack.emplace(newObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -102,7 +100,7 @@ void ParseHandler::startArray()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_stack.push(newArr);
|
_stack.emplace(newArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -120,7 +118,7 @@ void ParseHandler::key(const std::string& k)
|
|||||||
|
|
||||||
void ParseHandler::setValue(const Var& value)
|
void ParseHandler::setValue(const Var& value)
|
||||||
{
|
{
|
||||||
if (_stack.size())
|
if (!_stack.empty())
|
||||||
{
|
{
|
||||||
Var parent = _stack.top();
|
Var parent = _stack.top();
|
||||||
|
|
||||||
|
@ -13,16 +13,9 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/JSON/Parser.h"
|
#include "Poco/JSON/Parser.h"
|
||||||
#include "Poco/JSON/JSONException.h"
|
|
||||||
#include "Poco/Ascii.h"
|
|
||||||
#include "Poco/Token.h"
|
|
||||||
#include "Poco/UTF8Encoding.h"
|
|
||||||
#include "Poco/String.h"
|
|
||||||
#undef min
|
#undef min
|
||||||
#undef max
|
#undef max
|
||||||
#include <limits>
|
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
#include <istream>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@ -35,9 +28,7 @@ Parser::Parser(const Handler::Ptr& pHandler):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Parser::~Parser()
|
Parser::~Parser() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Parser::setHandler(const Handler::Ptr& pHandler)
|
void Parser::setHandler(const Handler::Ptr& pHandler)
|
||||||
|
@ -11,23 +11,20 @@
|
|||||||
// SPDX-License-Identifier: BSL-1.0
|
// SPDX-License-Identifier: BSL-1.0
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <Poco/JSON/ParserImpl.h>
|
||||||
|
#include <Poco/JSON/JSONException.h>
|
||||||
|
#include <Poco/StreamCopier.h>
|
||||||
|
|
||||||
#include "Poco/JSON/Parser.h"
|
|
||||||
#include "Poco/JSON/JSONException.h"
|
|
||||||
#include "Poco/Ascii.h"
|
|
||||||
#include "Poco/Token.h"
|
|
||||||
#include "Poco/UTF8Encoding.h"
|
|
||||||
#include "Poco/String.h"
|
|
||||||
#include "Poco/StreamCopier.h"
|
|
||||||
#undef min
|
#undef min
|
||||||
#undef max
|
#undef max
|
||||||
#include <limits>
|
|
||||||
#include <clocale>
|
|
||||||
#include <istream>
|
#include <istream>
|
||||||
|
#include <streambuf>
|
||||||
|
#include <clocale>
|
||||||
#include "pdjson.h"
|
#include "pdjson.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct json_stream json_stream;
|
using json_stream = struct json_stream;
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@ -38,13 +35,13 @@ extern "C"
|
|||||||
{
|
{
|
||||||
static int istream_get(void* ptr)
|
static int istream_get(void* ptr)
|
||||||
{
|
{
|
||||||
std::streambuf* pBuf = reinterpret_cast<std::streambuf*>(ptr);
|
auto pBuf = reinterpret_cast<std::streambuf*>(ptr);
|
||||||
return pBuf->sbumpc();
|
return pBuf->sbumpc();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int istream_peek(void* ptr)
|
static int istream_peek(void* ptr)
|
||||||
{
|
{
|
||||||
std::streambuf* pBuf = reinterpret_cast<std::streambuf*>(ptr);
|
auto pBuf = reinterpret_cast<std::streambuf*>(ptr);
|
||||||
return pBuf->sgetc();
|
return pBuf->sgetc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,8 +164,7 @@ void ParserImpl::stripComments(std::string& json)
|
|||||||
std::string::iterator it = json.begin();
|
std::string::iterator it = json.begin();
|
||||||
for (; it != json.end();)
|
for (; it != json.end();)
|
||||||
{
|
{
|
||||||
if (*it == '"' && !inString) inString = true;
|
inString = *it == '"' && !inString;
|
||||||
else inString = false;
|
|
||||||
if (!inString)
|
if (!inString)
|
||||||
{
|
{
|
||||||
if (*it == '/' && it + 1 != json.end() && *(it + 1) == '*')
|
if (*it == '/' && it + 1 != json.end() && *(it + 1) == '*')
|
||||||
@ -220,7 +216,7 @@ void ParserImpl::handleObject()
|
|||||||
while (tok != JSON_OBJECT_END && checkError())
|
while (tok != JSON_OBJECT_END && checkError())
|
||||||
{
|
{
|
||||||
json_next(_pJSON);
|
json_next(_pJSON);
|
||||||
if (_pHandler) _pHandler->key(std::string(json_get_string(_pJSON, NULL)));
|
if (_pHandler) _pHandler->key(std::string(json_get_string(_pJSON, nullptr)));
|
||||||
handle();
|
handle();
|
||||||
tok = json_peek(_pJSON);
|
tok = json_peek(_pJSON);
|
||||||
}
|
}
|
||||||
@ -252,7 +248,7 @@ void ParserImpl::handle()
|
|||||||
case JSON_NUMBER:
|
case JSON_NUMBER:
|
||||||
if (_pHandler)
|
if (_pHandler)
|
||||||
{
|
{
|
||||||
std::string str(json_get_string(_pJSON, NULL));
|
std::string str(json_get_string(_pJSON, nullptr));
|
||||||
if (str.find(_decimalPoint) != str.npos || str.find('e') != str.npos || str.find('E') != str.npos)
|
if (str.find(_decimalPoint) != str.npos || str.find('e') != str.npos || str.find('E') != str.npos)
|
||||||
{
|
{
|
||||||
_pHandler->value(NumberParser::parseFloat(str));
|
_pHandler->value(NumberParser::parseFloat(str));
|
||||||
|
@ -41,9 +41,7 @@ PrintHandler::PrintHandler(std::ostream& out, unsigned indent, int options):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PrintHandler::~PrintHandler()
|
PrintHandler::~PrintHandler() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PrintHandler::reset()
|
void PrintHandler::reset()
|
||||||
|
@ -37,9 +37,7 @@ Query::Query(const Var& source): _source(source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Query::~Query()
|
Query::~Query() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Object::Ptr Query::findObject(const std::string& path) const
|
Object::Ptr Query::findObject(const std::string& path) const
|
||||||
@ -51,7 +49,7 @@ Object::Ptr Query::findObject(const std::string& path) const
|
|||||||
else if (result.type() == typeid(Object))
|
else if (result.type() == typeid(Object))
|
||||||
return new Object(result.extract<Object>());
|
return new Object(result.extract<Object>());
|
||||||
|
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -79,7 +77,7 @@ Array::Ptr Query::findArray(const std::string& path) const
|
|||||||
else if (result.type() == typeid(Array))
|
else if (result.type() == typeid(Array))
|
||||||
return new Array(result.extract<Array>());
|
return new Array(result.extract<Array>());
|
||||||
|
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -150,7 +148,7 @@ Var Query::find(const std::string& path) const
|
|||||||
|
|
||||||
if (!result.isEmpty() && !indexes.empty())
|
if (!result.isEmpty() && !indexes.empty())
|
||||||
{
|
{
|
||||||
for (auto i: indexes)
|
for (const auto& i: indexes)
|
||||||
{
|
{
|
||||||
if (result.type() == typeid(Array::Ptr))
|
if (result.type() == typeid(Array::Ptr))
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "Poco/JSON/Stringifier.h"
|
#include "Poco/JSON/Stringifier.h"
|
||||||
#include "Poco/JSON/Array.h"
|
#include "Poco/JSON/Array.h"
|
||||||
#include "Poco/JSON/Object.h"
|
#include "Poco/JSON/Object.h"
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
|
|
||||||
using Poco::Dynamic::Var;
|
using Poco::Dynamic::Var;
|
||||||
@ -34,28 +33,28 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
|
|||||||
|
|
||||||
if (any.type() == typeid(Object))
|
if (any.type() == typeid(Object))
|
||||||
{
|
{
|
||||||
Object& o = const_cast<Object&>(any.extract<Object>());
|
auto& o = const_cast<Object&>(any.extract<Object>());
|
||||||
o.setEscapeUnicode(escapeUnicode);
|
o.setEscapeUnicode(escapeUnicode);
|
||||||
o.setLowercaseHex(lowercaseHex);
|
o.setLowercaseHex(lowercaseHex);
|
||||||
o.stringify(out, indent == 0 ? 0 : indent, step);
|
o.stringify(out, indent == 0 ? 0 : indent, step);
|
||||||
}
|
}
|
||||||
else if (any.type() == typeid(Array))
|
else if (any.type() == typeid(Array))
|
||||||
{
|
{
|
||||||
Array& a = const_cast<Array&>(any.extract<Array>());
|
auto& a = const_cast<Array&>(any.extract<Array>());
|
||||||
a.setEscapeUnicode(escapeUnicode);
|
a.setEscapeUnicode(escapeUnicode);
|
||||||
a.setLowercaseHex(lowercaseHex);
|
a.setLowercaseHex(lowercaseHex);
|
||||||
a.stringify(out, indent == 0 ? 0 : indent, step);
|
a.stringify(out, indent == 0 ? 0 : indent, step);
|
||||||
}
|
}
|
||||||
else if (any.type() == typeid(Object::Ptr))
|
else if (any.type() == typeid(Object::Ptr))
|
||||||
{
|
{
|
||||||
Object::Ptr& o = const_cast<Object::Ptr&>(any.extract<Object::Ptr>());
|
auto& o = const_cast<Object::Ptr&>(any.extract<Object::Ptr>());
|
||||||
o->setEscapeUnicode(escapeUnicode);
|
o->setEscapeUnicode(escapeUnicode);
|
||||||
o->setLowercaseHex(lowercaseHex);
|
o->setLowercaseHex(lowercaseHex);
|
||||||
o->stringify(out, indent == 0 ? 0 : indent, step);
|
o->stringify(out, indent == 0 ? 0 : indent, step);
|
||||||
}
|
}
|
||||||
else if (any.type() == typeid(Array::Ptr))
|
else if (any.type() == typeid(Array::Ptr))
|
||||||
{
|
{
|
||||||
Array::Ptr& a = const_cast<Array::Ptr&>(any.extract<Array::Ptr>());
|
auto& a = const_cast<Array::Ptr&>(any.extract<Array::Ptr>());
|
||||||
a->setEscapeUnicode(escapeUnicode);
|
a->setEscapeUnicode(escapeUnicode);
|
||||||
a->setLowercaseHex(lowercaseHex);
|
a->setLowercaseHex(lowercaseHex);
|
||||||
a->stringify(out, indent == 0 ? 0 : indent, step);
|
a->stringify(out, indent == 0 ? 0 : indent, step);
|
||||||
@ -66,7 +65,7 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
|
|||||||
}
|
}
|
||||||
else if (any.isNumeric() || any.isBoolean())
|
else if (any.isNumeric() || any.isBoolean())
|
||||||
{
|
{
|
||||||
std::string value = any.convert<std::string>();
|
auto value = any.convert<std::string>();
|
||||||
if ((Poco::icompare(value, "nan") == 0) ||
|
if ((Poco::icompare(value, "nan") == 0) ||
|
||||||
(Poco::icompare(value, "inf") == 0)) value = "null";
|
(Poco::icompare(value, "inf") == 0)) value = "null";
|
||||||
if (any.type() == typeid(char)) formatString(value, out, options);
|
if (any.type() == typeid(char)) formatString(value, out, options);
|
||||||
@ -74,7 +73,7 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
|
|||||||
}
|
}
|
||||||
else if (any.isString() || any.isDateTime() || any.isDate() || any.isTime())
|
else if (any.isString() || any.isDateTime() || any.isDate() || any.isTime())
|
||||||
{
|
{
|
||||||
std::string value = any.convert<std::string>();
|
auto value = any.convert<std::string>();
|
||||||
formatString(value, out, options);
|
formatString(value, out, options);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -32,17 +32,13 @@ POCO_IMPLEMENT_EXCEPTION(JSONTemplateException, Exception, "Template Exception")
|
|||||||
class Part
|
class Part
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Part()
|
Part() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~Part()
|
virtual ~Part() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void render(const Var& data, std::ostream& out) const = 0;
|
virtual void render(const Var& data, std::ostream& out) const = 0;
|
||||||
|
|
||||||
typedef std::vector<SharedPtr<Part>> VectorParts;
|
using VectorParts = std::vector<SharedPtr<Part>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -57,11 +53,9 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~StringPart()
|
~StringPart() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void render(const Var& data, std::ostream& out) const
|
void render(const Var& data, std::ostream& out) const override
|
||||||
{
|
{
|
||||||
out << _content;
|
out << _content;
|
||||||
}
|
}
|
||||||
@ -84,20 +78,16 @@ private:
|
|||||||
class MultiPart: public Part
|
class MultiPart: public Part
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MultiPart()
|
MultiPart() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~MultiPart()
|
~MultiPart() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void addPart(Part* part)
|
virtual void addPart(Part* part)
|
||||||
{
|
{
|
||||||
_parts.push_back(part);
|
_parts.emplace_back(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(const Var& data, std::ostream& out) const
|
void render(const Var& data, std::ostream& out) const override
|
||||||
{
|
{
|
||||||
for (const auto& p: _parts)
|
for (const auto& p: _parts)
|
||||||
{
|
{
|
||||||
@ -117,11 +107,9 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~EchoPart()
|
~EchoPart() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void render(const Var& data, std::ostream& out) const
|
void render(const Var& data, std::ostream& out) const override
|
||||||
{
|
{
|
||||||
Query query(data);
|
Query query(data);
|
||||||
Var value = query.find(_query);
|
Var value = query.find(_query);
|
||||||
@ -144,9 +132,7 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~LogicQuery()
|
virtual ~LogicQuery() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool apply(const Var& data) const
|
virtual bool apply(const Var& data) const
|
||||||
{
|
{
|
||||||
@ -161,7 +147,7 @@ public:
|
|||||||
// An empty string must result in false, otherwise true
|
// An empty string must result in false, otherwise true
|
||||||
// Which is not the case when we convert to bool with Var
|
// Which is not the case when we convert to bool with Var
|
||||||
{
|
{
|
||||||
std::string s = value.convert<std::string>();
|
auto s = value.convert<std::string>();
|
||||||
logic = !s.empty();
|
logic = !s.empty();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -188,11 +174,9 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~LogicExistQuery()
|
~LogicExistQuery() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool apply(const Var& data) const
|
bool apply(const Var& data) const override
|
||||||
{
|
{
|
||||||
Query query(data);
|
Query query(data);
|
||||||
Var value = query.find(_queryString);
|
Var value = query.find(_queryString);
|
||||||
@ -209,11 +193,9 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~LogicElseQuery()
|
~LogicElseQuery() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool apply(const Var& data) const
|
bool apply(const Var& data) const override
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -227,23 +209,21 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~LogicPart()
|
~LogicPart() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void addPart(LogicQuery* query, Part* part)
|
void addPart(LogicQuery* query, Part* part)
|
||||||
{
|
{
|
||||||
MultiPart::addPart(part);
|
MultiPart::addPart(part);
|
||||||
_queries.push_back(query);
|
_queries.emplace_back(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addPart(Part* part)
|
void addPart(Part* part) override
|
||||||
{
|
{
|
||||||
MultiPart::addPart(part);
|
MultiPart::addPart(part);
|
||||||
_queries.push_back(new LogicElseQuery());
|
_queries.push_back(new LogicElseQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(const Var& data, std::ostream& out) const
|
void render(const Var& data, std::ostream& out) const override
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (auto it = _queries.begin(); it != _queries.end(); ++it, ++count)
|
for (auto it = _queries.begin(); it != _queries.end(); ++it, ++count)
|
||||||
@ -268,11 +248,9 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~LoopPart()
|
~LoopPart() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void render(const Var& data, std::ostream& out) const
|
void render(const Var& data, std::ostream& out) const override
|
||||||
{
|
{
|
||||||
Query query(data);
|
Query query(data);
|
||||||
|
|
||||||
@ -322,14 +300,12 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~IncludePart()
|
~IncludePart() override = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void render(const Var& data, std::ostream& out) const
|
void render(const Var& data, std::ostream& out) const override
|
||||||
{
|
{
|
||||||
TemplateCache* cache = TemplateCache::instance();
|
TemplateCache* cache = TemplateCache::instance();
|
||||||
if (cache == 0)
|
if (cache == nullptr)
|
||||||
{
|
{
|
||||||
Template tpl(_path);
|
Template tpl(_path);
|
||||||
tpl.parse();
|
tpl.parse();
|
||||||
@ -348,16 +324,16 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
Template::Template(const Path& templatePath):
|
Template::Template(const Path& templatePath):
|
||||||
_parts(0),
|
_parts(nullptr),
|
||||||
_currentPart(0),
|
_currentPart(nullptr),
|
||||||
_templatePath(templatePath)
|
_templatePath(templatePath)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Template::Template():
|
Template::Template():
|
||||||
_parts(0),
|
_parts(nullptr),
|
||||||
_currentPart(0)
|
_currentPart(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,24 +406,24 @@ void Template::parse(std::istream& in)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_partStack.push(_currentPart);
|
_partStack.push(_currentPart);
|
||||||
LoopPart* part = new LoopPart(loopVariable, query);
|
auto part = new LoopPart(loopVariable, query);
|
||||||
_partStack.push(part);
|
_partStack.push(part);
|
||||||
_currentPart->addPart(part);
|
_currentPart->addPart(part);
|
||||||
_currentPart = part;
|
_currentPart = part;
|
||||||
}
|
}
|
||||||
else if (command.compare("else") == 0)
|
else if (command.compare("else") == 0)
|
||||||
{
|
{
|
||||||
if (_partStack.size() == 0)
|
if (_partStack.empty())
|
||||||
{
|
{
|
||||||
throw JSONTemplateException("Unexpected <? else ?> found");
|
throw JSONTemplateException("Unexpected <? else ?> found");
|
||||||
}
|
}
|
||||||
_currentPart = _partStack.top();
|
_currentPart = _partStack.top();
|
||||||
LogicPart* lp = dynamic_cast<LogicPart*>(_currentPart);
|
auto lp = dynamic_cast<LogicPart*>(_currentPart);
|
||||||
if (lp == 0)
|
if (lp == nullptr)
|
||||||
{
|
{
|
||||||
throw JSONTemplateException("Missing <? if ?> or <? ifexist ?> for <? else ?>");
|
throw JSONTemplateException("Missing <? if ?> or <? ifexist ?> for <? else ?>");
|
||||||
}
|
}
|
||||||
MultiPart* part = new MultiPart();
|
auto part = new MultiPart();
|
||||||
lp->addPart(part);
|
lp->addPart(part);
|
||||||
_currentPart = part;
|
_currentPart = part;
|
||||||
}
|
}
|
||||||
@ -459,18 +435,18 @@ void Template::parse(std::istream& in)
|
|||||||
throw JSONTemplateException("Missing query in <? " + command + " ?>");
|
throw JSONTemplateException("Missing query in <? " + command + " ?>");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_partStack.size() == 0)
|
if (_partStack.empty())
|
||||||
{
|
{
|
||||||
throw JSONTemplateException("Unexpected <? elsif / elif ?> found");
|
throw JSONTemplateException("Unexpected <? elsif / elif ?> found");
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentPart = _partStack.top();
|
_currentPart = _partStack.top();
|
||||||
LogicPart* lp = dynamic_cast<LogicPart*>(_currentPart);
|
auto lp = dynamic_cast<LogicPart*>(_currentPart);
|
||||||
if (lp == 0)
|
if (lp == nullptr)
|
||||||
{
|
{
|
||||||
throw JSONTemplateException("Missing <? if ?> or <? ifexist ?> for <? elsif / elif ?>");
|
throw JSONTemplateException("Missing <? if ?> or <? ifexist ?> for <? elsif / elif ?>");
|
||||||
}
|
}
|
||||||
MultiPart* part = new MultiPart();
|
auto part = new MultiPart();
|
||||||
lp->addPart(new LogicQuery(query), part);
|
lp->addPart(new LogicQuery(query), part);
|
||||||
_currentPart = part;
|
_currentPart = part;
|
||||||
}
|
}
|
||||||
@ -481,8 +457,8 @@ void Template::parse(std::istream& in)
|
|||||||
throw JSONTemplateException("Unexpected <? endfor ?> found");
|
throw JSONTemplateException("Unexpected <? endfor ?> found");
|
||||||
}
|
}
|
||||||
MultiPart* loopPart = _partStack.top();
|
MultiPart* loopPart = _partStack.top();
|
||||||
LoopPart* lp = dynamic_cast<LoopPart*>(loopPart);
|
auto lp = dynamic_cast<LoopPart*>(loopPart);
|
||||||
if (lp == 0)
|
if (lp == nullptr)
|
||||||
{
|
{
|
||||||
throw JSONTemplateException("Missing <? for ?> command");
|
throw JSONTemplateException("Missing <? for ?> command");
|
||||||
}
|
}
|
||||||
@ -498,8 +474,8 @@ void Template::parse(std::istream& in)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_currentPart = _partStack.top();
|
_currentPart = _partStack.top();
|
||||||
LogicPart* lp = dynamic_cast<LogicPart*>(_currentPart);
|
auto lp = dynamic_cast<LogicPart*>(_currentPart);
|
||||||
if (lp == 0)
|
if (lp == nullptr)
|
||||||
{
|
{
|
||||||
throw JSONTemplateException("Missing <? if ?> or <? ifexist ?> for <? endif ?>");
|
throw JSONTemplateException("Missing <? if ?> or <? ifexist ?> for <? endif ?>");
|
||||||
}
|
}
|
||||||
@ -516,7 +492,7 @@ void Template::parse(std::istream& in)
|
|||||||
throw JSONTemplateException("Missing query in <? " + command + " ?>");
|
throw JSONTemplateException("Missing query in <? " + command + " ?>");
|
||||||
}
|
}
|
||||||
_partStack.push(_currentPart);
|
_partStack.push(_currentPart);
|
||||||
LogicPart* lp = new LogicPart();
|
auto lp = new LogicPart();
|
||||||
_partStack.push(lp);
|
_partStack.push(lp);
|
||||||
_currentPart->addPart(lp);
|
_currentPart->addPart(lp);
|
||||||
_currentPart = new MultiPart();
|
_currentPart = new MultiPart();
|
||||||
@ -590,7 +566,7 @@ std::string Template::readText(std::istream& in)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text += c;
|
text += static_cast<char>(c);
|
||||||
|
|
||||||
c = in.get();
|
c = in.get();
|
||||||
}
|
}
|
||||||
@ -612,7 +588,7 @@ std::string Template::readTemplateCommand(std::istream& in)
|
|||||||
|
|
||||||
if (c == '?' && in.peek() == '>')
|
if (c == '?' && in.peek() == '>')
|
||||||
{
|
{
|
||||||
in.putback(c);
|
in.putback(static_cast<char>(c));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,7 +598,7 @@ std::string Template::readTemplateCommand(std::istream& in)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
command += c;
|
command += static_cast<char>(c);
|
||||||
|
|
||||||
c = in.get();
|
c = in.get();
|
||||||
}
|
}
|
||||||
@ -638,7 +614,7 @@ std::string Template::readWord(std::istream& in)
|
|||||||
while ((c = in.peek()) != -1 && !Ascii::isSpace(c))
|
while ((c = in.peek()) != -1 && !Ascii::isSpace(c))
|
||||||
{
|
{
|
||||||
in.get();
|
in.get();
|
||||||
word += c;
|
word += static_cast<char>(c);
|
||||||
}
|
}
|
||||||
return word;
|
return word;
|
||||||
}
|
}
|
||||||
@ -652,7 +628,7 @@ std::string Template::readQuery(std::istream& in)
|
|||||||
{
|
{
|
||||||
if (c == '?' && in.peek() == '>')
|
if (c == '?' && in.peek() == '>')
|
||||||
{
|
{
|
||||||
in.putback(c);
|
in.putback(static_cast<char>(c));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -660,7 +636,7 @@ std::string Template::readQuery(std::istream& in)
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
word += c;
|
word += static_cast<char>(c);
|
||||||
}
|
}
|
||||||
return word;
|
return word;
|
||||||
}
|
}
|
||||||
@ -685,7 +661,7 @@ std::string Template::readString(std::istream& in)
|
|||||||
{
|
{
|
||||||
while ((c = in.get()) != -1 && c != '"')
|
while ((c = in.get()) != -1 && c != '"')
|
||||||
{
|
{
|
||||||
str += c;
|
str += static_cast<char>(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
@ -20,10 +20,10 @@ namespace Poco {
|
|||||||
namespace JSON {
|
namespace JSON {
|
||||||
|
|
||||||
|
|
||||||
TemplateCache* TemplateCache::_pInstance = 0;
|
TemplateCache* TemplateCache::_pInstance = nullptr;
|
||||||
|
|
||||||
|
|
||||||
TemplateCache::TemplateCache(): _pLogger(0)
|
TemplateCache::TemplateCache(): _pLogger(nullptr)
|
||||||
{
|
{
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
@ -31,13 +31,13 @@ TemplateCache::TemplateCache(): _pLogger(0)
|
|||||||
|
|
||||||
TemplateCache::~TemplateCache()
|
TemplateCache::~TemplateCache()
|
||||||
{
|
{
|
||||||
_pInstance = 0;
|
_pInstance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TemplateCache::setup()
|
void TemplateCache::setup()
|
||||||
{
|
{
|
||||||
poco_assert (_pInstance == 0);
|
poco_assert (_pInstance == nullptr);
|
||||||
_pInstance = this;
|
_pInstance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ Template::Ptr TemplateCache::getTemplate(const Path& path)
|
|||||||
|
|
||||||
Template::Ptr tpl;
|
Template::Ptr tpl;
|
||||||
|
|
||||||
std::map<std::string, Template::Ptr>::iterator it = _cache.find(templatePathname);
|
auto it = _cache.find(templatePathname);
|
||||||
if (it == _cache.end())
|
if (it == _cache.end())
|
||||||
{
|
{
|
||||||
if (templateFile.exists())
|
if (templateFile.exists())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user