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