mirror of
https://github.com/tristanpenman/valijson.git
synced 2024-12-12 10:13:51 +01:00
Cosmetic improvements for poco_json_adapter.hpp and property_tree_adapter.hpp
This commit is contained in:
parent
e5c1cbfe88
commit
77d2ef8299
@ -61,7 +61,7 @@ public:
|
||||
|
||||
/// Construct a PocoJsonArray referencing an empty array.
|
||||
PocoJsonArray()
|
||||
: value(emptyArray())
|
||||
: m_value(emptyArray())
|
||||
{ }
|
||||
|
||||
/**
|
||||
@ -74,7 +74,7 @@ public:
|
||||
* an array.
|
||||
*/
|
||||
PocoJsonArray(const Poco::Dynamic::Var &value)
|
||||
: value(value)
|
||||
: m_value(value)
|
||||
{
|
||||
if (value.type() != typeid(Poco::JSON::Array::Ptr)) {
|
||||
throw std::runtime_error("Value is not an array.");
|
||||
@ -100,7 +100,7 @@ public:
|
||||
/// Return the number of elements in the array
|
||||
size_t size() const
|
||||
{
|
||||
return value.extract<Poco::JSON::Array::Ptr>()->size();
|
||||
return m_value.extract<Poco::JSON::Array::Ptr>()->size();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -115,7 +115,7 @@ private:
|
||||
}
|
||||
|
||||
/// Contained value
|
||||
Poco::Dynamic::Var value;
|
||||
Poco::Dynamic::Var m_value;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -138,7 +138,7 @@ public:
|
||||
|
||||
/// Construct a PocoJsonObject an empty object.
|
||||
PocoJsonObject()
|
||||
: value(emptyObject())
|
||||
: m_value(emptyObject())
|
||||
{ }
|
||||
|
||||
/**
|
||||
@ -151,7 +151,7 @@ public:
|
||||
* an object.
|
||||
*/
|
||||
PocoJsonObject(const Poco::Dynamic::Var &value)
|
||||
: value(value)
|
||||
: m_value(value)
|
||||
{
|
||||
if (value.type() != typeid(Poco::JSON::Object::Ptr)) {
|
||||
throw std::runtime_error("Value is not an object.");
|
||||
@ -189,7 +189,7 @@ public:
|
||||
/// Returns the number of members belonging to this object.
|
||||
size_t size() const
|
||||
{
|
||||
return value.extract<Poco::JSON::Object::Ptr>()->size();
|
||||
return m_value.extract<Poco::JSON::Object::Ptr>()->size();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -204,7 +204,7 @@ private:
|
||||
}
|
||||
|
||||
/// Contained value
|
||||
Poco::Dynamic::Var value;
|
||||
Poco::Dynamic::Var m_value;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -226,12 +226,12 @@ public:
|
||||
* @param source the PocoJson value to be copied
|
||||
*/
|
||||
explicit PocoJsonFrozenValue(const Poco::Dynamic::Var &source)
|
||||
: value(source)
|
||||
: m_value(source)
|
||||
{ }
|
||||
|
||||
virtual FrozenValue * clone() const
|
||||
{
|
||||
return new PocoJsonFrozenValue(value);
|
||||
return new PocoJsonFrozenValue(m_value);
|
||||
}
|
||||
|
||||
virtual bool equalTo(const Adapter &other, bool strict) const;
|
||||
@ -239,7 +239,7 @@ public:
|
||||
private:
|
||||
|
||||
/// Stored PocoJson value
|
||||
Poco::Dynamic::Var value;
|
||||
Poco::Dynamic::Var m_value;
|
||||
};
|
||||
|
||||
|
||||
@ -263,12 +263,12 @@ public:
|
||||
|
||||
/// Construct a wrapper for the empty object
|
||||
PocoJsonValue()
|
||||
: value(emptyObject())
|
||||
: m_value(emptyObject())
|
||||
{ }
|
||||
|
||||
/// Construct a wrapper for a specific PocoJson value
|
||||
PocoJsonValue(const Poco::Dynamic::Var& value)
|
||||
: value(value)
|
||||
: m_value(value)
|
||||
{ }
|
||||
|
||||
/**
|
||||
@ -280,7 +280,7 @@ public:
|
||||
*/
|
||||
FrozenValue * freeze() const
|
||||
{
|
||||
return new PocoJsonFrozenValue(value);
|
||||
return new PocoJsonFrozenValue(m_value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,8 +294,8 @@ public:
|
||||
*/
|
||||
opt::optional<PocoJsonArray> getArrayOptional() const
|
||||
{
|
||||
if (value.type() == typeid(Poco::JSON::Array::Ptr)) {
|
||||
return opt::make_optional(PocoJsonArray(value));
|
||||
if (m_value.type() == typeid(Poco::JSON::Array::Ptr)) {
|
||||
return opt::make_optional(PocoJsonArray(m_value));
|
||||
}
|
||||
|
||||
return opt::optional<PocoJsonArray>();
|
||||
@ -314,8 +314,8 @@ public:
|
||||
*/
|
||||
bool getArraySize(size_t &result) const
|
||||
{
|
||||
if (value.type() == typeid(Poco::JSON::Array::Ptr)) {
|
||||
result = value.extract<Poco::JSON::Array::Ptr>()->size();
|
||||
if (m_value.type() == typeid(Poco::JSON::Array::Ptr)) {
|
||||
result = m_value.extract<Poco::JSON::Array::Ptr>()->size();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -324,8 +324,8 @@ public:
|
||||
|
||||
bool getBool(bool &result) const
|
||||
{
|
||||
if (value.isBoolean()) {
|
||||
result = value.convert<bool>();
|
||||
if (m_value.isBoolean()) {
|
||||
result = m_value.convert<bool>();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -334,8 +334,8 @@ public:
|
||||
|
||||
bool getDouble(double &result) const
|
||||
{
|
||||
if (value.isNumeric() && !value.isInteger()) {
|
||||
result = value.convert<double>();
|
||||
if (m_value.isNumeric() && !m_value.isInteger()) {
|
||||
result = m_value.convert<double>();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -344,8 +344,8 @@ public:
|
||||
|
||||
bool getInteger(int64_t &result) const
|
||||
{
|
||||
if (value.isInteger()) {
|
||||
result = value.convert<int>();
|
||||
if (m_value.isInteger()) {
|
||||
result = m_value.convert<int>();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -362,8 +362,8 @@ public:
|
||||
*/
|
||||
opt::optional<PocoJsonObject> getObjectOptional() const
|
||||
{
|
||||
if (value.type() == typeid(Poco::JSON::Object::Ptr)) {
|
||||
return opt::make_optional(PocoJsonObject(value));
|
||||
if (m_value.type() == typeid(Poco::JSON::Object::Ptr)) {
|
||||
return opt::make_optional(PocoJsonObject(m_value));
|
||||
}
|
||||
|
||||
return opt::optional<PocoJsonObject>();
|
||||
@ -382,8 +382,8 @@ public:
|
||||
*/
|
||||
bool getObjectSize(size_t &result) const
|
||||
{
|
||||
if (value.type() == typeid(Poco::JSON::Object::Ptr)) {
|
||||
result = value.extract<Poco::JSON::Object::Ptr>()->size();
|
||||
if (m_value.type() == typeid(Poco::JSON::Object::Ptr)) {
|
||||
result = m_value.extract<Poco::JSON::Object::Ptr>()->size();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -392,8 +392,8 @@ public:
|
||||
|
||||
bool getString(std::string &result) const
|
||||
{
|
||||
if (value.isString()) {
|
||||
result = value.convert<std::string>();
|
||||
if (m_value.isString()) {
|
||||
result = m_value.convert<std::string>();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -407,42 +407,42 @@ public:
|
||||
|
||||
bool isArray() const
|
||||
{
|
||||
return value.type() == typeid(Poco::JSON::Array::Ptr);
|
||||
return m_value.type() == typeid(Poco::JSON::Array::Ptr);
|
||||
}
|
||||
|
||||
bool isBool() const
|
||||
{
|
||||
return value.isBoolean();
|
||||
return m_value.isBoolean();
|
||||
}
|
||||
|
||||
bool isDouble() const
|
||||
{
|
||||
return value.isNumeric() && !value.isInteger();
|
||||
return m_value.isNumeric() && !m_value.isInteger();
|
||||
}
|
||||
|
||||
bool isInteger() const
|
||||
{
|
||||
return !isBool() && value.isInteger();
|
||||
return !isBool() && m_value.isInteger();
|
||||
}
|
||||
|
||||
bool isNull() const
|
||||
{
|
||||
return value.isEmpty();
|
||||
return m_value.isEmpty();
|
||||
}
|
||||
|
||||
bool isNumber() const
|
||||
{
|
||||
return value.isNumeric();
|
||||
return m_value.isNumeric();
|
||||
}
|
||||
|
||||
bool isObject() const
|
||||
{
|
||||
return value.type() == typeid(Poco::JSON::Object::Ptr);
|
||||
return m_value.type() == typeid(Poco::JSON::Object::Ptr);
|
||||
}
|
||||
|
||||
bool isString() const
|
||||
{
|
||||
return value.isString();
|
||||
return m_value.isString();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -455,7 +455,7 @@ private:
|
||||
}
|
||||
|
||||
/// Contained value
|
||||
Poco::Dynamic::Var value;
|
||||
Poco::Dynamic::Var m_value;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -495,10 +495,7 @@ public:
|
||||
*
|
||||
* @see PocoJsonArray
|
||||
*/
|
||||
class PocoJsonArrayValueIterator :
|
||||
public std::iterator<
|
||||
std::bidirectional_iterator_tag, // bi-directional iterator
|
||||
PocoJsonAdapter> // value type
|
||||
class PocoJsonArrayValueIterator : public std::iterator<std::bidirectional_iterator_tag, PocoJsonAdapter>
|
||||
{
|
||||
public:
|
||||
|
||||
@ -509,14 +506,14 @@ public:
|
||||
* @param itr PocoJson iterator to store
|
||||
*/
|
||||
PocoJsonArrayValueIterator(const Poco::JSON::Array::ConstIterator &itr)
|
||||
: itr(itr)
|
||||
: m_itr(itr)
|
||||
{ }
|
||||
|
||||
/// Returns a PocoJsonAdapter that contains the value of the current
|
||||
/// element.
|
||||
PocoJsonAdapter operator*() const
|
||||
{
|
||||
return PocoJsonAdapter(*itr);
|
||||
return PocoJsonAdapter(*m_itr);
|
||||
}
|
||||
|
||||
DerefProxy<PocoJsonAdapter> operator->() const
|
||||
@ -537,42 +534,42 @@ public:
|
||||
*/
|
||||
bool operator==(const PocoJsonArrayValueIterator &other) const
|
||||
{
|
||||
return itr == other.itr;
|
||||
return m_itr == other.m_itr;
|
||||
}
|
||||
|
||||
bool operator!=(const PocoJsonArrayValueIterator &other) const
|
||||
{
|
||||
return !(itr == other.itr);
|
||||
return !(m_itr == other.m_itr);
|
||||
}
|
||||
|
||||
const PocoJsonArrayValueIterator& operator++()
|
||||
{
|
||||
itr++;
|
||||
m_itr++;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
PocoJsonArrayValueIterator operator++(int)
|
||||
{
|
||||
PocoJsonArrayValueIterator iterator_pre(itr);
|
||||
PocoJsonArrayValueIterator iterator_pre(m_itr);
|
||||
++(*this);
|
||||
return iterator_pre;
|
||||
}
|
||||
|
||||
const PocoJsonArrayValueIterator& operator--()
|
||||
{
|
||||
itr--;
|
||||
m_itr--;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void advance(std::ptrdiff_t n)
|
||||
{
|
||||
itr += n;
|
||||
m_itr += n;
|
||||
}
|
||||
|
||||
private:
|
||||
Poco::JSON::Array::ConstIterator itr;
|
||||
Poco::JSON::Array::ConstIterator m_itr;
|
||||
};
|
||||
|
||||
|
||||
@ -586,10 +583,7 @@ private:
|
||||
* @see PocoJsonObject
|
||||
* @see PocoJsonObjectMember
|
||||
*/
|
||||
class PocoJsonObjectMemberIterator :
|
||||
public std::iterator<
|
||||
std::bidirectional_iterator_tag, // bi-directional iterator
|
||||
PocoJsonObjectMember> // value type
|
||||
class PocoJsonObjectMemberIterator : public std::iterator<std::bidirectional_iterator_tag, PocoJsonObjectMember>
|
||||
{
|
||||
public:
|
||||
|
||||
@ -599,7 +593,7 @@ public:
|
||||
* @param itr PocoJson iterator to store
|
||||
*/
|
||||
PocoJsonObjectMemberIterator(const Poco::JSON::Object::ConstIterator &itr)
|
||||
: itr(itr)
|
||||
: m_itr(itr)
|
||||
{ }
|
||||
|
||||
/**
|
||||
@ -608,7 +602,7 @@ public:
|
||||
*/
|
||||
PocoJsonObjectMember operator*() const
|
||||
{
|
||||
return PocoJsonObjectMember(itr->first, itr->second);
|
||||
return PocoJsonObjectMember(m_itr->first, m_itr->second);
|
||||
}
|
||||
|
||||
DerefProxy<PocoJsonObjectMember> operator->() const
|
||||
@ -629,31 +623,31 @@ public:
|
||||
*/
|
||||
bool operator==(const PocoJsonObjectMemberIterator &other) const
|
||||
{
|
||||
return itr == other.itr;
|
||||
return m_itr == other.m_itr;
|
||||
}
|
||||
|
||||
bool operator!=(const PocoJsonObjectMemberIterator &other) const
|
||||
{
|
||||
return !(itr == other.itr);
|
||||
return !(m_itr == other.m_itr);
|
||||
}
|
||||
|
||||
const PocoJsonObjectMemberIterator& operator++()
|
||||
{
|
||||
itr++;
|
||||
m_itr++;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
PocoJsonObjectMemberIterator operator++(int)
|
||||
{
|
||||
PocoJsonObjectMemberIterator iterator_pre(itr);
|
||||
PocoJsonObjectMemberIterator iterator_pre(m_itr);
|
||||
++(*this);
|
||||
return iterator_pre;
|
||||
}
|
||||
|
||||
const PocoJsonObjectMemberIterator& operator--()
|
||||
{
|
||||
itr--;
|
||||
m_itr--;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -661,7 +655,7 @@ public:
|
||||
private:
|
||||
|
||||
/// Iternal copy of the original PocoJson iterator
|
||||
Poco::JSON::Object::ConstIterator itr;
|
||||
Poco::JSON::Object::ConstIterator m_itr;
|
||||
};
|
||||
|
||||
/// Specialisation of the AdapterTraits template struct for PocoJsonAdapter.
|
||||
@ -678,32 +672,29 @@ struct AdapterTraits<valijson::adapters::PocoJsonAdapter>
|
||||
|
||||
inline PocoJsonArrayValueIterator PocoJsonArray::begin() const
|
||||
{
|
||||
return value.extract<Poco::JSON::Array::Ptr>()->begin();
|
||||
return m_value.extract<Poco::JSON::Array::Ptr>()->begin();
|
||||
}
|
||||
|
||||
inline PocoJsonArrayValueIterator PocoJsonArray::end() const
|
||||
{
|
||||
return value.extract<Poco::JSON::Array::Ptr>()->end();
|
||||
return m_value.extract<Poco::JSON::Array::Ptr>()->end();
|
||||
}
|
||||
|
||||
inline PocoJsonObjectMemberIterator PocoJsonObject::begin() const
|
||||
{
|
||||
return value.extract<Poco::JSON::Object::Ptr>()->begin();
|
||||
return m_value.extract<Poco::JSON::Object::Ptr>()->begin();
|
||||
}
|
||||
|
||||
inline PocoJsonObjectMemberIterator PocoJsonObject::end() const
|
||||
{
|
||||
return value.extract<Poco::JSON::Object::Ptr>()->end();
|
||||
return m_value.extract<Poco::JSON::Object::Ptr>()->end();
|
||||
}
|
||||
|
||||
inline PocoJsonObjectMemberIterator PocoJsonObject::find(
|
||||
const std::string &propertyName) const
|
||||
inline PocoJsonObjectMemberIterator PocoJsonObject::find(const std::string &propertyName) const
|
||||
{
|
||||
auto& ptr = value.extract<Poco::JSON::Object::Ptr>();
|
||||
auto& ptr = m_value.extract<Poco::JSON::Object::Ptr>();
|
||||
|
||||
auto it = std::find_if(ptr->begin(), ptr->end(),
|
||||
[&propertyName](const Poco::JSON::Object::ValueType& p)
|
||||
{
|
||||
auto it = std::find_if(ptr->begin(), ptr->end(), [&propertyName](const Poco::JSON::Object::ValueType& p) {
|
||||
return p.first == propertyName;
|
||||
});
|
||||
return it;
|
||||
@ -711,7 +702,7 @@ inline PocoJsonObjectMemberIterator PocoJsonObject::find(
|
||||
|
||||
inline bool PocoJsonFrozenValue::equalTo(const Adapter &other, bool strict) const
|
||||
{
|
||||
return PocoJsonAdapter(value).equalTo(other, strict);
|
||||
return PocoJsonAdapter(m_value).equalTo(other, strict);
|
||||
}
|
||||
|
||||
} // namespace adapters
|
||||
|
@ -61,10 +61,10 @@ public:
|
||||
typedef PropertyTreeArrayValueIterator const_iterator;
|
||||
typedef PropertyTreeArrayValueIterator iterator;
|
||||
|
||||
/// Construct a PropertyTreeArra7 referencing an empty property tree
|
||||
/// Construct a PropertyTreeArray referencing an empty property tree
|
||||
/// singleton.
|
||||
PropertyTreeArray()
|
||||
: array(emptyTree()) { }
|
||||
: m_array(emptyTree()) { }
|
||||
|
||||
/**
|
||||
* @brief Construct PropertyTreeArray referencing a specific Boost
|
||||
@ -76,7 +76,7 @@ public:
|
||||
* checked due to runtime cost.
|
||||
*/
|
||||
explicit PropertyTreeArray(const boost::property_tree::ptree &array)
|
||||
: array(array) { }
|
||||
: m_array(array) { }
|
||||
|
||||
/// Return an iterator for the first element in the array.
|
||||
PropertyTreeArrayValueIterator begin() const;
|
||||
@ -87,7 +87,7 @@ public:
|
||||
/// Return the number of elements in the array
|
||||
size_t size() const
|
||||
{
|
||||
return array.size();
|
||||
return m_array.size();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -105,7 +105,7 @@ private:
|
||||
}
|
||||
|
||||
/// Reference to the contained value
|
||||
const boost::property_tree::ptree &array;
|
||||
const boost::property_tree::ptree &m_array;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -129,7 +129,7 @@ public:
|
||||
|
||||
/// Construct a PropertyTreeObject referencing an empty property tree.
|
||||
PropertyTreeObject()
|
||||
: object(emptyTree()) { }
|
||||
: m_object(emptyTree()) { }
|
||||
|
||||
/**
|
||||
* @brief Construct a PropertyTreeObject referencing a specific property
|
||||
@ -141,7 +141,7 @@ public:
|
||||
* runtime cost of doing so.
|
||||
*/
|
||||
PropertyTreeObject(const boost::property_tree::ptree &object)
|
||||
: object(object) { }
|
||||
: m_object(object) { }
|
||||
|
||||
/**
|
||||
* @brief Return an iterator for this first object member
|
||||
@ -176,7 +176,7 @@ public:
|
||||
/// Returns the number of members belonging to this object.
|
||||
size_t size() const
|
||||
{
|
||||
return object.size();
|
||||
return m_object.size();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -193,7 +193,7 @@ private:
|
||||
}
|
||||
|
||||
/// Reference to the contained object
|
||||
const boost::property_tree::ptree &object;
|
||||
const boost::property_tree::ptree &m_object;
|
||||
|
||||
};
|
||||
|
||||
@ -215,30 +215,28 @@ public:
|
||||
*
|
||||
* @param source string containing the POD vlaue
|
||||
*/
|
||||
explicit PropertyTreeFrozenValue(
|
||||
const boost::property_tree::ptree::data_type &source)
|
||||
: value(source) { }
|
||||
explicit PropertyTreeFrozenValue(const boost::property_tree::ptree::data_type &source)
|
||||
: m_value(source) { }
|
||||
|
||||
/**
|
||||
* @brief Make a copy of a Boost property tree object or array value
|
||||
*
|
||||
* @param source the property tree to be copied
|
||||
*/
|
||||
explicit PropertyTreeFrozenValue(
|
||||
const boost::property_tree::ptree &source)
|
||||
: value(source) { }
|
||||
explicit PropertyTreeFrozenValue(const boost::property_tree::ptree &source)
|
||||
: m_value(source) { }
|
||||
|
||||
virtual FrozenValue * clone() const
|
||||
FrozenValue * clone() const override
|
||||
{
|
||||
return new PropertyTreeFrozenValue(value);
|
||||
return new PropertyTreeFrozenValue(m_value);
|
||||
}
|
||||
|
||||
virtual bool equalTo(const Adapter &other, bool strict) const;
|
||||
bool equalTo(const Adapter &other, bool strict) const override;
|
||||
|
||||
private:
|
||||
|
||||
/// Stored value
|
||||
boost::property_tree::ptree value;
|
||||
boost::property_tree::ptree m_value;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -261,7 +259,7 @@ public:
|
||||
|
||||
/// Construct a wrapper for an empty property tree
|
||||
PropertyTreeValue()
|
||||
: object(emptyTree()) { }
|
||||
: m_object(emptyTree()) { }
|
||||
|
||||
/**
|
||||
* @brief Construct a PropertyTreeValue from a tree object
|
||||
@ -279,8 +277,8 @@ public:
|
||||
PropertyTreeValue(const boost::property_tree::ptree &tree)
|
||||
{
|
||||
if (tree.data().empty()) { // No string content
|
||||
if (tree.size() == 0) { // No children
|
||||
array.emplace(tree); // Treat as empty array
|
||||
if (tree.empty()) { // No children
|
||||
m_array.emplace(tree); // Treat as empty array
|
||||
} else {
|
||||
bool isArray = true;
|
||||
for (const auto &node : tree) {
|
||||
@ -291,13 +289,13 @@ public:
|
||||
}
|
||||
|
||||
if (isArray) {
|
||||
array.emplace(tree);
|
||||
m_array.emplace(tree);
|
||||
} else {
|
||||
object.emplace(tree);
|
||||
m_object.emplace(tree);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
value = tree.data();
|
||||
m_value = tree.data();
|
||||
}
|
||||
}
|
||||
|
||||
@ -310,12 +308,12 @@ public:
|
||||
*/
|
||||
FrozenValue* freeze() const
|
||||
{
|
||||
if (array) {
|
||||
return new PropertyTreeFrozenValue(*array);
|
||||
} else if (object) {
|
||||
return new PropertyTreeFrozenValue(*object);
|
||||
if (m_array) {
|
||||
return new PropertyTreeFrozenValue(*m_array);
|
||||
} else if (m_object) {
|
||||
return new PropertyTreeFrozenValue(*m_object);
|
||||
} else {
|
||||
return new PropertyTreeFrozenValue(*value);
|
||||
return new PropertyTreeFrozenValue(*m_value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,11 +328,11 @@ public:
|
||||
*/
|
||||
opt::optional<PropertyTreeArray> getArrayOptional() const
|
||||
{
|
||||
if (array) {
|
||||
return opt::make_optional(PropertyTreeArray(*array));
|
||||
if (m_array) {
|
||||
return opt::make_optional(PropertyTreeArray(*m_array));
|
||||
}
|
||||
|
||||
return opt::optional<PropertyTreeArray>();
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -350,25 +348,25 @@ public:
|
||||
*/
|
||||
bool getArraySize(size_t &result) const
|
||||
{
|
||||
if (array) {
|
||||
result = array->size();
|
||||
if (m_array) {
|
||||
result = m_array->size();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool getBool(bool &) const
|
||||
static bool getBool(bool &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool getDouble(double &) const
|
||||
static bool getDouble(double &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool getInteger(int64_t &) const
|
||||
static bool getInteger(int64_t &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -384,11 +382,11 @@ public:
|
||||
*/
|
||||
opt::optional<PropertyTreeObject> getObjectOptional() const
|
||||
{
|
||||
if (object) {
|
||||
return opt::make_optional(PropertyTreeObject(*object));
|
||||
if (m_object) {
|
||||
return opt::make_optional(PropertyTreeObject(*m_object));
|
||||
}
|
||||
|
||||
return opt::optional<PropertyTreeObject>();
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -404,8 +402,8 @@ public:
|
||||
*/
|
||||
bool getObjectSize(size_t &result) const
|
||||
{
|
||||
if (object) {
|
||||
result = object->size();
|
||||
if (m_object) {
|
||||
result = m_object->size();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -414,8 +412,8 @@ public:
|
||||
|
||||
bool getString(std::string &result) const
|
||||
{
|
||||
if (value) {
|
||||
result = *value;
|
||||
if (m_value) {
|
||||
result = *m_value;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -429,42 +427,42 @@ public:
|
||||
|
||||
bool isArray() const
|
||||
{
|
||||
return static_cast<bool>(array);
|
||||
return static_cast<bool>(m_array);
|
||||
}
|
||||
|
||||
bool isBool() const
|
||||
static bool isBool()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isDouble() const
|
||||
static bool isDouble()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isInteger() const
|
||||
static bool isInteger()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isNull() const
|
||||
static bool isNull()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isNumber() const
|
||||
static bool isNumber()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isObject() const
|
||||
{
|
||||
return static_cast<bool>(object);
|
||||
return static_cast<bool>(m_object);
|
||||
}
|
||||
|
||||
bool isString() const
|
||||
{
|
||||
return static_cast<bool>(value);
|
||||
return static_cast<bool>(m_value);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -476,13 +474,13 @@ private:
|
||||
}
|
||||
|
||||
/// Reference used if the value is known to be an array
|
||||
opt::optional<const boost::property_tree::ptree &> array;
|
||||
opt::optional<const boost::property_tree::ptree &> m_array;
|
||||
|
||||
/// Reference used if the value is known to be an object
|
||||
opt::optional<const boost::property_tree::ptree &> object;
|
||||
opt::optional<const boost::property_tree::ptree &> m_object;
|
||||
|
||||
/// Reference used if the value is known to be a POD type
|
||||
opt::optional<std::string> value;
|
||||
opt::optional<std::string> m_value;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -522,10 +520,7 @@ public:
|
||||
*
|
||||
* @see PropertyTreeArray
|
||||
*/
|
||||
class PropertyTreeArrayValueIterator:
|
||||
public std::iterator<
|
||||
std::bidirectional_iterator_tag, // bi-directional iterator
|
||||
PropertyTreeAdapter> // value type
|
||||
class PropertyTreeArrayValueIterator : public std::iterator<std::bidirectional_iterator_tag, PropertyTreeAdapter>
|
||||
{
|
||||
public:
|
||||
|
||||
@ -537,13 +532,13 @@ public:
|
||||
*/
|
||||
PropertyTreeArrayValueIterator(
|
||||
const boost::property_tree::ptree::const_iterator &itr)
|
||||
: itr(itr) { }
|
||||
: m_itr(itr) { }
|
||||
|
||||
/// Returns a PropertyTreeAdapter that contains the value of the current
|
||||
/// element.
|
||||
PropertyTreeAdapter operator*() const
|
||||
{
|
||||
return PropertyTreeAdapter(itr->second);
|
||||
return PropertyTreeAdapter(m_itr->second);
|
||||
}
|
||||
|
||||
DerefProxy<PropertyTreeAdapter> operator->() const
|
||||
@ -564,31 +559,31 @@ public:
|
||||
*/
|
||||
bool operator==(const PropertyTreeArrayValueIterator &rhs) const
|
||||
{
|
||||
return itr == rhs.itr;
|
||||
return m_itr == rhs.m_itr;
|
||||
}
|
||||
|
||||
bool operator!=(const PropertyTreeArrayValueIterator &rhs) const
|
||||
{
|
||||
return !(itr == rhs.itr);
|
||||
return !(m_itr == rhs.m_itr);
|
||||
}
|
||||
|
||||
const PropertyTreeArrayValueIterator& operator++()
|
||||
{
|
||||
itr++;
|
||||
m_itr++;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
PropertyTreeArrayValueIterator operator++(int)
|
||||
{
|
||||
PropertyTreeArrayValueIterator iterator_pre(itr);
|
||||
PropertyTreeArrayValueIterator iterator_pre(m_itr);
|
||||
++(*this);
|
||||
return iterator_pre;
|
||||
}
|
||||
|
||||
const PropertyTreeArrayValueIterator& operator--()
|
||||
{
|
||||
itr--;
|
||||
m_itr--;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -597,18 +592,18 @@ public:
|
||||
{
|
||||
if (n > 0) {
|
||||
while (n-- > 0) {
|
||||
itr++;
|
||||
m_itr++;
|
||||
}
|
||||
} else {
|
||||
while (n++ < 0) {
|
||||
itr--;
|
||||
m_itr--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
boost::property_tree::ptree::const_iterator itr;
|
||||
boost::property_tree::ptree::const_iterator m_itr;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -621,10 +616,7 @@ private:
|
||||
* @see PropertyTreeObject
|
||||
* @see PropertyTreeObjectMember
|
||||
*/
|
||||
class PropertyTreeObjectMemberIterator:
|
||||
public std::iterator<
|
||||
std::bidirectional_iterator_tag, // bi-directional iterator
|
||||
PropertyTreeObjectMember> // value type
|
||||
class PropertyTreeObjectMemberIterator: public std::iterator<std::bidirectional_iterator_tag, PropertyTreeObjectMember>
|
||||
{
|
||||
public:
|
||||
|
||||
@ -635,7 +627,7 @@ public:
|
||||
*/
|
||||
PropertyTreeObjectMemberIterator(
|
||||
boost::property_tree::ptree::const_assoc_iterator itr)
|
||||
: itr(itr) { }
|
||||
: m_itr(itr) { }
|
||||
|
||||
/**
|
||||
* @brief Returns a PropertyTreeObjectMember that contains the key and
|
||||
@ -643,7 +635,7 @@ public:
|
||||
*/
|
||||
PropertyTreeObjectMember operator*() const
|
||||
{
|
||||
return PropertyTreeObjectMember(itr->first, itr->second);
|
||||
return PropertyTreeObjectMember(m_itr->first, m_itr->second);
|
||||
}
|
||||
|
||||
DerefProxy<PropertyTreeObjectMember> operator->() const
|
||||
@ -664,38 +656,38 @@ public:
|
||||
*/
|
||||
bool operator==(const PropertyTreeObjectMemberIterator &rhs) const
|
||||
{
|
||||
return itr == rhs.itr;
|
||||
return m_itr == rhs.m_itr;
|
||||
}
|
||||
|
||||
bool operator!=(const PropertyTreeObjectMemberIterator &rhs) const
|
||||
{
|
||||
return !(itr == rhs.itr);
|
||||
return !(m_itr == rhs.m_itr);
|
||||
}
|
||||
|
||||
const PropertyTreeObjectMemberIterator& operator++()
|
||||
{
|
||||
itr++;
|
||||
m_itr++;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
PropertyTreeObjectMemberIterator operator++(int)
|
||||
{
|
||||
PropertyTreeObjectMemberIterator iterator_pre(itr);
|
||||
PropertyTreeObjectMemberIterator iterator_pre(m_itr);
|
||||
++(*this);
|
||||
return iterator_pre;
|
||||
}
|
||||
|
||||
const PropertyTreeObjectMemberIterator& operator--()
|
||||
{
|
||||
itr--;
|
||||
m_itr--;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
boost::property_tree::ptree::const_assoc_iterator itr;
|
||||
boost::property_tree::ptree::const_assoc_iterator m_itr;
|
||||
};
|
||||
|
||||
/// Specialisation of the AdapterTraits template struct for PropertyTreeAdapter.
|
||||
@ -712,40 +704,39 @@ struct AdapterTraits<valijson::adapters::PropertyTreeAdapter>
|
||||
|
||||
inline bool PropertyTreeFrozenValue::equalTo(const Adapter &other, bool strict) const
|
||||
{
|
||||
return PropertyTreeAdapter(value).equalTo(other, strict);
|
||||
return PropertyTreeAdapter(m_value).equalTo(other, strict);
|
||||
}
|
||||
|
||||
inline PropertyTreeArrayValueIterator PropertyTreeArray::begin() const
|
||||
{
|
||||
return array.begin();
|
||||
return m_array.begin();
|
||||
}
|
||||
|
||||
inline PropertyTreeArrayValueIterator PropertyTreeArray::end() const
|
||||
{
|
||||
return array.end();
|
||||
return m_array.end();
|
||||
}
|
||||
|
||||
inline PropertyTreeObjectMemberIterator PropertyTreeObject::begin() const
|
||||
{
|
||||
return object.ordered_begin();
|
||||
return m_object.ordered_begin();
|
||||
}
|
||||
|
||||
inline PropertyTreeObjectMemberIterator PropertyTreeObject::end() const
|
||||
{
|
||||
return object.not_found();
|
||||
return m_object.not_found();
|
||||
}
|
||||
|
||||
inline PropertyTreeObjectMemberIterator PropertyTreeObject::find(
|
||||
const std::string &propertyName) const
|
||||
{
|
||||
const boost::property_tree::ptree::const_assoc_iterator
|
||||
itr = object.find(propertyName);
|
||||
const boost::property_tree::ptree::const_assoc_iterator itr = m_object.find(propertyName);
|
||||
|
||||
if (itr != object.not_found()) {
|
||||
if (itr != m_object.not_found()) {
|
||||
return itr;
|
||||
}
|
||||
|
||||
return object.not_found();
|
||||
return m_object.not_found();
|
||||
}
|
||||
|
||||
} // namespace adapters
|
||||
|
Loading…
Reference in New Issue
Block a user