Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
json_std_optional.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
19#include <nlohmann/json.hpp>
20#include <optional>
21
22namespace nlohmann {
23 template<typename T>
24 struct adl_serializer<std::optional<T>> {
25 static void to_json(json &j, const std::optional<T> &opt) {
26 if (opt.has_value()) {
27 j = *opt;
28 } else {
29 j = nullptr;
30 }
31 }
32
33 static void from_json(const json &j, std::optional<T> &opt) {
34 if (j.is_null()) {
35 opt = std::nullopt;
36 } else {
37 opt = j.get<T>();
38 }
39 }
40 };
41} // namespace nlohmann
void to_json(nlohmann::json &j, const PatchSchedulerConfig &p)
Converts a PatchSchedulerConfig object to a JSON object.
void from_json(const nlohmann::json &j, PatchSchedulerConfig &p)
Deserializes a PatchSchedulerConfig object from a JSON object.
STL namespace.