mirror of
https://github.com/tristanpenman/valijson.git
synced 2025-03-04 07:27:24 +01:00
Cosmetic improvements for json11_adapter.hpp
This commit is contained in:
parent
6f1f4acb82
commit
e11c17c3f0
@ -61,7 +61,7 @@ public:
|
||||
|
||||
/// Construct a Json11Array referencing an empty array.
|
||||
Json11Array()
|
||||
: value(emptyArray()) { }
|
||||
: m_value(emptyArray()) { }
|
||||
|
||||
/**
|
||||
* @brief Construct a Json11Array referencing a specific Json11
|
||||
@ -73,7 +73,7 @@ public:
|
||||
* an array.
|
||||
*/
|
||||
Json11Array(const json11::Json &value)
|
||||
: value(value)
|
||||
: m_value(value)
|
||||
{
|
||||
if (!value.is_array()) {
|
||||
throw std::runtime_error("Value is not an array.");
|
||||
@ -99,7 +99,7 @@ public:
|
||||
/// Return the number of elements in the array
|
||||
size_t size() const
|
||||
{
|
||||
return value.array_items().size();
|
||||
return m_value.array_items().size();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -116,7 +116,7 @@ private:
|
||||
}
|
||||
|
||||
/// Reference to the contained value
|
||||
const json11::Json &value;
|
||||
const json11::Json &m_value;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -139,7 +139,7 @@ public:
|
||||
|
||||
/// Construct a Json11Object referencing an empty object singleton.
|
||||
Json11Object()
|
||||
: value(emptyObject()) { }
|
||||
: m_value(emptyObject()) { }
|
||||
|
||||
/**
|
||||
* @brief Construct a Json11Object referencing a specific Json11
|
||||
@ -151,7 +151,7 @@ public:
|
||||
* an object.
|
||||
*/
|
||||
Json11Object(const json11::Json &value)
|
||||
: value(value)
|
||||
: m_value(value)
|
||||
{
|
||||
if (!value.is_object()) {
|
||||
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.object_items().size();
|
||||
return m_value.object_items().size();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -206,7 +206,7 @@ private:
|
||||
}
|
||||
|
||||
/// Reference to the contained object
|
||||
const json11::Json &value;
|
||||
const json11::Json &m_value;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -227,20 +227,20 @@ public:
|
||||
*
|
||||
* @param source the Json11 value to be copied
|
||||
*/
|
||||
explicit Json11FrozenValue(const json11::Json &source)
|
||||
: value(source) { }
|
||||
Json11FrozenValue(json11::Json source)
|
||||
: m_value(std::move(source)) { }
|
||||
|
||||
virtual FrozenValue * clone() const
|
||||
FrozenValue * clone() const override
|
||||
{
|
||||
return new Json11FrozenValue(value);
|
||||
return new Json11FrozenValue(m_value);
|
||||
}
|
||||
|
||||
virtual bool equalTo(const Adapter &other, bool strict) const;
|
||||
bool equalTo(const Adapter &other, bool strict) const override;
|
||||
|
||||
private:
|
||||
|
||||
/// Stored Json11 value
|
||||
json11::Json value;
|
||||
json11::Json m_value;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -263,11 +263,11 @@ public:
|
||||
|
||||
/// Construct a wrapper for the empty object singleton
|
||||
Json11Value()
|
||||
: value(emptyObject()) { }
|
||||
: m_value(emptyObject()) { }
|
||||
|
||||
/// Construct a wrapper for a specific Json11 value
|
||||
Json11Value(const json11::Json &value)
|
||||
: value(value) { }
|
||||
: m_value(value) { }
|
||||
|
||||
/**
|
||||
* @brief Create a new Json11FrozenValue instance that contains the
|
||||
@ -278,7 +278,7 @@ public:
|
||||
*/
|
||||
FrozenValue * freeze() const
|
||||
{
|
||||
return new Json11FrozenValue(value);
|
||||
return new Json11FrozenValue(m_value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -292,11 +292,11 @@ public:
|
||||
*/
|
||||
opt::optional<Json11Array> getArrayOptional() const
|
||||
{
|
||||
if (value.is_array()) {
|
||||
return opt::make_optional(Json11Array(value));
|
||||
if (m_value.is_array()) {
|
||||
return opt::make_optional(Json11Array(m_value));
|
||||
}
|
||||
|
||||
return opt::optional<Json11Array>();
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -312,8 +312,8 @@ public:
|
||||
*/
|
||||
bool getArraySize(size_t &result) const
|
||||
{
|
||||
if (value.is_array()) {
|
||||
result = value.array_items().size();
|
||||
if (m_value.is_array()) {
|
||||
result = m_value.array_items().size();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -322,8 +322,8 @@ public:
|
||||
|
||||
bool getBool(bool &result) const
|
||||
{
|
||||
if (value.is_bool()) {
|
||||
result = value.bool_value();
|
||||
if (m_value.is_bool()) {
|
||||
result = m_value.bool_value();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -332,8 +332,8 @@ public:
|
||||
|
||||
bool getDouble(double &result) const
|
||||
{
|
||||
if (value.is_number()) {
|
||||
result = value.number_value();
|
||||
if (m_value.is_number()) {
|
||||
result = m_value.number_value();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -342,8 +342,8 @@ public:
|
||||
|
||||
bool getInteger(int64_t &result) const
|
||||
{
|
||||
if(isInteger()) {
|
||||
result = value.int_value();
|
||||
if (isInteger()) {
|
||||
result = m_value.int_value();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -360,11 +360,11 @@ public:
|
||||
*/
|
||||
opt::optional<Json11Object> getObjectOptional() const
|
||||
{
|
||||
if (value.is_object()) {
|
||||
return opt::make_optional(Json11Object(value));
|
||||
if (m_value.is_object()) {
|
||||
return opt::make_optional(Json11Object(m_value));
|
||||
}
|
||||
|
||||
return opt::optional<Json11Object>();
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -380,8 +380,8 @@ public:
|
||||
*/
|
||||
bool getObjectSize(size_t &result) const
|
||||
{
|
||||
if (value.is_object()) {
|
||||
result = value.object_items().size();
|
||||
if (m_value.is_object()) {
|
||||
result = m_value.object_items().size();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -390,8 +390,8 @@ public:
|
||||
|
||||
bool getString(std::string &result) const
|
||||
{
|
||||
if (value.is_string()) {
|
||||
result = value.string_value();
|
||||
if (m_value.is_string()) {
|
||||
result = m_value.string_value();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -405,43 +405,42 @@ public:
|
||||
|
||||
bool isArray() const
|
||||
{
|
||||
return value.is_array();
|
||||
return m_value.is_array();
|
||||
}
|
||||
|
||||
bool isBool() const
|
||||
{
|
||||
return value.is_bool();
|
||||
return m_value.is_bool();
|
||||
}
|
||||
|
||||
bool isDouble() const
|
||||
{
|
||||
return value.is_number();
|
||||
return m_value.is_number();
|
||||
}
|
||||
|
||||
bool isInteger() const
|
||||
{
|
||||
return value.is_number()
|
||||
&& value.int_value() == value.number_value();
|
||||
return m_value.is_number() && m_value.int_value() == m_value.number_value();
|
||||
}
|
||||
|
||||
bool isNull() const
|
||||
{
|
||||
return value.is_null();
|
||||
return m_value.is_null();
|
||||
}
|
||||
|
||||
bool isNumber() const
|
||||
{
|
||||
return value.is_number();
|
||||
return m_value.is_number();
|
||||
}
|
||||
|
||||
bool isObject() const
|
||||
{
|
||||
return value.is_object();
|
||||
return m_value.is_object();
|
||||
}
|
||||
|
||||
bool isString() const
|
||||
{
|
||||
return value.is_string();
|
||||
return m_value.is_string();
|
||||
}
|
||||
|
||||
private:
|
||||
@ -454,7 +453,7 @@ private:
|
||||
}
|
||||
|
||||
/// Reference to the contained Json11 value.
|
||||
const json11::Json &value;
|
||||
const json11::Json &m_value;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -480,7 +479,7 @@ public:
|
||||
: BasicAdapter() { }
|
||||
|
||||
/// Construct a Json11Adapter containing a specific Json11 value
|
||||
Json11Adapter(const json11::Json &value)
|
||||
explicit Json11Adapter(const json11::Json &value)
|
||||
: BasicAdapter(value) { }
|
||||
};
|
||||
|
||||
@ -506,15 +505,14 @@ public:
|
||||
*
|
||||
* @param itr Json11 iterator to store
|
||||
*/
|
||||
Json11ArrayValueIterator(
|
||||
const json11::Json::array::const_iterator &itr)
|
||||
: itr(itr) { }
|
||||
Json11ArrayValueIterator(const json11::Json::array::const_iterator &itr)
|
||||
: m_itr(itr) { }
|
||||
|
||||
/// Returns a Json11Adapter that contains the value of the current
|
||||
/// element.
|
||||
Json11Adapter operator*() const
|
||||
{
|
||||
return Json11Adapter(*itr);
|
||||
return Json11Adapter(*m_itr);
|
||||
}
|
||||
|
||||
DerefProxy<Json11Adapter> operator->() const
|
||||
@ -535,43 +533,43 @@ public:
|
||||
*/
|
||||
bool operator==(const Json11ArrayValueIterator &other) const
|
||||
{
|
||||
return itr == other.itr;
|
||||
return m_itr == other.m_itr;
|
||||
}
|
||||
|
||||
bool operator!=(const Json11ArrayValueIterator &other) const
|
||||
{
|
||||
return !(itr == other.itr);
|
||||
return !(m_itr == other.m_itr);
|
||||
}
|
||||
|
||||
const Json11ArrayValueIterator& operator++()
|
||||
{
|
||||
itr++;
|
||||
m_itr++;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Json11ArrayValueIterator operator++(int)
|
||||
{
|
||||
Json11ArrayValueIterator iterator_pre(itr);
|
||||
Json11ArrayValueIterator iterator_pre(m_itr);
|
||||
++(*this);
|
||||
return iterator_pre;
|
||||
}
|
||||
|
||||
const Json11ArrayValueIterator& operator--()
|
||||
{
|
||||
itr--;
|
||||
m_itr--;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void advance(std::ptrdiff_t n)
|
||||
{
|
||||
itr += n;
|
||||
m_itr += n;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
json11::Json::array::const_iterator itr;
|
||||
json11::Json::array::const_iterator m_itr;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -596,9 +594,8 @@ public:
|
||||
*
|
||||
* @param itr Json11 iterator to store
|
||||
*/
|
||||
Json11ObjectMemberIterator(
|
||||
const json11::Json::object::const_iterator &itr)
|
||||
: itr(itr) { }
|
||||
Json11ObjectMemberIterator(const json11::Json::object::const_iterator &itr)
|
||||
: m_itr(itr) { }
|
||||
|
||||
/**
|
||||
* @brief Returns a Json11ObjectMember that contains the key and value
|
||||
@ -606,7 +603,7 @@ public:
|
||||
*/
|
||||
Json11ObjectMember operator*() const
|
||||
{
|
||||
return Json11ObjectMember(itr->first, itr->second);
|
||||
return Json11ObjectMember(m_itr->first, m_itr->second);
|
||||
}
|
||||
|
||||
DerefProxy<Json11ObjectMember> operator->() const
|
||||
@ -627,31 +624,31 @@ public:
|
||||
*/
|
||||
bool operator==(const Json11ObjectMemberIterator &other) const
|
||||
{
|
||||
return itr == other.itr;
|
||||
return m_itr == other.m_itr;
|
||||
}
|
||||
|
||||
bool operator!=(const Json11ObjectMemberIterator &other) const
|
||||
{
|
||||
return !(itr == other.itr);
|
||||
return !(m_itr == other.m_itr);
|
||||
}
|
||||
|
||||
const Json11ObjectMemberIterator& operator++()
|
||||
{
|
||||
itr++;
|
||||
m_itr++;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Json11ObjectMemberIterator operator++(int)
|
||||
{
|
||||
Json11ObjectMemberIterator iterator_pre(itr);
|
||||
Json11ObjectMemberIterator iterator_pre(m_itr);
|
||||
++(*this);
|
||||
return iterator_pre;
|
||||
}
|
||||
|
||||
const Json11ObjectMemberIterator& operator--()
|
||||
{
|
||||
itr--;
|
||||
m_itr--;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -659,7 +656,7 @@ public:
|
||||
private:
|
||||
|
||||
/// Iternal copy of the original Json11 iterator
|
||||
json11::Json::object::const_iterator itr;
|
||||
json11::Json::object::const_iterator m_itr;
|
||||
};
|
||||
|
||||
/// Specialisation of the AdapterTraits template struct for Json11Adapter.
|
||||
@ -676,33 +673,33 @@ struct AdapterTraits<valijson::adapters::Json11Adapter>
|
||||
|
||||
inline bool Json11FrozenValue::equalTo(const Adapter &other, bool strict) const
|
||||
{
|
||||
return Json11Adapter(value).equalTo(other, strict);
|
||||
return Json11Adapter(m_value).equalTo(other, strict);
|
||||
}
|
||||
|
||||
inline Json11ArrayValueIterator Json11Array::begin() const
|
||||
{
|
||||
return value.array_items().begin();
|
||||
return m_value.array_items().begin();
|
||||
}
|
||||
|
||||
inline Json11ArrayValueIterator Json11Array::end() const
|
||||
{
|
||||
return value.array_items().end();
|
||||
return m_value.array_items().end();
|
||||
}
|
||||
|
||||
inline Json11ObjectMemberIterator Json11Object::begin() const
|
||||
{
|
||||
return value.object_items().begin();
|
||||
return m_value.object_items().begin();
|
||||
}
|
||||
|
||||
inline Json11ObjectMemberIterator Json11Object::end() const
|
||||
{
|
||||
return value.object_items().end();
|
||||
return m_value.object_items().end();
|
||||
}
|
||||
|
||||
inline Json11ObjectMemberIterator Json11Object::find(
|
||||
const std::string &propertyName) const
|
||||
{
|
||||
return value.object_items().find(propertyName);
|
||||
return m_value.object_items().find(propertyName);
|
||||
}
|
||||
|
||||
} // namespace adapters
|
||||
|
Loading…
x
Reference in New Issue
Block a user