mirror of
https://github.com/tristanpenman/valijson.git
synced 2025-01-06 08:41:12 +01:00
Cosmetic improvements for rapidjson_adapter.hpp
This commit is contained in:
parent
d7901d4858
commit
508bc019ec
@ -64,10 +64,10 @@ class GenericRapidJsonObjectMemberIterator;
|
|||||||
/// Container for a property name and an associated RapidJson value
|
/// Container for a property name and an associated RapidJson value
|
||||||
template<class ValueType = rapidjson::Value>
|
template<class ValueType = rapidjson::Value>
|
||||||
class GenericRapidJsonObjectMember :
|
class GenericRapidJsonObjectMember :
|
||||||
public std::pair<std::string, GenericRapidJsonAdapter<ValueType> >
|
public std::pair<std::string, GenericRapidJsonAdapter<ValueType>>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef std::pair<std::string, GenericRapidJsonAdapter<ValueType> > Super;
|
typedef std::pair<std::string, GenericRapidJsonAdapter<ValueType>> Super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GenericRapidJsonObjectMember(
|
GenericRapidJsonObjectMember(
|
||||||
@ -97,7 +97,7 @@ public:
|
|||||||
|
|
||||||
/// Construct a RapidJsonArray referencing an empty array singleton.
|
/// Construct a RapidJsonArray referencing an empty array singleton.
|
||||||
GenericRapidJsonArray()
|
GenericRapidJsonArray()
|
||||||
: value(emptyArray()) { }
|
: m_value(emptyArray()) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a RapidJsonArray referencing a specific RapidJson
|
* @brief Construct a RapidJsonArray referencing a specific RapidJson
|
||||||
@ -109,7 +109,7 @@ public:
|
|||||||
* an array.
|
* an array.
|
||||||
*/
|
*/
|
||||||
GenericRapidJsonArray(const ValueType &value)
|
GenericRapidJsonArray(const ValueType &value)
|
||||||
: value(value)
|
: m_value(value)
|
||||||
{
|
{
|
||||||
if (!value.IsArray()) {
|
if (!value.IsArray()) {
|
||||||
throw std::runtime_error("Value is not an array.");
|
throw std::runtime_error("Value is not an array.");
|
||||||
@ -125,7 +125,7 @@ public:
|
|||||||
/// Return the number of elements in the array
|
/// Return the number of elements in the array
|
||||||
size_t size() const
|
size_t size() const
|
||||||
{
|
{
|
||||||
return value.Size();
|
return m_value.Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -142,7 +142,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reference to the contained value
|
/// Reference to the contained value
|
||||||
const ValueType &value;
|
const ValueType &m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,7 +166,7 @@ public:
|
|||||||
|
|
||||||
/// Construct a GenericRapidJsonObject referencing an empty object singleton.
|
/// Construct a GenericRapidJsonObject referencing an empty object singleton.
|
||||||
GenericRapidJsonObject()
|
GenericRapidJsonObject()
|
||||||
: value(emptyObject()) { }
|
: m_value(emptyObject()) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a GenericRapidJsonObject referencing a specific
|
* @brief Construct a GenericRapidJsonObject referencing a specific
|
||||||
@ -178,7 +178,7 @@ public:
|
|||||||
* an object.
|
* an object.
|
||||||
*/
|
*/
|
||||||
GenericRapidJsonObject(const ValueType &value)
|
GenericRapidJsonObject(const ValueType &value)
|
||||||
: value(value)
|
: m_value(value)
|
||||||
{
|
{
|
||||||
if (!value.IsObject()) {
|
if (!value.IsObject()) {
|
||||||
throw std::runtime_error("Value is not an object.");
|
throw std::runtime_error("Value is not an object.");
|
||||||
@ -216,7 +216,7 @@ public:
|
|||||||
/// Returns the number of members belonging to this object.
|
/// Returns the number of members belonging to this object.
|
||||||
size_t size() const
|
size_t size() const
|
||||||
{
|
{
|
||||||
return value.MemberEnd() - value.MemberBegin();
|
return m_value.MemberEnd() - m_value.MemberBegin();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -233,7 +233,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reference to the contained object
|
/// Reference to the contained object
|
||||||
const ValueType &value;
|
const ValueType &m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -254,12 +254,12 @@ public:
|
|||||||
|
|
||||||
explicit GenericRapidJsonFrozenValue(const char *str)
|
explicit GenericRapidJsonFrozenValue(const char *str)
|
||||||
{
|
{
|
||||||
value.SetString(str, allocator);
|
m_value.SetString(str, m_allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit GenericRapidJsonFrozenValue(const std::string &str)
|
explicit GenericRapidJsonFrozenValue(const std::string &str)
|
||||||
{
|
{
|
||||||
value.SetString(str.c_str(), (unsigned int)str.length(), allocator);
|
m_value.SetString(str.c_str(), (unsigned int)str.length(), m_allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -269,17 +269,17 @@ public:
|
|||||||
*/
|
*/
|
||||||
explicit GenericRapidJsonFrozenValue(const ValueType &source)
|
explicit GenericRapidJsonFrozenValue(const ValueType &source)
|
||||||
{
|
{
|
||||||
if (!copy(source, value, allocator)) {
|
if (!copy(source, m_value, m_allocator)) {
|
||||||
throw std::runtime_error("Failed to copy ValueType");
|
throw std::runtime_error("Failed to copy ValueType");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual FrozenValue * clone() const
|
FrozenValue * clone() const override
|
||||||
{
|
{
|
||||||
return new GenericRapidJsonFrozenValue(value);
|
return new GenericRapidJsonFrozenValue(m_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool equalTo(const Adapter &other, bool strict) const;
|
bool equalTo(const Adapter &other, bool strict) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -311,8 +311,7 @@ private:
|
|||||||
return true;
|
return true;
|
||||||
case rapidjson::kObjectType:
|
case rapidjson::kObjectType:
|
||||||
dest.SetObject();
|
dest.SetObject();
|
||||||
for (typename ValueType::ConstMemberIterator itr = source.MemberBegin();
|
for (typename ValueType::ConstMemberIterator itr = source.MemberBegin(); itr != source.MemberEnd(); ++itr) {
|
||||||
itr != source.MemberEnd(); ++itr) {
|
|
||||||
ValueType name(itr->name.GetString(), itr->name.GetStringLength(), allocator);
|
ValueType name(itr->name.GetString(), itr->name.GetStringLength(), allocator);
|
||||||
ValueType value;
|
ValueType value;
|
||||||
copy(itr->value, value, allocator);
|
copy(itr->value, value, allocator);
|
||||||
@ -351,10 +350,10 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Local memory allocator for RapidJson value
|
/// Local memory allocator for RapidJson value
|
||||||
typename ValueType::AllocatorType allocator;
|
typename ValueType::AllocatorType m_allocator;
|
||||||
|
|
||||||
/// Local RapidJson value
|
/// Local RapidJson value
|
||||||
ValueType value;
|
ValueType m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -377,11 +376,11 @@ class GenericRapidJsonValue
|
|||||||
public:
|
public:
|
||||||
/// Construct a wrapper for the empty object singleton
|
/// Construct a wrapper for the empty object singleton
|
||||||
GenericRapidJsonValue()
|
GenericRapidJsonValue()
|
||||||
: value(emptyObject()) { }
|
: m_value(emptyObject()) { }
|
||||||
|
|
||||||
/// Construct a wrapper for a specific RapidJson value
|
/// Construct a wrapper for a specific RapidJson value
|
||||||
GenericRapidJsonValue(const ValueType &value)
|
GenericRapidJsonValue(const ValueType &value)
|
||||||
: value(value) { }
|
: m_value(value) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new GenericRapidJsonFrozenValue instance that contains
|
* @brief Create a new GenericRapidJsonFrozenValue instance that contains
|
||||||
@ -392,7 +391,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
FrozenValue * freeze() const
|
FrozenValue * freeze() const
|
||||||
{
|
{
|
||||||
return new GenericRapidJsonFrozenValue<ValueType>(value);
|
return new GenericRapidJsonFrozenValue<ValueType>(m_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -404,13 +403,13 @@ public:
|
|||||||
*
|
*
|
||||||
* Otherwise it will return an empty optional.
|
* Otherwise it will return an empty optional.
|
||||||
*/
|
*/
|
||||||
opt::optional<GenericRapidJsonArray<ValueType> > getArrayOptional() const
|
opt::optional<GenericRapidJsonArray<ValueType>> getArrayOptional() const
|
||||||
{
|
{
|
||||||
if (value.IsArray()) {
|
if (m_value.IsArray()) {
|
||||||
return opt::make_optional(GenericRapidJsonArray<ValueType>(value));
|
return opt::make_optional(GenericRapidJsonArray<ValueType>(m_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return opt::optional<GenericRapidJsonArray<ValueType> >();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -426,8 +425,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool getArraySize(size_t &result) const
|
bool getArraySize(size_t &result) const
|
||||||
{
|
{
|
||||||
if (value.IsArray()) {
|
if (m_value.IsArray()) {
|
||||||
result = value.Size();
|
result = m_value.Size();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,8 +435,8 @@ public:
|
|||||||
|
|
||||||
bool getBool(bool &result) const
|
bool getBool(bool &result) const
|
||||||
{
|
{
|
||||||
if (value.IsBool()) {
|
if (m_value.IsBool()) {
|
||||||
result = value.GetBool();
|
result = m_value.GetBool();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,8 +445,8 @@ public:
|
|||||||
|
|
||||||
bool getDouble(double &result) const
|
bool getDouble(double &result) const
|
||||||
{
|
{
|
||||||
if (value.IsDouble()) {
|
if (m_value.IsDouble()) {
|
||||||
result = value.GetDouble();
|
result = m_value.GetDouble();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,17 +455,17 @@ public:
|
|||||||
|
|
||||||
bool getInteger(int64_t &result) const
|
bool getInteger(int64_t &result) const
|
||||||
{
|
{
|
||||||
if (value.IsInt()) {
|
if (m_value.IsInt()) {
|
||||||
result = value.GetInt();
|
result = m_value.GetInt();
|
||||||
return true;
|
return true;
|
||||||
} else if (value.IsInt64()) {
|
} else if (m_value.IsInt64()) {
|
||||||
result = value.GetInt64();
|
result = m_value.GetInt64();
|
||||||
return true;
|
return true;
|
||||||
} else if (value.IsUint()) {
|
} else if (m_value.IsUint()) {
|
||||||
result = static_cast<int64_t>(value.GetUint());
|
result = static_cast<int64_t>(m_value.GetUint());
|
||||||
return true;
|
return true;
|
||||||
} else if (value.IsUint64()) {
|
} else if (m_value.IsUint64()) {
|
||||||
result = static_cast<int64_t>(value.GetUint64());
|
result = static_cast<int64_t>(m_value.GetUint64());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,13 +481,13 @@ public:
|
|||||||
*
|
*
|
||||||
* Otherwise it will return an empty optional.
|
* Otherwise it will return an empty optional.
|
||||||
*/
|
*/
|
||||||
opt::optional<GenericRapidJsonObject<ValueType> > getObjectOptional() const
|
opt::optional<GenericRapidJsonObject<ValueType>> getObjectOptional() const
|
||||||
{
|
{
|
||||||
if (value.IsObject()) {
|
if (m_value.IsObject()) {
|
||||||
return opt::make_optional(GenericRapidJsonObject<ValueType>(value));
|
return opt::make_optional(GenericRapidJsonObject<ValueType>(m_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return opt::optional<GenericRapidJsonObject<ValueType> >();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -504,8 +503,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool getObjectSize(size_t &result) const
|
bool getObjectSize(size_t &result) const
|
||||||
{
|
{
|
||||||
if (value.IsObject()) {
|
if (m_value.IsObject()) {
|
||||||
result = value.MemberEnd() - value.MemberBegin();
|
result = m_value.MemberEnd() - m_value.MemberBegin();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,8 +513,8 @@ public:
|
|||||||
|
|
||||||
bool getString(std::string &result) const
|
bool getString(std::string &result) const
|
||||||
{
|
{
|
||||||
if (value.IsString()) {
|
if (m_value.IsString()) {
|
||||||
result.assign(value.GetString(), value.GetStringLength());
|
result.assign(m_value.GetString(), m_value.GetStringLength());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,43 +528,42 @@ public:
|
|||||||
|
|
||||||
bool isArray() const
|
bool isArray() const
|
||||||
{
|
{
|
||||||
return value.IsArray();
|
return m_value.IsArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isBool() const
|
bool isBool() const
|
||||||
{
|
{
|
||||||
return value.IsBool();
|
return m_value.IsBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isDouble() const
|
bool isDouble() const
|
||||||
{
|
{
|
||||||
return value.IsDouble();
|
return m_value.IsDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInteger() const
|
bool isInteger() const
|
||||||
{
|
{
|
||||||
return value.IsInt() || value.IsInt64() || value.IsUint() ||
|
return m_value.IsInt() || m_value.IsInt64() || m_value.IsUint() || m_value.IsUint64();
|
||||||
value.IsUint64();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNull() const
|
bool isNull() const
|
||||||
{
|
{
|
||||||
return value.IsNull();
|
return m_value.IsNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNumber() const
|
bool isNumber() const
|
||||||
{
|
{
|
||||||
return value.IsNumber();
|
return m_value.IsNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isObject() const
|
bool isObject() const
|
||||||
{
|
{
|
||||||
return value.IsObject();
|
return m_value.IsObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isString() const
|
bool isString() const
|
||||||
{
|
{
|
||||||
return value.IsString();
|
return m_value.IsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -578,7 +576,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reference to the contained RapidJson value.
|
/// Reference to the contained RapidJson value.
|
||||||
const ValueType &value;
|
const ValueType &m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -596,7 +594,7 @@ class GenericRapidJsonAdapter:
|
|||||||
GenericRapidJsonArray<ValueType>,
|
GenericRapidJsonArray<ValueType>,
|
||||||
GenericRapidJsonObjectMember<ValueType>,
|
GenericRapidJsonObjectMember<ValueType>,
|
||||||
GenericRapidJsonObject<ValueType>,
|
GenericRapidJsonObject<ValueType>,
|
||||||
GenericRapidJsonValue<ValueType> >
|
GenericRapidJsonValue<ValueType>>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -606,7 +604,7 @@ public:
|
|||||||
GenericRapidJsonArray<ValueType>,
|
GenericRapidJsonArray<ValueType>,
|
||||||
GenericRapidJsonObjectMember<ValueType>,
|
GenericRapidJsonObjectMember<ValueType>,
|
||||||
GenericRapidJsonObject<ValueType>,
|
GenericRapidJsonObject<ValueType>,
|
||||||
GenericRapidJsonValue<ValueType> >() { }
|
GenericRapidJsonValue<ValueType>>() { }
|
||||||
|
|
||||||
/// Construct a RapidJsonAdapter containing a specific RapidJson value
|
/// Construct a RapidJsonAdapter containing a specific RapidJson value
|
||||||
GenericRapidJsonAdapter(const ValueType &value)
|
GenericRapidJsonAdapter(const ValueType &value)
|
||||||
@ -614,7 +612,7 @@ public:
|
|||||||
GenericRapidJsonArray<ValueType>,
|
GenericRapidJsonArray<ValueType>,
|
||||||
GenericRapidJsonObjectMember<ValueType>,
|
GenericRapidJsonObjectMember<ValueType>,
|
||||||
GenericRapidJsonObject<ValueType>,
|
GenericRapidJsonObject<ValueType>,
|
||||||
GenericRapidJsonValue<ValueType> >(value) { }
|
GenericRapidJsonValue<ValueType>>(value) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -630,7 +628,7 @@ template<class ValueType>
|
|||||||
class GenericRapidJsonArrayValueIterator:
|
class GenericRapidJsonArrayValueIterator:
|
||||||
public std::iterator<
|
public std::iterator<
|
||||||
std::bidirectional_iterator_tag, // bi-directional iterator
|
std::bidirectional_iterator_tag, // bi-directional iterator
|
||||||
GenericRapidJsonAdapter<ValueType> > // value type
|
GenericRapidJsonAdapter<ValueType>> // value type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -642,19 +640,19 @@ public:
|
|||||||
*/
|
*/
|
||||||
GenericRapidJsonArrayValueIterator(
|
GenericRapidJsonArrayValueIterator(
|
||||||
const typename ValueType::ConstValueIterator &itr)
|
const typename ValueType::ConstValueIterator &itr)
|
||||||
: itr(itr) { }
|
: m_itr(itr) { }
|
||||||
|
|
||||||
/// Returns a GenericRapidJsonAdapter that contains the value of the current
|
/// Returns a GenericRapidJsonAdapter that contains the value of the current
|
||||||
/// element.
|
/// element.
|
||||||
GenericRapidJsonAdapter<ValueType> operator*() const
|
GenericRapidJsonAdapter<ValueType> operator*() const
|
||||||
{
|
{
|
||||||
return GenericRapidJsonAdapter<ValueType>(*itr);
|
return GenericRapidJsonAdapter<ValueType>(*m_itr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a proxy for the value of the current element
|
/// Returns a proxy for the value of the current element
|
||||||
DerefProxy<GenericRapidJsonAdapter<ValueType> > operator->() const
|
DerefProxy<GenericRapidJsonAdapter<ValueType>> operator->() const
|
||||||
{
|
{
|
||||||
return DerefProxy<GenericRapidJsonAdapter<ValueType> >(**this);
|
return DerefProxy<GenericRapidJsonAdapter<ValueType>>(**this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -670,47 +668,47 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool operator==(const GenericRapidJsonArrayValueIterator<ValueType> &other) const
|
bool operator==(const GenericRapidJsonArrayValueIterator<ValueType> &other) const
|
||||||
{
|
{
|
||||||
return itr == other.itr;
|
return m_itr == other.m_itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const GenericRapidJsonArrayValueIterator<ValueType>& other) const
|
bool operator!=(const GenericRapidJsonArrayValueIterator<ValueType>& other) const
|
||||||
{
|
{
|
||||||
return !(itr == other.itr);
|
return m_itr != other.m_itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericRapidJsonArrayValueIterator<ValueType>& operator++()
|
GenericRapidJsonArrayValueIterator<ValueType>& operator++()
|
||||||
{
|
{
|
||||||
itr++;
|
m_itr++;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericRapidJsonArrayValueIterator<ValueType> operator++(int) {
|
GenericRapidJsonArrayValueIterator<ValueType> operator++(int) {
|
||||||
GenericRapidJsonArrayValueIterator<ValueType> iterator_pre(itr);
|
GenericRapidJsonArrayValueIterator<ValueType> iterator_pre(m_itr);
|
||||||
++(*this);
|
++(*this);
|
||||||
return iterator_pre;
|
return iterator_pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericRapidJsonArrayValueIterator<ValueType>& operator--()
|
GenericRapidJsonArrayValueIterator<ValueType>& operator--()
|
||||||
{
|
{
|
||||||
itr--;
|
m_itr--;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void advance(std::ptrdiff_t n)
|
void advance(std::ptrdiff_t n)
|
||||||
{
|
{
|
||||||
itr += n;
|
m_itr += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ptrdiff_t difference(const GenericRapidJsonArrayValueIterator<ValueType> &other)
|
std::ptrdiff_t difference(const GenericRapidJsonArrayValueIterator<ValueType> &other)
|
||||||
{
|
{
|
||||||
return std::distance(itr, other.itr);
|
return std::distance(m_itr, other.itr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
typename ValueType::ConstValueIterator itr;
|
typename ValueType::ConstValueIterator m_itr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -727,7 +725,7 @@ template<class ValueType>
|
|||||||
class GenericRapidJsonObjectMemberIterator:
|
class GenericRapidJsonObjectMemberIterator:
|
||||||
public std::iterator<
|
public std::iterator<
|
||||||
std::bidirectional_iterator_tag, // bi-directional iterator
|
std::bidirectional_iterator_tag, // bi-directional iterator
|
||||||
GenericRapidJsonObjectMember<ValueType> > // value type
|
GenericRapidJsonObjectMember<ValueType>> // value type
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -738,7 +736,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
GenericRapidJsonObjectMemberIterator(
|
GenericRapidJsonObjectMemberIterator(
|
||||||
const typename ValueType::ConstMemberIterator &itr)
|
const typename ValueType::ConstMemberIterator &itr)
|
||||||
: itr(itr) { }
|
: m_itr(itr) { }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -748,14 +746,14 @@ public:
|
|||||||
GenericRapidJsonObjectMember<ValueType> operator*() const
|
GenericRapidJsonObjectMember<ValueType> operator*() const
|
||||||
{
|
{
|
||||||
return GenericRapidJsonObjectMember<ValueType>(
|
return GenericRapidJsonObjectMember<ValueType>(
|
||||||
std::string(itr->name.GetString(), itr->name.GetStringLength()),
|
std::string(m_itr->name.GetString(), m_itr->name.GetStringLength()),
|
||||||
itr->value);
|
m_itr->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a proxy for the value of the current element
|
/// Returns a proxy for the value of the current element
|
||||||
DerefProxy<GenericRapidJsonObjectMember<ValueType> > operator->() const
|
DerefProxy<GenericRapidJsonObjectMember<ValueType>> operator->() const
|
||||||
{
|
{
|
||||||
return DerefProxy<GenericRapidJsonObjectMember<ValueType> >(**this);
|
return DerefProxy<GenericRapidJsonObjectMember<ValueType>>(**this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -771,85 +769,77 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool operator==(const GenericRapidJsonObjectMemberIterator<ValueType> &other) const
|
bool operator==(const GenericRapidJsonObjectMemberIterator<ValueType> &other) const
|
||||||
{
|
{
|
||||||
return itr == other.itr;
|
return m_itr == other.m_itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const GenericRapidJsonObjectMemberIterator<ValueType> &other) const
|
bool operator!=(const GenericRapidJsonObjectMemberIterator<ValueType> &other) const
|
||||||
{
|
{
|
||||||
return !(itr == other.itr);
|
return m_itr != other.m_itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericRapidJsonObjectMemberIterator<ValueType>& operator++()
|
GenericRapidJsonObjectMemberIterator<ValueType>& operator++()
|
||||||
{
|
{
|
||||||
itr++;
|
m_itr++;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericRapidJsonObjectMemberIterator<ValueType> operator++(int)
|
GenericRapidJsonObjectMemberIterator<ValueType> operator++(int)
|
||||||
{
|
{
|
||||||
GenericRapidJsonObjectMemberIterator<ValueType> iterator_pre(itr);
|
GenericRapidJsonObjectMemberIterator<ValueType> iterator_pre(m_itr);
|
||||||
++(*this);
|
++(*this);
|
||||||
return iterator_pre;
|
return iterator_pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericRapidJsonObjectMemberIterator<ValueType>& operator--()
|
GenericRapidJsonObjectMemberIterator<ValueType>& operator--()
|
||||||
{
|
{
|
||||||
itr--;
|
m_itr--;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ptrdiff_t difference(const GenericRapidJsonObjectMemberIterator &other)
|
std::ptrdiff_t difference(const GenericRapidJsonObjectMemberIterator &other)
|
||||||
{
|
{
|
||||||
return std::distance(itr, other.itr);
|
return std::distance(m_itr, other.itr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// Iternal copy of the original RapidJson iterator
|
/// Iternal copy of the original RapidJson iterator
|
||||||
typename ValueType::ConstMemberIterator itr;
|
typename ValueType::ConstMemberIterator m_itr;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
inline bool GenericRapidJsonFrozenValue<ValueType>::equalTo(
|
inline bool GenericRapidJsonFrozenValue<ValueType>::equalTo(const Adapter &other, bool strict) const
|
||||||
const Adapter &other, bool strict) const
|
|
||||||
{
|
{
|
||||||
return GenericRapidJsonAdapter<ValueType>(value).equalTo(other, strict);
|
return GenericRapidJsonAdapter<ValueType>(m_value).equalTo(other, strict);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
inline typename GenericRapidJsonArray<ValueType>::iterator
|
inline typename GenericRapidJsonArray<ValueType>::iterator GenericRapidJsonArray<ValueType>::begin() const
|
||||||
GenericRapidJsonArray<ValueType>::begin() const
|
|
||||||
{
|
{
|
||||||
return value.Begin();
|
return m_value.Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
inline typename GenericRapidJsonArray<ValueType>::iterator
|
inline typename GenericRapidJsonArray<ValueType>::iterator GenericRapidJsonArray<ValueType>::end() const
|
||||||
GenericRapidJsonArray<ValueType>::end() const
|
|
||||||
{
|
{
|
||||||
return value.End();
|
return m_value.End();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class ValueType>
|
||||||
|
inline typename GenericRapidJsonObject<ValueType>::iterator GenericRapidJsonObject<ValueType>::begin() const
|
||||||
|
{
|
||||||
|
return m_value.MemberBegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class ValueType>
|
||||||
|
inline typename GenericRapidJsonObject<ValueType>::iterator GenericRapidJsonObject<ValueType>::end() const
|
||||||
|
{
|
||||||
|
return m_value.MemberEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
inline typename GenericRapidJsonObject<ValueType>::iterator
|
inline typename GenericRapidJsonObject<ValueType>::iterator
|
||||||
GenericRapidJsonObject<ValueType>::begin() const
|
GenericRapidJsonObject<ValueType>::find(const std::string &propertyName) const
|
||||||
{
|
|
||||||
return value.MemberBegin();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class ValueType>
|
|
||||||
inline typename GenericRapidJsonObject<ValueType>::iterator
|
|
||||||
GenericRapidJsonObject<ValueType>::end() const
|
|
||||||
{
|
|
||||||
return value.MemberEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class ValueType>
|
|
||||||
inline typename GenericRapidJsonObject<ValueType>::iterator
|
|
||||||
GenericRapidJsonObject<ValueType>::find(
|
|
||||||
const std::string &propertyName) const
|
|
||||||
{
|
{
|
||||||
// Hack to support older versions of rapidjson where pointers are used as
|
// Hack to support older versions of rapidjson where pointers are used as
|
||||||
// the built in iterator type. In those versions, the FindMember function
|
// the built in iterator type. In those versions, the FindMember function
|
||||||
@ -866,20 +856,18 @@ inline typename GenericRapidJsonObject<ValueType>::iterator
|
|||||||
// properties being compared. We get around this by implementing our
|
// properties being compared. We get around this by implementing our
|
||||||
// own linear scan.
|
// own linear scan.
|
||||||
const size_t propertyNameLength = propertyName.length();
|
const size_t propertyNameLength = propertyName.length();
|
||||||
for (typename ValueType::ConstMemberIterator itr = value.MemberBegin();
|
for (typename ValueType::ConstMemberIterator itr = m_value.MemberBegin(); itr != m_value.MemberEnd(); ++itr) {
|
||||||
itr != value.MemberEnd(); ++itr) {
|
|
||||||
const size_t memberNameLength = itr->name.GetStringLength();
|
const size_t memberNameLength = itr->name.GetStringLength();
|
||||||
if (memberNameLength == propertyNameLength &&
|
if (memberNameLength == propertyNameLength &&
|
||||||
strncmp(itr->name.GetString(), propertyName.c_str(),
|
strncmp(itr->name.GetString(), propertyName.c_str(), itr->name.GetStringLength()) == 0) {
|
||||||
itr->name.GetStringLength()) == 0) {
|
|
||||||
return itr;
|
return itr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return value.MemberEnd();
|
return m_value.MemberEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
return value.FindMember(propertyName.c_str()); // Times are good.
|
return m_value.FindMember(propertyName.c_str()); // Times are good.
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef GenericRapidJsonAdapter<> RapidJsonAdapter;
|
typedef GenericRapidJsonAdapter<> RapidJsonAdapter;
|
||||||
@ -906,18 +894,16 @@ struct AdapterTraits<valijson::adapters::RapidJsonAdapter>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAllocator>
|
typedef rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAllocator> RapidJsonCrt;
|
||||||
RapidJsonCrt;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Specialisation of the AdapterTraits template struct for a
|
* @brief Specialisation of the AdapterTraits template struct for a
|
||||||
* RapidJsonAdapter that uses the default CRT allocator
|
* RapidJsonAdapter that uses the default CRT allocator
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct AdapterTraits<valijson::adapters::GenericRapidJsonAdapter<RapidJsonCrt> >
|
struct AdapterTraits<valijson::adapters::GenericRapidJsonAdapter<RapidJsonCrt>>
|
||||||
{
|
{
|
||||||
typedef rapidjson::GenericDocument<rapidjson::UTF8<>,
|
typedef rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> DocumentType;
|
||||||
rapidjson::CrtAllocator> DocumentType;
|
|
||||||
|
|
||||||
static std::string adapterName()
|
static std::string adapterName()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user