-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #702 from wildmeshing/dzint/import_export_cache_co…
…mponents Dzint/import export cache components
- Loading branch information
Showing
14 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <nlohmann/json.hpp> | ||
#include <wmtk/components/base/Paths.hpp> | ||
#include <wmtk/components/export_cache/export_cache.hpp> | ||
#include <wmtk/components/input/input.hpp> | ||
|
||
using namespace wmtk::components::base; | ||
using json = nlohmann::json; | ||
|
||
const std::filesystem::path data_dir = WMTK_DATA_DIR; | ||
|
||
TEST_CASE("component_export_cache", "[components][export_cache]") | ||
{ | ||
wmtk::io::Cache cache("wmtk_cache", "."); | ||
|
||
// input | ||
{ | ||
const std::filesystem::path input_file = data_dir / "small.msh"; | ||
json component_json = { | ||
{"name", "input_mesh"}, | ||
{"file", input_file.string()}, | ||
{"ignore_z", false}}; | ||
|
||
|
||
CHECK_NOTHROW(wmtk::components::input(Paths(), component_json, cache)); | ||
} | ||
|
||
wmtk::io::Cache cache_dump("wmtk_dump", "."); | ||
|
||
// export cache | ||
{ | ||
json o; | ||
o["folder"] = cache_dump.get_cache_path() / "exported_cache"; | ||
|
||
CHECK_NOTHROW(wmtk::components::export_cache(Paths(), o, cache)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <nlohmann/json.hpp> | ||
#include <wmtk/components/base/Paths.hpp> | ||
#include <wmtk/components/export_cache/export_cache.hpp> | ||
#include <wmtk/components/import_cache/import_cache.hpp> | ||
#include <wmtk/components/input/input.hpp> | ||
|
||
using namespace wmtk::components::base; | ||
using json = nlohmann::json; | ||
|
||
const std::filesystem::path data_dir = WMTK_DATA_DIR; | ||
|
||
TEST_CASE("component_import_cache", "[components][import_cache]") | ||
{ | ||
wmtk::io::Cache cache("wmtk_cache", "."); | ||
|
||
// input | ||
{ | ||
const std::filesystem::path input_file = data_dir / "small.msh"; | ||
json component_json = { | ||
{"name", "input_mesh"}, | ||
{"file", input_file.string()}, | ||
{"ignore_z", false}}; | ||
|
||
|
||
CHECK_NOTHROW(wmtk::components::input(Paths(), component_json, cache)); | ||
} | ||
|
||
wmtk::io::Cache cache_dump("wmtk_dump", "."); | ||
|
||
// export cache | ||
{ | ||
json o; | ||
o["folder"] = cache_dump.get_cache_path() / "exported_cache"; | ||
|
||
CHECK_NOTHROW(wmtk::components::export_cache(Paths(), o, cache)); | ||
} | ||
|
||
wmtk::io::Cache cache2("wmtk_cache_from_import", "."); | ||
// import cache | ||
{ | ||
json o; | ||
o["folder"] = cache_dump.get_cache_path() / "exported_cache"; | ||
|
||
CHECK_NOTHROW(wmtk::components::import_cache(Paths(), o, cache2)); | ||
} | ||
|
||
CHECK(cache.equals(cache2)); | ||
} |
9 changes: 9 additions & 0 deletions
9
components/wmtk_components/export_cache/wmtk/components/export_cache/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
set(SRC_FILES | ||
ExportCacheOptions.hpp | ||
export_cache.cpp | ||
export_cache.hpp) | ||
|
||
#CURRENT_COMPONENT_LIB_NAME is set from the main cmake | ||
target_sources(${CURRENT_COMPONENT_LIB_NAME} PRIVATE ${SRC_FILES}) | ||
|
20 changes: 20 additions & 0 deletions
20
components/wmtk_components/export_cache/wmtk/components/export_cache/ExportCacheOptions.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <wmtk/components/base/json_utils.hpp> | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
namespace wmtk { | ||
namespace components { | ||
namespace internal { | ||
|
||
struct ExportCacheOptions | ||
{ | ||
std::filesystem::path folder; | ||
}; | ||
|
||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ExportCacheOptions, folder); | ||
|
||
} // namespace internal | ||
} // namespace components | ||
} // namespace wmtk |
27 changes: 27 additions & 0 deletions
27
components/wmtk_components/export_cache/wmtk/components/export_cache/export_cache.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "export_cache.hpp" | ||
|
||
#include <wmtk/components/base/resolve_path.hpp> | ||
#include <wmtk/utils/Logger.hpp> | ||
|
||
#include "ExportCacheOptions.hpp" | ||
|
||
namespace wmtk::components { | ||
|
||
void export_cache(const base::Paths& paths, const nlohmann::json& j, io::Cache& cache) | ||
{ | ||
using namespace internal; | ||
|
||
ExportCacheOptions options = j.get<ExportCacheOptions>(); | ||
|
||
std::string export_location = | ||
wmtk::components::base::resolve_path(options.folder.string(), paths.root_path); | ||
|
||
if (std::filesystem::exists(export_location)) { | ||
log_and_throw_error("Cannot export cache, folder {} already exists", export_location); | ||
} | ||
|
||
if (!cache.export_cache(export_location)) { | ||
log_and_throw_error("Could not export cache from {}", export_location); | ||
} | ||
} | ||
} // namespace wmtk::components |
12 changes: 12 additions & 0 deletions
12
components/wmtk_components/export_cache/wmtk/components/export_cache/export_cache.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include <nlohmann/json.hpp> | ||
#include <wmtk/io/Cache.hpp> | ||
|
||
#include <wmtk/components/base/Paths.hpp> | ||
|
||
namespace wmtk::components { | ||
|
||
void export_cache(const base::Paths& paths, const nlohmann::json& j, io::Cache& cache); | ||
|
||
} // namespace wmtk::components |
11 changes: 11 additions & 0 deletions
11
components/wmtk_components/export_cache/wmtk/components/export_cache/export_cache_spec.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[ | ||
{ | ||
"pointer": "/", | ||
"type": "object", | ||
"required": ["folder"] | ||
}, | ||
{ | ||
"pointer": "/folder", | ||
"type": "string" | ||
} | ||
] |
9 changes: 9 additions & 0 deletions
9
components/wmtk_components/import_cache/wmtk/components/import_cache/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
set(SRC_FILES | ||
ImportCacheOptions.hpp | ||
import_cache.cpp | ||
import_cache.hpp) | ||
|
||
#CURRENT_COMPONENT_LIB_NAME is set from the main cmake | ||
target_sources(${CURRENT_COMPONENT_LIB_NAME} PRIVATE ${SRC_FILES}) | ||
|
20 changes: 20 additions & 0 deletions
20
components/wmtk_components/import_cache/wmtk/components/import_cache/ImportCacheOptions.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <wmtk/components/base/json_utils.hpp> | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
namespace wmtk { | ||
namespace components { | ||
namespace internal { | ||
|
||
struct ImportCacheOptions | ||
{ | ||
std::filesystem::path folder; | ||
}; | ||
|
||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ImportCacheOptions, folder); | ||
|
||
} // namespace internal | ||
} // namespace components | ||
} // namespace wmtk |
27 changes: 27 additions & 0 deletions
27
components/wmtk_components/import_cache/wmtk/components/import_cache/import_cache.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "import_cache.hpp" | ||
|
||
#include <wmtk/components/base/resolve_path.hpp> | ||
#include <wmtk/utils/Logger.hpp> | ||
|
||
#include "ImportCacheOptions.hpp" | ||
|
||
namespace wmtk::components { | ||
|
||
void import_cache(const base::Paths& paths, const nlohmann::json& j, io::Cache& cache) | ||
{ | ||
using namespace internal; | ||
|
||
ImportCacheOptions options = j.get<ImportCacheOptions>(); | ||
|
||
std::string import_location = | ||
wmtk::components::base::resolve_path(options.folder.string(), paths.root_path); | ||
|
||
if (!std::filesystem::exists(import_location)) { | ||
log_and_throw_error("Cannot import cache, folder {} does not exist", import_location); | ||
} | ||
|
||
if (!cache.import_cache(import_location)) { | ||
log_and_throw_error("Could not import cache from {}", import_location); | ||
} | ||
} | ||
} // namespace wmtk::components |
12 changes: 12 additions & 0 deletions
12
components/wmtk_components/import_cache/wmtk/components/import_cache/import_cache.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include <nlohmann/json.hpp> | ||
#include <wmtk/io/Cache.hpp> | ||
|
||
#include <wmtk/components/base/Paths.hpp> | ||
|
||
namespace wmtk::components { | ||
|
||
void import_cache(const base::Paths& paths, const nlohmann::json& j, io::Cache& cache); | ||
|
||
} // namespace wmtk::components |
11 changes: 11 additions & 0 deletions
11
components/wmtk_components/import_cache/wmtk/components/import_cache/import_cache_spec.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[ | ||
{ | ||
"pointer": "/", | ||
"type": "object", | ||
"required": ["folder"] | ||
}, | ||
{ | ||
"pointer": "/folder", | ||
"type": "string" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters