don't let the GetObject macro rewrite the GetObject method, add a GetObj alias

This commit is contained in:
Hendrik Muhs 2021-04-19 12:29:11 -07:00
parent 3168d7c343
commit d179facf90
2 changed files with 19 additions and 0 deletions

View File

@ -42,6 +42,15 @@ RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible lo
RAPIDJSON_DIAG_OFF(effc++)
#endif // __GNUC__
#ifdef GetObject
// see https://github.com/Tencent/rapidjson/issues/1448
// a former included windows.h might have defined a macro called GetObject, which affects
// GetObject defined here. This ensures the macro does not get applied
#pragma push_macro("GetObject")
#define RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED
#undef GetObject
#endif
#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
#include <iterator> // std::random_access_iterator_tag
#endif
@ -1602,7 +1611,9 @@ public:
}
Object GetObject() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); }
Object GetObj() { RAPIDJSON_ASSERT(IsObject()); return Object(*this); }
ConstObject GetObject() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); }
ConstObject GetObj() const { RAPIDJSON_ASSERT(IsObject()); return ConstObject(*this); }
//@}
@ -3008,4 +3019,9 @@ private:
RAPIDJSON_NAMESPACE_END
RAPIDJSON_DIAG_POP
#ifdef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED
#pragma pop_macro("GetObject")
#undef RAPIDJSON_WINDOWS_GETOBJECT_WORKAROUND_APPLIED
#endif
#endif // RAPIDJSON_DOCUMENT_H_

View File

@ -22,6 +22,7 @@
#endif
#include "rapidjson/document.h"
#undef GetObject
using namespace rapidjson;
@ -34,4 +35,6 @@ TEST(Platform, GetObject) {
EXPECT_TRUE(o.IsObject());
auto sub = o.GetObject();
EXPECT_TRUE(sub.HasMember("pi"));
auto sub2 = o.GetObj();
EXPECT_TRUE(sub2.HasMember("pi"));
}