Skip to content

Commit

Permalink
♻️ Continue moving all the bits of code that need "cereal/archives/js…
Browse files Browse the repository at this point in the history
…on.hpp" in the same file
  • Loading branch information
JulesFouchy committed Sep 30, 2023
1 parent 8f25f74 commit f6f36de
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/Module_Nodes/Module_Nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,3 @@ void Module_Nodes::debug_show_nodes_and_links_registries_windows(Ui_Ref ui) cons
}

} // namespace Lab

#include <cereal/archives/json.hpp>
#include <cereal/types/polymorphic.hpp>
CEREAL_REGISTER_TYPE(Lab::Module_Nodes); // NOLINT
7 changes: 3 additions & 4 deletions src/Module_Nodes/NodesCategoryConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
#include "NodesCategoryConfig.h"
#include <Module_Nodes/NodeColor.h>
#include <cereal/archives/json.hpp>
#include <filesystem>
#include <smart/smart.hpp>
#include "Cool/Path/Path.h"
#include "Cool/Serialization/Serialization.h"
#include "Cool/Variables/internal/color_utils.h"
#include "Serialization/SNodesCategoryConfig.h"
#include "imgui.h"

namespace Lab {

void NodesCategoryConfig::save_to_json() const
{
Cool::Serialization::save<decltype(*this), cereal::JSONOutputArchive>(*this, _path_to_json);
serialize_nodes_cat_cfg(*this, _path_to_json);
}

void NodesCategoryConfig::load_from_json()
{
Cool::Serialization::load<decltype(*this), cereal::JSONInputArchive>(*this, _path_to_json)
deserialize(*this, _path_to_json)
.send_error_if_any([&](std::string const& message) {
return Cool::Message{
.category = "Nodes Category",
Expand Down
11 changes: 11 additions & 0 deletions src/Serialization/SNodesCategoryConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include <filesystem>
#include "Cool/Log/OptionalErrorMessage.h"
#include "Module_Nodes/NodesCategoryConfig.h"

namespace Lab {

auto serialize_nodes_cat_cfg(NodesCategoryConfig const& config, std::filesystem::path const& path) -> bool;
auto deserialize(NodesCategoryConfig& config, std::filesystem::path const& path) -> Cool::OptionalErrorMessage;

} // namespace Lab
17 changes: 15 additions & 2 deletions src/Serialization/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
/// this file as much as possible.
///

#include <cereal/types/polymorphic.hpp>
#include "Cool/Serialization/Serialization.h"
#include "Module_Nodes/Module_Nodes.h"
#include "SNodesCategoryConfig.h"
#include "SProject.h"

//
Expand All @@ -17,10 +20,20 @@ auto serialize(Project const& project, std::filesystem::path const& path) -> boo
{
return Cool::Serialization::save<Project, cereal::JSONOutputArchive>(project, path, "Project");
}

auto deserialize(Project& project, std::filesystem::path const& path) -> Cool::OptionalErrorMessage
{
return Cool::Serialization::load<Project, cereal::JSONInputArchive>(project, path);
}

} // namespace Lab
auto serialize_nodes_cat_cfg(NodesCategoryConfig const& config, std::filesystem::path const& path) -> bool
{
return Cool::Serialization::save<NodesCategoryConfig, cereal::JSONOutputArchive>(config, path);
}
auto deserialize(NodesCategoryConfig& config, std::filesystem::path const& path) -> Cool::OptionalErrorMessage
{
return Cool::Serialization::load<NodesCategoryConfig, cereal::JSONInputArchive>(config, path);
}

} // namespace Lab

CEREAL_REGISTER_TYPE(Lab::Module_Nodes); // NOLINT

0 comments on commit f6f36de

Please sign in to comment.