Skip to content

Commit

Permalink
Add yyjson support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mzf-guest committed Oct 19, 2024
1 parent fa0f8d3 commit f568d35
Show file tree
Hide file tree
Showing 13 changed files with 434 additions and 96 deletions.
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ option(ENABLE_FORTRAN "Build Fortran Support" OFF)
option(ENABLE_MPI "Build MPI Support" OFF)
option(ENABLE_OPENMP "Build OpenMP Support" OFF)

option(USE_SYSTEM_YYJSON "Use yyjson as a replacement for rapidjson." OFF)
if(${USE_SYSTEM_YYJSON})
add_compile_definitions(USE_YYJSON)
endif()

# Add another option that provides extra
# control over conduit tests for cases where
# conduit is brought in as a submodule
Expand Down
12 changes: 9 additions & 3 deletions src/cmake/Setup3rdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ endif()
################################
# Setup includes for RapidJSON
################################
include(cmake/thirdparty/SetupRapidJSON.cmake)
message(STATUS "Using RapidJSON Include: ${RAPIDJSON_INCLUDE_DIR}")
include_directories(${RAPIDJSON_INCLUDE_DIR})
if(${USE_SYSTEM_YYJSON})
find_package(yyjson REQUIRED)
link_libraries(yyjson::yyjson)
include_directories(thirdparty_builtin/yyjson)
else()
include(cmake/thirdparty/SetupRapidJSON.cmake)
message(STATUS "Using RapidJSON Include: ${RAPIDJSON_INCLUDE_DIR}")
include_directories(${RAPIDJSON_INCLUDE_DIR})
endif()

################################
# Setup and build libb64
Expand Down
1 change: 1 addition & 0 deletions src/libs/conduit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ set(conduit_headers
${CMAKE_CURRENT_BINARY_DIR}/conduit_config.h
conduit_config.hpp
${CMAKE_CURRENT_BINARY_DIR}/conduit_bitwidth_style_types.h
conduit_json.hpp
)

#
Expand Down
165 changes: 82 additions & 83 deletions src/libs/conduit/conduit_generator.cpp

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/libs/conduit/conduit_json.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef CONDUIT_JSON_HPP
#define CONDUIT_JSON_HPP

#ifdef USE_YYJSON
#include "conduit_yyjson.h"
#define conduit_json conduit_yyjson
#else
#include "rapidjson/document.h"
#include "rapidjson/error/en.h"
#define conduit_json conduit_rapidjson
#endif

#endif
4 changes: 2 additions & 2 deletions src/tests/conduit/t_conduit_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <iostream>
#include "gtest/gtest.h"
#include "rapidjson/document.h"
#include "conduit_json.hpp"
using namespace conduit;

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -198,7 +198,7 @@ TEST(conduit_node, simple_schema)

std::string res = n.schema().to_json();
std::cout << res;
conduit_rapidjson::Document d;
conduit_json::Document d;
d.Parse<0>(res.c_str());

EXPECT_TRUE(d.HasMember("a"));
Expand Down
2 changes: 1 addition & 1 deletion src/tests/conduit/t_conduit_node_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <iostream>
#include "gtest/gtest.h"
#include "rapidjson/document.h"
#include "conduit_json.hpp"
using namespace conduit;

//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/tests/conduit/t_conduit_node_to_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <iostream>
#include "gtest/gtest.h"
#include "rapidjson/document.h"
#include "conduit_json.hpp"
using namespace conduit;

// TODO(JRC): Figure out if there's any better way to facilitate these conversions
Expand Down
2 changes: 1 addition & 1 deletion src/tests/conduit/t_conduit_node_type_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <iostream>
#include "gtest/gtest.h"
#include "rapidjson/document.h"
#include "conduit_json.hpp"
using namespace conduit;
using namespace conduit::utils;

Expand Down
2 changes: 1 addition & 1 deletion src/tests/conduit/t_conduit_node_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <iostream>
#include "gtest/gtest.h"
#include "rapidjson/document.h"
#include "conduit_json.hpp"
using namespace conduit;

//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/tests/docs/t_conduit_docs_tutorial_basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <iostream>
#include "gtest/gtest.h"
#include "rapidjson/document.h"
#include "conduit_json.hpp"

using namespace conduit;

Expand Down
6 changes: 3 additions & 3 deletions src/tests/thirdparty/t_rapidjson_smoke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
///
//-----------------------------------------------------------------------------

#include "rapidjson/document.h"
#include "conduit_json.hpp"
#include "gtest/gtest.h"

//-----------------------------------------------------------------------------
TEST(rapidjson_smoke, basic_use)
TEST(json_smoke, basic_use)
{
const char json[] = "{ \"hello\" : \"world\" }";

conduit_rapidjson::Document d;
conduit_json::Document d;
d.Parse<0>(json);

ASSERT_STREQ(d["hello"].GetString(),"world");
Expand Down
Loading

0 comments on commit f568d35

Please sign in to comment.