Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
make_node.hpp
Go to the documentation of this file.
1// # This file is a part of toml++ and is subject to the the terms of the MIT license.
2// # Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
3// # See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
4// SPDX-License-Identifier: MIT
5#pragma once
6
8#include "header_start.hpp"
9
12 template <typename T>
13 TOML_NODISCARD TOML_ATTR(returns_nonnull) auto* make_node_impl_specialized(
14 T && val, [[maybe_unused]] value_flags flags) {
15 using unwrapped_type = unwrap_node<remove_cvref<T>>;
16 static_assert(!std::is_same_v<unwrapped_type, node>);
17 static_assert(!is_node_view<unwrapped_type>);
18
19 // arrays + tables - invoke copy/move ctor
20 if constexpr (is_one_of<unwrapped_type, array, table>) {
21 return new unwrapped_type(static_cast<T&&>(val));
22 }
23
24 // values
25 else {
26 using native_type = native_type_of<unwrapped_type>;
27 using value_type = value<native_type>;
28
29 value_type* out;
30
31 // copy/move ctor
32 if constexpr (std::is_same_v<remove_cvref<T>, value_type>) {
33 out = new value_type{static_cast<T&&>(val), flags};
34 }
35
36 // creating from raw value
37 else {
38 static_assert(!is_wide_string<T> || TOML_ENABLE_WINDOWS_COMPAT,
39 "Instantiating values from wide-character strings is only "
40 "supported on Windows with TOML_ENABLE_WINDOWS_COMPAT enabled.");
41
42 if constexpr (!is_losslessly_convertible_to_native<unwrapped_type>) {
43 if constexpr (std::is_same_v<native_type, int64_t>)
44 static_assert(always_false<T>,
45 "Integral value initializers must be losslessly convertible to int64_t");
46 else if constexpr (std::is_same_v<native_type, double>)
47 static_assert(
48 always_false<T>,
49 "Floating-point value initializers must be losslessly convertible to double");
50 else
51 static_assert(
52 always_false<T>,
53 "Value initializers must be losslessly convertible to one of the TOML value types");
54 }
55
56 if constexpr (is_wide_string<T>) {
57#if TOML_ENABLE_WINDOWS_COMPAT
58 out = new value_type{narrow(static_cast<T&&>(val))};
59#else
60 static_assert(always_false<T>, "Evaluated unreachable branch!");
61#endif
62 } else
63 out = new value_type{static_cast<T&&>(val)};
64
66 }
67
68 return out;
69 }
70 }
71
72 template <typename T>
74 using unwrapped_type = unwrap_node<remove_cvref<T>>;
75 if constexpr (std::is_same_v<unwrapped_type, node> || is_node_view<unwrapped_type>) {
76 if constexpr (is_node_view<unwrapped_type>) {
77 if (!val) return static_cast<toml::node*>(nullptr);
78 }
79
80 return static_cast<T&&>(val).visit([flags](auto&& concrete) {
81 return static_cast<toml::node*>(
82 make_node_impl_specialized(static_cast<decltype(concrete)&&>(concrete), flags));
83 });
84 } else
85 return make_node_impl_specialized(static_cast<T&&>(val), flags);
86 }
87
88 template <typename T>
89 TOML_NODISCARD auto* make_node_impl(inserter<T> && val,
91 return make_node_impl(static_cast<T&&>(val.value), flags);
92 }
93
94 template <typename T, bool = (is_node<T> || is_node_view<T> || is_value<T> ||
95 can_partially_represent_native<T>)>
96 struct inserted_type_of_ {
97 using type = std::remove_pointer_t<decltype(make_node_impl(std::declval<T>()))>;
98 };
99
100 template <typename T>
101 struct inserted_type_of_<inserter<T>, false> {
102 using type = typename inserted_type_of_<remove_cvref<T>>::type;
103 };
104
105 template <typename T>
106 struct inserted_type_of_<T, false> {
107 using type = void;
108 };
109
110 template <typename T>
112 return node_ptr{make_node_impl(static_cast<T&&>(val), flags)};
113 }
114
115 template <typename... T>
116 struct emplaced_type_of_ {
117 using type = void;
118 };
119
120 template <typename T>
121 struct emplaced_type_of_<T> {
122 using type = std::conditional_t<is_one_of<T, node, node_view<node>, node_view<const node>>,
123 void, typename inserted_type_of_<T>::type>;
124 };
125
126 template <typename T>
127 struct emplaced_type_of_<inserter<T>> {
128 using type = typename emplaced_type_of_<remove_cvref<T>>::type;
129 };
130
131 template <typename... T>
132 using emplaced_type_of = typename emplaced_type_of_<remove_cvref<T>...>::type;
133}
136
151 template <typename T>
152 using inserted_type_of =
153 POXY_IMPLEMENTATION_DETAIL(typename impl::inserted_type_of_<impl::remove_cvref<T>>::type);
154}
156
157#include "header_end.hpp"
#define T
Definition 17.names.cpp:163
#define val
Definition 17.names.cpp:570
const char * narrow(char *dst, const char *src)
#define flags
const int out
enum TOML_OPEN_FLAGS_ENUM value_flags
Metadata associated with TOML values.
constexpr value_flags preserve_source_value_flags
Special #toml::value_flags constant used for array + table insert functions to specify that any value...
#define TOML_ENABLE_WINDOWS_COMPAT
Enables the use of wide strings (wchar_t, std::wstring) in various places throughout the library when...
TOML_NAMESPACE_START
TOML_NAMESPACE_END
#define POXY_IMPLEMENTATION_DETAIL(...)
#define TOML_NODISCARD
#define TOML_ATTR(...)
#define TOML_IMPL_NAMESPACE_END
#define TOML_IMPL_NAMESPACE_START
#define false
Definition stdbool.h:26
Helper class for suppressing move-construction in single-argument array constructors.