From 106a8a60c4f88cb45e3120544f05fb2ac48e6b28 Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Mon, 24 Aug 2020 21:58:03 -0400 Subject: rapidjson serialization --- rapidjson/allocators.h | 8 ++++---- rapidjson/document.h | 14 ++++++++++++-- rapidjson/fwd.h | 4 ++-- rapidjsonwrapper.h | 4 +++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/rapidjson/allocators.h b/rapidjson/allocators.h index 98affe03..68fc35d1 100644 --- a/rapidjson/allocators.h +++ b/rapidjson/allocators.h @@ -64,19 +64,19 @@ public: static const bool kNeedFree = true; void* Malloc(size_t size) { if (size) // behavior of malloc(0) is implementation defined. - return std::malloc(size); + return je_malloc(size); else return NULL; // standardize to returning NULL. } void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { (void)originalSize; if (newSize == 0) { - std::free(originalPtr); + je_free(originalPtr); return NULL; } - return std::realloc(originalPtr, newSize); + return je_realloc(originalPtr, newSize); } - static void Free(void *ptr) { std::free(ptr); } + static void Free(void *ptr) { je_free(ptr); } }; /////////////////////////////////////////////////////////////////////////////// diff --git a/rapidjson/document.h b/rapidjson/document.h index e3e20dfb..f873c272 100644 --- a/rapidjson/document.h +++ b/rapidjson/document.h @@ -536,7 +536,7 @@ template class GenericObject; \tparam Encoding Encoding of the value. (Even non-string values need to have the same encoding in a document) \tparam Allocator Allocator type for allocating memory of object, array and string. */ -template > +template class GenericValue { public: //! Name-value pair in an object. @@ -1206,6 +1206,11 @@ public: return *this; } + GenericValue& AddMember(GenericValue& name, BinaryNinjaCore::string& value, Allocator& allocator) { + GenericValue v(value.data(), allocator); + return AddMember(name, v, allocator); + } + //! Add a constant string value as member (name-value pair) to the object. /*! \param name A string value as name of member. \param value constant string reference as value of member. @@ -1546,6 +1551,11 @@ public: return *this; } + GenericValue& PushBack(BinaryNinjaCore::string value, Allocator& allocator) { + GenericValue v(value.c_str(), allocator); + return PushBack(v, allocator); + } + #if RAPIDJSON_HAS_CXX11_RVALUE_REFS GenericValue& PushBack(GenericValue&& value, Allocator& allocator) { return PushBack(value, allocator); @@ -2020,7 +2030,7 @@ typedef GenericValue > Value; \tparam StackAllocator Allocator for allocating memory for stack during parsing. \warning Although GenericDocument inherits from GenericValue, the API does \b not provide any virtual functions, especially no virtual destructor. To avoid memory leaks, do not \c delete a GenericDocument object via a pointer to a GenericValue. */ -template , typename StackAllocator = CrtAllocator> +template class GenericDocument : public GenericValue { public: typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding. diff --git a/rapidjson/fwd.h b/rapidjson/fwd.h index e8104e84..74f80de7 100644 --- a/rapidjson/fwd.h +++ b/rapidjson/fwd.h @@ -113,12 +113,12 @@ struct GenericStringRef; template class GenericValue; -typedef GenericValue, MemoryPoolAllocator > Value; +typedef GenericValue, CrtAllocator > Value; template class GenericDocument; -typedef GenericDocument, MemoryPoolAllocator, CrtAllocator> Document; +typedef GenericDocument, CrtAllocator, CrtAllocator> Document; // pointer.h diff --git a/rapidjsonwrapper.h b/rapidjsonwrapper.h index 1ff02e7e..ac418807 100644 --- a/rapidjsonwrapper.h +++ b/rapidjsonwrapper.h @@ -20,7 +20,7 @@ struct GenericException: public std::exception } }; -#define RAPIDJSON_HAS_STDSTRING 1 +#define RAPIDJSON_HAS_STDSTRING 0 #define RAPIDJSON_HAS_CXX11_NOEXCEPT 0 #define RAPIDJSON_ASSERT(x) do {if (!(x)) throw GenericException(); } while(0); #define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode,offset) \ @@ -35,6 +35,8 @@ struct ParseException: public std::runtime_error, rapidjson::ParseResult #include "rapidjson/rapidjson.h" #include "rapidjson/document.h" +#include "rapidjson/stringbuffer.h" +#include "rapidjson/writer.h" #if defined(__GNUC__) && __GNUC__ >= 8 #pragma GCC diagnostic pop -- cgit v1.3.1