Shamrock
2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shamsolvergraph
include
shamsolvergraph
edge
IDataEdgeSerializable.hpp
Go to the documentation of this file.
1
// -------------------------------------------------------//
2
//
3
// SHAMROCK code for hydrodynamics
4
// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5
// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6
// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7
//
8
// -------------------------------------------------------//
9
10
#pragma once
11
18
19
#include "
shambase/exception.hpp
"
20
#include "
shambase/pre_main_call.hpp
"
21
#include "
shambase/type_name_info.hpp
"
22
#include "nlohmann/json_fwd.hpp"
23
#include "
shamsolvergraph/JsonSerializable.hpp
"
24
#include "
shamsolvergraph/edge/IDataEdge.hpp
"
25
#include <stdexcept>
26
27
namespace
shamrock::solvergraph {
28
29
template
<
class
T>
30
class
IDataEdgeSerializable
:
public
IDataEdge
<T>,
public
JsonSerializable
{
31
public
:
32
using
IDataEdge
<T>
::IDataEdge
;
33
using
IDataEdge
<T>::data;
34
35
void
_impl_to_json
(nlohmann::json &j)
const override
{
36
j[
"data"
] = data;
37
j[
"label"
] = this->get_label();
38
j[
"tex_symbol"
] = this->get_raw_tex_symbol();
39
};
40
41
static
IDataEdgeSerializable<T>
from_json
(
const
nlohmann::json &j) {
42
std::string label = j.at(
"label"
).get<std::string>();
43
std::string tex_symbol = j.at(
"tex_symbol"
).get<std::string>();
44
45
auto
tmp =
IDataEdgeSerializable<T>
(label, tex_symbol);
46
tmp.data = j.at(
"data"
).get<T>();
47
return
tmp;
48
};
49
50
inline
static
std::string type_name_static() {
51
return
"IDataEdgeSerializable<"
+ shambase::get_type_name<T>() +
">"
;
52
}
53
54
std::string
type_name
()
const override
{
return
type_name_static(); };
55
};
56
57
}
// namespace shamrock::solvergraph
58
59
#define REGISTER_IDATAEDGESERIALIZABLE(Tin) \
60
PRE_MAIN_FUNCTION_CALL([&]() { \
61
using T = Tin; \
62
auto &instance = shamrock::solvergraph::JsonSerializable_registry::instance(); \
63
if (!instance.is_type_registered(T::type_name_static())) { \
64
instance.register_type<T>(T::type_name_static()); \
65
} \
66
})
67
68
REGISTER_IDATAEDGESERIALIZABLE(
shamrock::solvergraph::IDataEdgeSerializable<f64>
);
IDataEdge.hpp
JsonSerializable.hpp
Polymorphic JSON serialization via a type registry.
shamrock::solvergraph::from_json
void from_json(const nlohmann::json &j, SolverGraphSerializable &p)
Deserialize a SolverGraphSerializable from JSON.
Definition
SolverGraphSerializable.hpp:83
shamrock::solvergraph::IDataEdgeSerializable
Definition
IDataEdgeSerializable.hpp:30
shamrock::solvergraph::IDataEdgeSerializable::_impl_to_json
void _impl_to_json(nlohmann::json &j) const override
Write derived-class fields into a JSON object.
Definition
IDataEdgeSerializable.hpp:35
shamrock::solvergraph::IDataEdgeSerializable::type_name
std::string type_name() const override
Return the type discriminator string for this class.
Definition
IDataEdgeSerializable.hpp:54
shamrock::solvergraph::IDataEdge
Definition
IDataEdge.hpp:27
exception.hpp
This header file contains utility functions related to exception handling in the code.
pre_main_call.hpp
Provides a macro to call a lambda before main.
shamrock::solvergraph::JsonSerializable
Base interface for types that can be serialized to and from JSON.
Definition
JsonSerializable.hpp:72
type_name_info.hpp
Generated on
for Shamrock by
1.15.0