-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_value_converter.hpp
57 lines (49 loc) · 2.43 KB
/
node_value_converter.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/// _______ __ __ __ _____ __ __ __
/// | __| |_/ | \_/ |/ _ \ / \/ \| | fkYAML: A C++ header-only YAML library
/// | __| _ < \_ _/| ___ | _ | |___ version 0.3.9
/// |__| |_| \__| |_| |_| |_|___||___|______| https://github.com/fktn-k/fkYAML
///
/// SPDX-FileCopyrightText: 2023-2024 Kensuke Fukutani <fktn.dev@gmail.com>
/// SPDX-License-Identifier: MIT
///
/// @file
#ifndef FK_YAML_NODE_VALUE_CONVERTER_HPP_
#define FK_YAML_NODE_VALUE_CONVERTER_HPP_
#include <utility>
#include <fkYAML/detail/macros/version_macros.hpp>
#include <fkYAML/detail/conversions/from_node.hpp>
#include <fkYAML/detail/conversions/to_node.hpp>
FK_YAML_NAMESPACE_BEGIN
/// @brief An ADL friendly converter between basic_node objects and native data objects.
/// @tparam ValueType A default target data type.
/// @sa https://fktn-k.github.io/fkYAML/api/node_value_converter/
template <typename ValueType, typename>
class node_value_converter {
public:
/// @brief Convert a YAML node value into compatible native data.
/// @tparam BasicNodeType A basic_node template instance type.
/// @tparam TargetType A native data type for conversion.
/// @param n A basic_node object.
/// @param val A native data object.
/// @sa https://fktn-k.github.io/fkYAML/api/node_value_converter/from_node/
template <typename BasicNodeType, typename TargetType = ValueType>
static auto from_node(BasicNodeType&& n, TargetType& val) noexcept(
noexcept(::fkyaml::from_node(std::forward<BasicNodeType>(n), val)))
-> decltype(::fkyaml::from_node(std::forward<BasicNodeType>(n), val), void()) {
::fkyaml::from_node(std::forward<BasicNodeType>(n), val);
}
/// @brief Convert compatible native data into a YAML node.
/// @tparam BasicNodeType A basic_node template instance type.
/// @tparam TargetType A native data type for conversion.
/// @param n A basic_node object.
/// @param val A native data object.
/// @sa https://fktn-k.github.io/fkYAML/api/node_value_converter/to_node/
template <typename BasicNodeType, typename TargetType = ValueType>
static auto to_node(BasicNodeType& n, TargetType&& val) noexcept(
noexcept(::fkyaml::to_node(n, std::forward<TargetType>(val))))
-> decltype(::fkyaml::to_node(n, std::forward<TargetType>(val))) {
::fkyaml::to_node(n, std::forward<TargetType>(val));
}
};
FK_YAML_NAMESPACE_END
#endif /* FK_YAML_NODE_VALUE_CONVERTER_HPP_ */