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.
This commit is contained in:
Par Winzell 2017-11-17 11:37:19 -08:00
parent c70ded31d5
commit 423458a841
2 changed files with 18 additions and 1 deletions

View File

@ -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}

View File

@ -18,7 +18,12 @@
#include <draco/compression/encode.h>
#include <json.hpp>
using json = nlohmann::json;
#include <fifo_map.hpp>
template<class K, class V, class ignore, class A>
using workaround_fifo_map = nlohmann::fifo_map<K, V, nlohmann::fifo_map_compare<K>, A>;
using json = nlohmann::basic_json<workaround_fifo_map>;
#include "FBX2glTF.h"
#include "RawModel.h"