From 423458a841532146f43a01b62c1d7c6b9e87e050 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Fri, 17 Nov 2017 11:37:19 -0800 Subject: [PATCH] Construct JSON with explicit key order. We are at liberty to order our JSON any way we like (by spec) and we can improve readability a lot by doing so. By default, this JSON library uses an unordered map for objects, but it's relatively easy to switch in a FiFo map that keeps track of the insertion order. --- CMakeLists.txt | 12 ++++++++++++ src/Raw2Gltf.h | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f236a7..b7d3518 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,16 @@ set(MATHFU_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/mathfu/src/MathFu/include/" "${CMAKE_BINARY_DIR}/mathfu/src/MathFu/dependencies/vectorial/include") +# OrderedMap +ExternalProject_Add(FiFoMap + PREFIX fifo_map + GIT_REPOSITORY https://github.com/nlohmann/fifo_map + CONFIGURE_COMMAND ${CMAKE_COMMAND} -E echo "Skipping FiFoMap configure step." + BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Skipping FiFoMap build step." + INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "Skipping FiFoMap install step." +) +set(FIFO_MAP_INCLUDE_DIR "${CMAKE_BINARY_DIR}/fifo_map/src/FiFoMap/src") + # JSON ExternalProject_Add(Json PREFIX json @@ -138,6 +148,7 @@ add_executable(FBX2glTF ${SOURCE_FILES}) add_dependencies(FBX2glTF Draco MathFu + FiFoMap Json CxxOpts CPPCodec @@ -167,6 +178,7 @@ target_include_directories(FBX2glTF PUBLIC ${FBXSDK_INCLUDE_DIR} ${DRACO_INCLUDE_DIR} ${MATHFU_INCLUDE_DIRS} + ${FIFO_MAP_INCLUDE_DIR} ${JSON_INCLUDE_DIR} ${CXXOPTS_INCLUDE_DIR} ${CPPCODEC_INCLUDE_DIR} diff --git a/src/Raw2Gltf.h b/src/Raw2Gltf.h index 8e6ecf5..f83224b 100644 --- a/src/Raw2Gltf.h +++ b/src/Raw2Gltf.h @@ -18,7 +18,12 @@ #include #include -using json = nlohmann::json; +#include + +template +using workaround_fifo_map = nlohmann::fifo_map, A>; + +using json = nlohmann::basic_json; #include "FBX2glTF.h" #include "RawModel.h"