// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Types/String.h" #include "Engine/Core/Types/StringView.h" // TODO: config RAPIDJSON_SSE2 for rapidjson #define RAPIDJSON_ERROR_CHARTYPE Char #define RAPIDJSON_ERROR_STRING(x) TEXT(x) #define RAPIDJSON_ASSERT(x) ASSERT(x) #define RAPIDJSON_NEW(x) New() #define RAPIDJSON_DELETE(x) Delete(x) #define RAPIDJSON_NOMEMBERITERATORCLASS #include #include #include #include namespace rapidjson_flax { // The memory allocator implementation for rapidjson library that uses default engine Allocator. class FlaxAllocator { public: static const bool kNeedFree = true; void* Malloc(size_t size) { // Behavior of malloc(0) is implementation defined so for size=0 return nullptr. // By default Flax doesn't use Allocate(0) so it's not important for the engine itself. if (size) return Allocator::Allocate((uint64)size); return nullptr; } void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { return AllocatorExt::Realloc(originalPtr, (uint64)originalSize, (uint64)newSize); } static void Free(void* ptr) { Allocator::Free(ptr); } }; // String buffer with UTF8 encoding typedef rapidjson::GenericStringBuffer, FlaxAllocator> StringBuffer; // GenericDocument with UTF8 encoding typedef rapidjson::GenericDocument, rapidjson::MemoryPoolAllocator, FlaxAllocator> Document; // GenericValue with UTF8 encoding typedef rapidjson::GenericValue, rapidjson::MemoryPoolAllocator> Value; // JSON writer to the stream template, typename TargetEncoding = rapidjson::UTF8<>, unsigned writeFlags = rapidjson::kWriteDefaultFlags> using Writer = rapidjson::Writer; // Pretty JSON writer to the stream template, typename TargetEncoding = rapidjson::UTF8<>, unsigned writeFlags = rapidjson::kWriteDefaultFlags> using PrettyWriter = rapidjson::PrettyWriter; }