Skip to content

Commit

Permalink
Moved some nlohmann json code out of headers
Browse files Browse the repository at this point in the history
Signed-off-by: Jared Duffey <[email protected]>
  • Loading branch information
JDuffeyBQ committed Oct 15, 2024
1 parent d53f2a3 commit c02a393
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 52 deletions.
2 changes: 0 additions & 2 deletions src/simplnx/Parameters/CreateColorMapParameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "simplnx/Filter/ValueParameter.hpp"
#include "simplnx/simplnx_export.hpp"

#include <nlohmann/json.hpp>

#include <string>

namespace nx::core
Expand Down
51 changes: 51 additions & 0 deletions src/simplnx/Parameters/ReadHDF5DatasetParameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include "simplnx/Utilities/SIMPLConversion.hpp"

#include <nlohmann/json.hpp>

using namespace nx::core;
namespace
{
Expand All @@ -42,6 +44,55 @@ constexpr StringLiteral k_ParentGroupKey = "parent_group";

namespace nx::core
{
// -----------------------------------------------------------------------------
Result<ReadHDF5DatasetParameter::DatasetImportInfo> ReadHDF5DatasetParameter::DatasetImportInfo::ReadJson(const nlohmann::json& json)
{
DatasetImportInfo data;
if(!json.contains(k_DatasetPath_Key.view()))
{
return MakeErrorResult<DatasetImportInfo>(-500, fmt::format("ImportHDF5DatasetParameter ValueType: Cannot find the key \"{}\" in the ValueType json object.", k_DatasetPath_Key));
}
else if(!json[k_DatasetPath_Key.str()].is_string())
{
return MakeErrorResult<DatasetImportInfo>(-501, fmt::format("ImportHDF5DatasetParameter ValueType: 'Dataset Path' value is of type {} and is not a string.", json[k_DatasetPath_Key].type_name()));
}
data.dataSetPath = json[k_DatasetPath_Key.str()];

if(!json.contains(k_ComponentDimensions_Key.view()))
{
return MakeErrorResult<DatasetImportInfo>(-502, fmt::format("ImportHDF5DatasetParameter ValueType: Cannot find the key \"{}\" in the ValueType json object.", k_ComponentDimensions_Key));
}
else if(!json[k_ComponentDimensions_Key.str()].is_string())
{
return MakeErrorResult<DatasetImportInfo>(
-503, fmt::format("ImportHDF5DatasetParameter ValueType: 'Component Dimensions' value is of type {} and is not a string.", json[k_ComponentDimensions_Key].type_name()));
}
data.componentDimensions = json[k_ComponentDimensions_Key.str()];

if(!json.contains(k_TupleDimensions_Key.view()))
{
return MakeErrorResult<DatasetImportInfo>(-502, fmt::format("ImportHDF5DatasetParameter ValueType: Cannot find the key \"{}\" in the ValueType json object.", k_TupleDimensions_Key));
}
else if(!json[k_TupleDimensions_Key.str()].is_string())
{
return MakeErrorResult<DatasetImportInfo>(
-503, fmt::format("ImportHDF5DatasetParameter ValueType: 'Tuple Dimensions' value is of type {} and is not a string.", json[k_TupleDimensions_Key].type_name()));
}
data.tupleDimensions = json[k_TupleDimensions_Key.str()];

return {data};
}

// -----------------------------------------------------------------------------
nlohmann::json ReadHDF5DatasetParameter::DatasetImportInfo::writeJson() const
{
nlohmann::json json;
json[k_DatasetPath_Key.str()] = dataSetPath;
json[k_ComponentDimensions_Key.str()] = componentDimensions;
json[k_TupleDimensions_Key.str()] = tupleDimensions;
return json;
}

// -----------------------------------------------------------------------------
ReadHDF5DatasetParameter::ReadHDF5DatasetParameter(const std::string& name, const std::string& humanName, const std::string& helpText, const ValueType& defaultValue)
: ValueParameter(name, humanName, helpText)
Expand Down
54 changes: 4 additions & 50 deletions src/simplnx/Parameters/ReadHDF5DatasetParameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
#include "simplnx/Filter/ValueParameter.hpp"
#include "simplnx/simplnx_export.hpp"

#include <nlohmann/json.hpp>

#include <list>
#include <memory>

Expand All @@ -47,7 +45,7 @@ namespace nx::core
class SIMPLNX_EXPORT ReadHDF5DatasetParameter : public ValueParameter
{
public:
struct DatasetImportInfo
struct SIMPLNX_EXPORT DatasetImportInfo
{
std::string dataSetPath;
std::string componentDimensions;
Expand All @@ -57,53 +55,9 @@ class SIMPLNX_EXPORT ReadHDF5DatasetParameter : public ValueParameter
static inline constexpr StringLiteral k_ComponentDimensions_Key = "component_dimensions";
static inline constexpr StringLiteral k_TupleDimensions_Key = "tuple_dimensions";

static Result<DatasetImportInfo> ReadJson(const nlohmann::json& json)
{
DatasetImportInfo data;
if(!json.contains(k_DatasetPath_Key.view()))
{
return MakeErrorResult<DatasetImportInfo>(-500, fmt::format("ImportHDF5DatasetParameter ValueType: Cannot find the key \"{}\" in the ValueType json object.", k_DatasetPath_Key));
}
else if(!json[k_DatasetPath_Key.str()].is_string())
{
return MakeErrorResult<DatasetImportInfo>(-501,
fmt::format("ImportHDF5DatasetParameter ValueType: 'Dataset Path' value is of type {} and is not a string.", json[k_DatasetPath_Key].type_name()));
}
data.dataSetPath = json[k_DatasetPath_Key.str()];

if(!json.contains(k_ComponentDimensions_Key.view()))
{
return MakeErrorResult<DatasetImportInfo>(-502, fmt::format("ImportHDF5DatasetParameter ValueType: Cannot find the key \"{}\" in the ValueType json object.", k_ComponentDimensions_Key));
}
else if(!json[k_ComponentDimensions_Key.str()].is_string())
{
return MakeErrorResult<DatasetImportInfo>(
-503, fmt::format("ImportHDF5DatasetParameter ValueType: 'Component Dimensions' value is of type {} and is not a string.", json[k_ComponentDimensions_Key].type_name()));
}
data.componentDimensions = json[k_ComponentDimensions_Key.str()];

if(!json.contains(k_TupleDimensions_Key.view()))
{
return MakeErrorResult<DatasetImportInfo>(-502, fmt::format("ImportHDF5DatasetParameter ValueType: Cannot find the key \"{}\" in the ValueType json object.", k_TupleDimensions_Key));
}
else if(!json[k_TupleDimensions_Key.str()].is_string())
{
return MakeErrorResult<DatasetImportInfo>(
-503, fmt::format("ImportHDF5DatasetParameter ValueType: 'Tuple Dimensions' value is of type {} and is not a string.", json[k_TupleDimensions_Key].type_name()));
}
data.tupleDimensions = json[k_TupleDimensions_Key.str()];

return {data};
}

nlohmann::json writeJson() const
{
nlohmann::json json;
json[k_DatasetPath_Key.str()] = dataSetPath;
json[k_ComponentDimensions_Key.str()] = componentDimensions;
json[k_TupleDimensions_Key.str()] = tupleDimensions;
return json;
}
static Result<DatasetImportInfo> ReadJson(const nlohmann::json& json);

nlohmann::json writeJson() const;
};

using InputFile = std::string;
Expand Down

0 comments on commit c02a393

Please sign in to comment.