summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2020-08-24 21:58:03 -0400
committerJosh Ferrell <josh@vector35.com>2020-10-28 18:53:24 -0400
commit106a8a60c4f88cb45e3120544f05fb2ac48e6b28 (patch)
treee5a71b6d91bbdfa3f64cdd2cbbd75abd5fe5d24e
parentbe44532917b2458bb81ba838bce0a0d045957909 (diff)
rapidjson serialization
-rw-r--r--rapidjson/allocators.h8
-rw-r--r--rapidjson/document.h14
-rw-r--r--rapidjson/fwd.h4
-rw-r--r--rapidjsonwrapper.h4
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 <bool, typename> 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 <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
+template <typename Encoding, typename Allocator = CrtAllocator >
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<UTF8<> > 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 Encoding, typename Allocator = MemoryPoolAllocator<>, typename StackAllocator = CrtAllocator>
+template <typename Encoding, typename Allocator = CrtAllocator, typename StackAllocator = CrtAllocator>
class GenericDocument : public GenericValue<Encoding, Allocator> {
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 <typename Encoding, typename Allocator>
class GenericValue;
-typedef GenericValue<UTF8<char>, MemoryPoolAllocator<CrtAllocator> > Value;
+typedef GenericValue<UTF8<char>, CrtAllocator > Value;
template <typename Encoding, typename Allocator, typename StackAllocator>
class GenericDocument;
-typedef GenericDocument<UTF8<char>, MemoryPoolAllocator<CrtAllocator>, CrtAllocator> Document;
+typedef GenericDocument<UTF8<char>, 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