From ebc003e205c2ab73645555d9dfe5892e10e1d367 Mon Sep 17 00:00:00 2001 From: Eric Rannaud Date: Thu, 12 Sep 2019 08:57:36 -0700 Subject: [PATCH 1/7] Make GenericMemberIterator::Iterator public again (RAPIDJSON_NOMEMBERITERATORCLASS) d87b698d0f made all definitions of GenericMemberIterator consistent as classes (they were structs with RAPIDJSON_NOMEMBERITERATORCLASS defined), but it didn't keep the member definitions public. document.h:586:71: error: 'Iterator' is a private member of 'rapidjson::GenericMemberIterator, rapidjson::MemoryPoolAllocator >' typedef typename GenericMemberIterator::Iterator MemberIterator; //!< Member iterator for i... ^ document.h:2124:32: note: in instantiation of template class 'rapidjson::GenericValue, rapidjson::MemoryPoolAllocator >' requested here class GenericDocument : public GenericValue { --- include/rapidjson/document.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 9783fe4..35fef09 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -210,12 +210,14 @@ class GenericMemberIterator; //! non-const GenericMemberIterator template class GenericMemberIterator { +public: //! use plain pointer as iterator type typedef GenericMember* Iterator; }; //! const GenericMemberIterator template class GenericMemberIterator { +public: //! use plain const pointer as iterator type typedef const GenericMember* Iterator; }; From 13f5ab4f443d158caf36cb06ff846f5bbb0b491f Mon Sep 17 00:00:00 2001 From: Xuanyi Zhou Date: Sat, 26 Dec 2020 22:58:13 -0500 Subject: [PATCH 2/7] fix schema test compile error --- test/unittest/schematest.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/unittest/schematest.cpp b/test/unittest/schematest.cpp index d9c3a09..01a92b2 100644 --- a/test/unittest/schematest.cpp +++ b/test/unittest/schematest.cpp @@ -2038,9 +2038,6 @@ TEST(SchemaValidator, Ref_remote_issue1210) { class SchemaDocumentProvider : public IRemoteSchemaDocumentProvider { SchemaDocument** collection; - SchemaDocumentProvider(const SchemaDocumentProvider&); - SchemaDocumentProvider& operator=(const SchemaDocumentProvider&); - public: SchemaDocumentProvider(SchemaDocument** collection) : collection(collection) { } virtual const SchemaDocument* GetRemoteDocument(const char* uri, SizeType length) { From 30069262310f27a48dd17d7358ba656c77d5a2fe Mon Sep 17 00:00:00 2001 From: Xuanyi Zhou Date: Sat, 26 Dec 2020 23:09:39 -0500 Subject: [PATCH 3/7] suppress enum bitwise operation warnings on msvc --- include/rapidjson/document.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index d514cc2..533a9ad 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -2003,17 +2003,18 @@ private: // Initial flags of different types. kNullFlag = kNullType, - kTrueFlag = kTrueType | kBoolFlag, - kFalseFlag = kFalseType | kBoolFlag, - kNumberIntFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag, - kNumberUintFlag = kNumberType | kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag, - kNumberInt64Flag = kNumberType | kNumberFlag | kInt64Flag, - kNumberUint64Flag = kNumberType | kNumberFlag | kUint64Flag, - kNumberDoubleFlag = kNumberType | kNumberFlag | kDoubleFlag, - kNumberAnyFlag = kNumberType | kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag, - kConstStringFlag = kStringType | kStringFlag, - kCopyStringFlag = kStringType | kStringFlag | kCopyFlag, - kShortStringFlag = kStringType | kStringFlag | kCopyFlag | kInlineStrFlag, + // These casts are added to suppress the warning on MSVC about bitwise operations between enums of different types. + kTrueFlag = static_cast(kTrueType) | static_cast(kBoolFlag), + kFalseFlag = static_cast(kFalseType) | static_cast(kBoolFlag), + kNumberIntFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kIntFlag | kInt64Flag), + kNumberUintFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kUintFlag | kUint64Flag | kInt64Flag), + kNumberInt64Flag = static_cast(kNumberType) | static_cast(kNumberFlag | kInt64Flag), + kNumberUint64Flag = static_cast(kNumberType) | static_cast(kNumberFlag | kUint64Flag), + kNumberDoubleFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kDoubleFlag), + kNumberAnyFlag = static_cast(kNumberType) | static_cast(kNumberFlag | kIntFlag | kInt64Flag | kUintFlag | kUint64Flag | kDoubleFlag), + kConstStringFlag = static_cast(kStringType) | static_cast(kStringFlag), + kCopyStringFlag = static_cast(kStringType) | static_cast(kStringFlag | kCopyFlag), + kShortStringFlag = static_cast(kStringType) | static_cast(kStringFlag | kCopyFlag | kInlineStrFlag), kObjectFlag = kObjectType, kArrayFlag = kArrayType, From d742a030aa1e7254ffc3115d42046a721c28fa78 Mon Sep 17 00:00:00 2001 From: Xuanyi Zhou Date: Sat, 26 Dec 2020 23:27:43 -0500 Subject: [PATCH 4/7] add body to private copy constructor & copy assignment --- test/unittest/schematest.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unittest/schematest.cpp b/test/unittest/schematest.cpp index 01a92b2..da2a49d 100644 --- a/test/unittest/schematest.cpp +++ b/test/unittest/schematest.cpp @@ -2038,6 +2038,11 @@ TEST(SchemaValidator, Ref_remote_issue1210) { class SchemaDocumentProvider : public IRemoteSchemaDocumentProvider { SchemaDocument** collection; + SchemaDocumentProvider(const SchemaDocumentProvider&) { + } + SchemaDocumentProvider& operator=(const SchemaDocumentProvider&) { + } + public: SchemaDocumentProvider(SchemaDocument** collection) : collection(collection) { } virtual const SchemaDocument* GetRemoteDocument(const char* uri, SizeType length) { From 1e4f59d3aed8235e2cce763570054ef06d7a2fd3 Mon Sep 17 00:00:00 2001 From: Xuanyi Zhou Date: Sat, 26 Dec 2020 23:38:27 -0500 Subject: [PATCH 5/7] add return statement & comment --- test/unittest/schematest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unittest/schematest.cpp b/test/unittest/schematest.cpp index da2a49d..e3caa0f 100644 --- a/test/unittest/schematest.cpp +++ b/test/unittest/schematest.cpp @@ -2038,9 +2038,11 @@ TEST(SchemaValidator, Ref_remote_issue1210) { class SchemaDocumentProvider : public IRemoteSchemaDocumentProvider { SchemaDocument** collection; + // Dummy private copy constructor & assignment operator. SchemaDocumentProvider(const SchemaDocumentProvider&) { } SchemaDocumentProvider& operator=(const SchemaDocumentProvider&) { + return *this; } public: From 5e50f27ed1da8101e4da16b04ac653b21be526f8 Mon Sep 17 00:00:00 2001 From: Xuanyi Zhou Date: Sat, 26 Dec 2020 23:41:42 -0500 Subject: [PATCH 6/7] also initialize class member --- test/unittest/schematest.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unittest/schematest.cpp b/test/unittest/schematest.cpp index e3caa0f..8a51b10 100644 --- a/test/unittest/schematest.cpp +++ b/test/unittest/schematest.cpp @@ -2039,7 +2039,8 @@ TEST(SchemaValidator, Ref_remote_issue1210) { SchemaDocument** collection; // Dummy private copy constructor & assignment operator. - SchemaDocumentProvider(const SchemaDocumentProvider&) { + // Function bodies added so that they compile in MSVC 2019. + SchemaDocumentProvider(const SchemaDocumentProvider&) : collection(NULL) { } SchemaDocumentProvider& operator=(const SchemaDocumentProvider&) { return *this; From cbf62de55d684b70df2ae072097568719454f321 Mon Sep 17 00:00:00 2001 From: Krystian Chmura Date: Tue, 5 Jan 2021 14:20:57 +0100 Subject: [PATCH 7/7] Add implicit conversion from Object and Array to Value (#1404) Allows resolution of JSON Pointer on Object and Array --- include/rapidjson/document.h | 2 ++ test/unittest/pointertest.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 533a9ad..028235e 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -2612,6 +2612,7 @@ public: GenericArray& operator=(const GenericArray& rhs) { value_ = rhs.value_; return *this; } ~GenericArray() {} + operator ValueType&() const { return value_; } SizeType Size() const { return value_.Size(); } SizeType Capacity() const { return value_.Capacity(); } bool Empty() const { return value_.Empty(); } @@ -2667,6 +2668,7 @@ public: GenericObject& operator=(const GenericObject& rhs) { value_ = rhs.value_; return *this; } ~GenericObject() {} + operator ValueType&() const { return value_; } SizeType MemberCount() const { return value_.MemberCount(); } SizeType MemberCapacity() const { return value_.MemberCapacity(); } bool ObjectEmpty() const { return value_.ObjectEmpty(); } diff --git a/test/unittest/pointertest.cpp b/test/unittest/pointertest.cpp index 72c686f..4371803 100644 --- a/test/unittest/pointertest.cpp +++ b/test/unittest/pointertest.cpp @@ -1529,6 +1529,38 @@ TEST(Pointer, Ambiguity) { } } +TEST(Pointer, ResolveOnObject) { + Document d; + EXPECT_FALSE(d.Parse("{\"a\": 123}").HasParseError()); + + { + Value::ConstObject o = static_cast(d).GetObject(); + EXPECT_EQ(123, Pointer("/a").Get(o)->GetInt()); + } + + { + Value::Object o = d.GetObject(); + Pointer("/a").Set(o, 456, d.GetAllocator()); + EXPECT_EQ(456, Pointer("/a").Get(o)->GetInt()); + } +} + +TEST(Pointer, ResolveOnArray) { + Document d; + EXPECT_FALSE(d.Parse("[1, 2, 3]").HasParseError()); + + { + Value::ConstArray a = static_cast(d).GetArray(); + EXPECT_EQ(2, Pointer("/1").Get(a)->GetInt()); + } + + { + Value::Array a = d.GetArray(); + Pointer("/1").Set(a, 123, d.GetAllocator()); + EXPECT_EQ(123, Pointer("/1").Get(a)->GetInt()); + } +} + TEST(Pointer, LessThan) { static const struct { const char *str;