Skip to content

Commit

Permalink
use external JSON library
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk committed Mar 29, 2022
1 parent ff7bd3d commit 1a3b387
Show file tree
Hide file tree
Showing 6 changed files with 22,117 additions and 24 deletions.
1 change: 0 additions & 1 deletion .github/actions/vtk-install-dep/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ runs:
-DVTK_MODULE_ENABLE_VTK_RenderingOpenGL2=YES
-DVTK_MODULE_ENABLE_VTK_RenderingVolumeOpenGL2=YES
-DVTK_MODULE_ENABLE_VTK_TestingCore=YES
-DVTK_MODULE_ENABLE_VTK_jsoncpp=YES
${{ inputs.vtk_version != 'v9.0.0' && '-DVTK_ENABLE_REMOTE_MODULES=OFF -DVTK_SMP_IMPLEMENTATION_TYPE=STDThread' || null }}
${{ inputs.os == 'windows-latest' && '-Ax64 -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded' || null }}
Expand Down
2 changes: 1 addition & 1 deletion resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ssao": true,
"scalars": "",
"comp": "-2",
"cells": "true"
"cells": true
},
".*(tif|tiff)":
{
Expand Down
15 changes: 10 additions & 5 deletions src/application/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
set(EXEC_PLATFORM_SPECIFIC_FILES "")
set(F3D_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/main.cxx
${CMAKE_CURRENT_SOURCE_DIR}/F3DStarter.cxx
)

if(WIN32)
set(EXEC_PLATFORM_SPECIFIC_FILES "${CMAKE_SOURCE_DIR}/resources/f3d.rc")
list(APPEND F3D_SOURCE_FILES "${CMAKE_SOURCE_DIR}/resources/f3d.rc")
endif()

if(APPLE)
set(EXEC_PLATFORM_SPECIFIC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/F3DNSDelegate.mm")
list(APPEND F3D_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/F3DNSDelegate.mm")
endif()

# Define f3d target
add_executable(f3d main.cxx ${CMAKE_CURRENT_SOURCE_DIR}/F3DStarter.cxx ${EXEC_PLATFORM_SPECIFIC_FILES})
add_executable(f3d ${F3D_SOURCE_FILES})
target_link_libraries(f3d PUBLIC libf3d)
set_target_properties(f3d PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
if (APPLE)
Expand All @@ -16,7 +21,7 @@ elseif (UNIX)
set_target_properties(f3d PROPERTIES INSTALL_RPATH $ORIGIN/../lib)
endif ()

target_compile_features(f3d PRIVATE cxx_std_11)
target_compile_features(f3d PRIVATE cxx_std_17)

if(F3D_STRICT_BUILD)
if(MSVC)
Expand Down
4 changes: 2 additions & 2 deletions src/application/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ int main(int argc, char** argv)
// exit gracefully after cleanup when no process is required
exit(EXIT_SUCCESS);
}
catch (...)
catch (const std::exception& ex)
{
f3d::log::error("F3D encountered an unexpected exception");
f3d::log::error("F3D encountered an unexpected exception: ", ex.what());
exit(EXIT_FAILURE);
}

Expand Down
28 changes: 13 additions & 15 deletions src/library/F3DOptions.cxx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "F3DOptions.h"

#include "cxxopts.hpp"
#include "json.hpp"

#include "F3DException.h"
#include "f3d_config.h"
#include "f3d_engine.h"
#include "f3d_log.h"
#include "f3d_options.h"

#include <vtk_jsoncpp.h>
#include <vtksys/SystemTools.hxx>

#include <fstream>
Expand Down Expand Up @@ -416,29 +416,27 @@ bool ConfigurationOptions::InitializeDictionaryFromConfigFile(const std::string&
return false;
}

Json::Value root;
Json::CharReaderBuilder builder;
builder["collectComments"] = false;
std::string errs;
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
bool success = Json::parseFromStream(builder, file, &root, &errs);
if (!success)
nlohmann::json j;

try
{
file >> j;
}
catch (const std::exception& ex)
{
f3d::log::error("Unable to parse the configuration file ", configFilePath);
f3d::log::error(errs);
f3d::log::error(ex.what());
return false;
}

for (auto const& id : root.getMemberNames())
for (const auto& regexpConfig : j.items())
{
const Json::Value node = root[id];
std::map<std::string, std::string> localDic;
for (auto const& nl : node.getMemberNames())
for (const auto& prop : regexpConfig.value().items())
{
const Json::Value v = node[nl];
localDic[nl] = v.asString();
localDic[prop.key()] = ToString(prop.value());
}
this->ConfigDic[id] = localDic;
this->ConfigDic[regexpConfig.key()] = localDic;
}

return true;
Expand Down
Loading

0 comments on commit 1a3b387

Please sign in to comment.