ChimeraTK-DeviceAccess
03.26.00
Loading...
Searching...
No Matches
JsonExtensions.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2
// SPDX-License-Identifier: LGPL-3.0-or-later
3
#pragma once
4
5
#include <nlohmann/json.hpp>
6
7
#include <optional>
8
9
namespace
nlohmann
{
10
11
template
<
typename
T>
12
struct
adl_serializer<
std
::optional<T>> {
13
static
void
to_json
(
json
& j,
const
std::optional<T>& opt) {
14
if
(opt.has_value()) {
15
j = *opt;
16
}
17
else
{
18
j =
nullptr
;
19
}
20
}
21
22
static
void
from_json
(
const
json
& j, std::optional<T>& opt) {
23
if
(j.is_null()) {
24
opt = std::nullopt;
25
}
26
else
{
27
opt = j.get<T>();
28
}
29
}
30
};
31
32
}
// namespace nlohmann
json
nlohmann::json json
Definition
MuxedInterruptDistributor.cc:12
nlohmann
Definition
JsonExtensions.h:9
std
STL namespace.
nlohmann::adl_serializer< std::optional< T > >::to_json
static void to_json(json &j, const std::optional< T > &opt)
Definition
JsonExtensions.h:13
nlohmann::adl_serializer< std::optional< T > >::from_json
static void from_json(const json &j, std::optional< T > &opt)
Definition
JsonExtensions.h:22
sources
ChimeraTK-DeviceAccess
include
JsonExtensions.h
Generated by
1.9.8