/src/tomlplusplus/include/toml++/impl/value.hpp
Line | Count | Source |
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 | | |
7 | | #include "date_time.hpp" |
8 | | #include "node.hpp" |
9 | | #include "print_to_stream.hpp" |
10 | | #include "std_utility.hpp" |
11 | | #include "header_start.hpp" |
12 | | TOML_DISABLE_ARITHMETIC_WARNINGS; |
13 | | |
14 | | /// \cond |
15 | | // clang-format off |
16 | | |
17 | | #if TOML_ENABLE_WINDOWS_COMPAT |
18 | | #define TOML_SA_VALUE_MESSAGE_WSTRING TOML_SA_LIST_SEP "std::wstring" |
19 | | #else |
20 | | #define TOML_SA_VALUE_MESSAGE_WSTRING |
21 | | #endif |
22 | | #if TOML_HAS_CHAR8 |
23 | | #define TOML_SA_VALUE_MESSAGE_U8STRING_VIEW TOML_SA_LIST_SEP "std::u8string_view" |
24 | | #define TOML_SA_VALUE_MESSAGE_CONST_CHAR8 TOML_SA_LIST_SEP "const char8_t*" |
25 | | #else |
26 | | #define TOML_SA_VALUE_MESSAGE_U8STRING_VIEW |
27 | | #define TOML_SA_VALUE_MESSAGE_CONST_CHAR8 |
28 | | #endif |
29 | | |
30 | | #define TOML_SA_VALUE_EXACT_FUNC_MESSAGE(type_arg) \ |
31 | | "The " type_arg " must be one of:" \ |
32 | | TOML_SA_LIST_NEW "A native TOML value type" \ |
33 | | TOML_SA_NATIVE_VALUE_TYPE_LIST \ |
34 | | \ |
35 | | TOML_SA_LIST_NXT "A non-view type capable of losslessly representing a native TOML value type" \ |
36 | | TOML_SA_LIST_BEG "std::string" \ |
37 | | TOML_SA_VALUE_MESSAGE_WSTRING \ |
38 | | TOML_SA_LIST_SEP "any signed integer type >= 64 bits" \ |
39 | | TOML_SA_LIST_SEP "any floating-point type >= 64 bits" \ |
40 | | TOML_SA_LIST_END \ |
41 | | \ |
42 | | TOML_SA_LIST_NXT "An immutable view type not requiring additional temporary storage" \ |
43 | | TOML_SA_LIST_BEG "std::string_view" \ |
44 | | TOML_SA_VALUE_MESSAGE_U8STRING_VIEW \ |
45 | | TOML_SA_LIST_SEP "const char*" \ |
46 | | TOML_SA_VALUE_MESSAGE_CONST_CHAR8 \ |
47 | | TOML_SA_LIST_END |
48 | | |
49 | | #define TOML_SA_VALUE_FUNC_MESSAGE(type_arg) \ |
50 | | "The " type_arg " must be one of:" \ |
51 | | TOML_SA_LIST_NEW "A native TOML value type" \ |
52 | | TOML_SA_NATIVE_VALUE_TYPE_LIST \ |
53 | | \ |
54 | | TOML_SA_LIST_NXT "A non-view type capable of losslessly representing a native TOML value type" \ |
55 | | TOML_SA_LIST_BEG "std::string" \ |
56 | | TOML_SA_VALUE_MESSAGE_WSTRING \ |
57 | | TOML_SA_LIST_SEP "any signed integer type >= 64 bits" \ |
58 | | TOML_SA_LIST_SEP "any floating-point type >= 64 bits" \ |
59 | | TOML_SA_LIST_END \ |
60 | | \ |
61 | | TOML_SA_LIST_NXT "A non-view type capable of (reasonably) representing a native TOML value type" \ |
62 | | TOML_SA_LIST_BEG "any other integral type" \ |
63 | | TOML_SA_LIST_SEP "any floating-point type" \ |
64 | | TOML_SA_LIST_END \ |
65 | | \ |
66 | | TOML_SA_LIST_NXT "An immutable view type not requiring additional temporary storage" \ |
67 | | TOML_SA_LIST_BEG "std::string_view" \ |
68 | | TOML_SA_VALUE_MESSAGE_U8STRING_VIEW \ |
69 | | TOML_SA_LIST_SEP "const char*" \ |
70 | | TOML_SA_VALUE_MESSAGE_CONST_CHAR8 \ |
71 | | TOML_SA_LIST_END |
72 | | |
73 | | // clang-format on |
74 | | /// \endcond |
75 | | |
76 | | /// \cond |
77 | | TOML_IMPL_NAMESPACE_START |
78 | | { |
79 | | template <typename T, typename...> |
80 | | struct native_value_maker |
81 | | { |
82 | | template <typename... Args> |
83 | | TOML_NODISCARD |
84 | | static T make(Args&&... args) noexcept(std::is_nothrow_constructible_v<T, Args&&...>) |
85 | 10.0k | { |
86 | | if constexpr (std::is_aggregate_v<T>) |
87 | | return T{ static_cast<Args&&>(args)... }; |
88 | | else |
89 | 10.0k | return T(static_cast<Args&&>(args)...); |
90 | 10.0k | } std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > toml::v3::impl::native_value_maker<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string_view<char, std::__1::char_traits<char> > >::make<std::__1::basic_string_view<char, std::__1::char_traits<char> > >(std::__1::basic_string_view<char, std::__1::char_traits<char> >&&) Line | Count | Source | 85 | 8.32k | { | 86 | | if constexpr (std::is_aggregate_v<T>) | 87 | | return T{ static_cast<Args&&>(args)... }; | 88 | | else | 89 | 8.32k | return T(static_cast<Args&&>(args)...); | 90 | 8.32k | } |
long toml::v3::impl::native_value_maker<long, long long>::make<long long>(long long&&) Line | Count | Source | 85 | 1.67k | { | 86 | | if constexpr (std::is_aggregate_v<T>) | 87 | | return T{ static_cast<Args&&>(args)... }; | 88 | | else | 89 | 1.67k | return T(static_cast<Args&&>(args)...); | 90 | 1.67k | } |
|
91 | | }; |
92 | | |
93 | | template <typename T> |
94 | | struct native_value_maker<T, T> |
95 | | { |
96 | | template <typename U> |
97 | | TOML_NODISCARD |
98 | | TOML_ALWAYS_INLINE |
99 | | static U&& make(U&& val) noexcept |
100 | 466k | { |
101 | 466k | return static_cast<U&&>(val); |
102 | 466k | } bool&& toml::v3::impl::native_value_maker<bool, bool>::make<bool>(bool&&) Line | Count | Source | 100 | 696 | { | 101 | 696 | return static_cast<U&&>(val); | 102 | 696 | } |
long&& toml::v3::impl::native_value_maker<long, long>::make<long>(long&&) Line | Count | Source | 100 | 444k | { | 101 | 444k | return static_cast<U&&>(val); | 102 | 444k | } |
double&& toml::v3::impl::native_value_maker<double, double>::make<double>(double&&) Line | Count | Source | 100 | 7.61k | { | 101 | 7.61k | return static_cast<U&&>(val); | 102 | 7.61k | } |
long& toml::v3::impl::native_value_maker<long, long>::make<long&>(long&) Line | Count | Source | 100 | 4.93k | { | 101 | 4.93k | return static_cast<U&&>(val); | 102 | 4.93k | } |
toml::v3::time&& toml::v3::impl::native_value_maker<toml::v3::time, toml::v3::time>::make<toml::v3::time>(toml::v3::time&&) Line | Count | Source | 100 | 1.72k | { | 101 | 1.72k | return static_cast<U&&>(val); | 102 | 1.72k | } |
toml::v3::date&& toml::v3::impl::native_value_maker<toml::v3::date, toml::v3::date>::make<toml::v3::date>(toml::v3::date&&) Line | Count | Source | 100 | 2.52k | { | 101 | 2.52k | return static_cast<U&&>(val); | 102 | 2.52k | } |
toml::v3::stdopt::date_time&& toml::v3::impl::native_value_maker<toml::v3::stdopt::date_time, toml::v3::stdopt::date_time>::make<toml::v3::stdopt::date_time>(toml::v3::stdopt::date_time&&) Line | Count | Source | 100 | 4.10k | { | 101 | 4.10k | return static_cast<U&&>(val); | 102 | 4.10k | } |
|
103 | | }; |
104 | | |
105 | | #if TOML_HAS_CHAR8 || TOML_ENABLE_WINDOWS_COMPAT |
106 | | |
107 | | struct string_maker |
108 | | { |
109 | | template <typename T> |
110 | | TOML_NODISCARD |
111 | | static std::string make(T&& arg) |
112 | | { |
113 | | using arg_type = std::decay_t<T>; |
114 | | #if TOML_HAS_CHAR8 |
115 | | if constexpr (is_one_of<arg_type, char8_t*, const char8_t*>) |
116 | | { |
117 | | return std::string(reinterpret_cast<const char*>(static_cast<const char8_t*>(arg))); |
118 | | } |
119 | | if constexpr (is_one_of<arg_type, std::u8string, std::u8string_view>) |
120 | | { |
121 | | return std::string(reinterpret_cast<const char*>(static_cast<const char8_t*>(arg.data())), |
122 | | arg.length()); |
123 | | } |
124 | | #endif |
125 | | |
126 | | #if TOML_ENABLE_WINDOWS_COMPAT |
127 | | if constexpr (is_wide_string<arg_type>) |
128 | | { |
129 | | return narrow(static_cast<T&&>(arg)); |
130 | | } |
131 | | #endif |
132 | | } |
133 | | }; |
134 | | |
135 | | #if TOML_HAS_CHAR8 |
136 | | template <> |
137 | | struct native_value_maker<std::string, char8_t*> : string_maker |
138 | | {}; |
139 | | template <> |
140 | | struct native_value_maker<std::string, const char8_t*> : string_maker |
141 | | {}; |
142 | | template <> |
143 | | struct native_value_maker<std::string, std::u8string> : string_maker |
144 | | {}; |
145 | | template <> |
146 | | struct native_value_maker<std::string, std::u8string_view> : string_maker |
147 | | {}; |
148 | | #endif // TOML_HAS_CHAR8 |
149 | | |
150 | | #if TOML_ENABLE_WINDOWS_COMPAT |
151 | | template <> |
152 | | struct native_value_maker<std::string, wchar_t*> : string_maker |
153 | | {}; |
154 | | template <> |
155 | | struct native_value_maker<std::string, const wchar_t*> : string_maker |
156 | | {}; |
157 | | template <> |
158 | | struct native_value_maker<std::string, std::wstring> : string_maker |
159 | | {}; |
160 | | template <> |
161 | | struct native_value_maker<std::string, std::wstring_view> : string_maker |
162 | | {}; |
163 | | #endif // TOML_ENABLE_WINDOWS_COMPAT |
164 | | |
165 | | #endif // TOML_HAS_CHAR8 || TOML_ENABLE_WINDOWS_COMPAT |
166 | | |
167 | | template <typename T> |
168 | | TOML_CONST_GETTER |
169 | | inline optional<T> node_integer_cast(int64_t val) noexcept |
170 | | { |
171 | | static_assert(node_type_of<T> == node_type::integer); |
172 | | static_assert(!is_cvref<T>); |
173 | | |
174 | | using traits = value_traits<T>; |
175 | | if constexpr (!traits::is_signed) |
176 | | { |
177 | | if constexpr ((sizeof(T) * CHAR_BIT) < 63) // 63 bits == int64_max |
178 | | { |
179 | | using common_t = decltype(int64_t{} + T{}); |
180 | | if (val < int64_t{} || static_cast<common_t>(val) > static_cast<common_t>(traits::max)) |
181 | | return {}; |
182 | | } |
183 | | else |
184 | | { |
185 | | if (val < int64_t{}) |
186 | | return {}; |
187 | | } |
188 | | } |
189 | | else |
190 | | { |
191 | | if (val < traits::min || val > traits::max) |
192 | | return {}; |
193 | | } |
194 | | return { static_cast<T>(val) }; |
195 | | } |
196 | | |
197 | | template <typename...> |
198 | | struct value_variadic_ctor_allowed : std::true_type |
199 | | {}; |
200 | | |
201 | | template <typename T, typename... Args> |
202 | | struct value_variadic_ctor_allowed<value<T>, value<T>, Args...> : std::false_type |
203 | | {}; |
204 | | } |
205 | | TOML_IMPL_NAMESPACE_END; |
206 | | /// \endcond |
207 | | |
208 | | TOML_NAMESPACE_START |
209 | | { |
210 | | /// \brief A TOML value. |
211 | | /// |
212 | | /// \tparam ValueType The value's native TOML data type. Can be one of: |
213 | | /// - std::string |
214 | | /// - toml::date |
215 | | /// - toml::time |
216 | | /// - toml::date_time |
217 | | /// - int64_t |
218 | | /// - double |
219 | | /// - bool |
220 | | template <typename ValueType> |
221 | | class value : public node |
222 | | { |
223 | | static_assert(impl::is_native<ValueType> && !impl::is_cvref<ValueType>, |
224 | | "A toml::value<> must model one of the native TOML value types:" TOML_SA_NATIVE_VALUE_TYPE_LIST); |
225 | | |
226 | | private: |
227 | | /// \cond |
228 | | |
229 | | friend class TOML_PARSER_TYPENAME; |
230 | | |
231 | | template <typename T, typename U> |
232 | | TOML_CONST_INLINE_GETTER |
233 | | static auto as_value([[maybe_unused]] U* ptr) noexcept |
234 | 0 | { |
235 | | if constexpr (std::is_same_v<value_type, T>) |
236 | 0 | return ptr; |
237 | | else |
238 | 0 | return nullptr; |
239 | 0 | } Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<long, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<double, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<bool, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<toml::v3::date, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<toml::v3::time, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<toml::v3::stdopt::date_time, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const>(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<long, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const>(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<double, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const>(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<bool, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const>(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<toml::v3::date, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const>(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<toml::v3::time, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const>(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const*) Unexecuted instantiation: auto toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_value<toml::v3::stdopt::date_time, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const>(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<bool> >(toml::v3::value<bool>*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<long, toml::v3::value<bool> >(toml::v3::value<bool>*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<double, toml::v3::value<bool> >(toml::v3::value<bool>*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<bool, toml::v3::value<bool> >(toml::v3::value<bool>*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<toml::v3::date, toml::v3::value<bool> >(toml::v3::value<bool>*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<toml::v3::time, toml::v3::value<bool> >(toml::v3::value<bool>*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<toml::v3::stdopt::date_time, toml::v3::value<bool> >(toml::v3::value<bool>*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<bool> const>(toml::v3::value<bool> const*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<long, toml::v3::value<bool> const>(toml::v3::value<bool> const*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<double, toml::v3::value<bool> const>(toml::v3::value<bool> const*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<bool, toml::v3::value<bool> const>(toml::v3::value<bool> const*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<toml::v3::date, toml::v3::value<bool> const>(toml::v3::value<bool> const*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<toml::v3::time, toml::v3::value<bool> const>(toml::v3::value<bool> const*) Unexecuted instantiation: auto toml::v3::value<bool>::as_value<toml::v3::stdopt::date_time, toml::v3::value<bool> const>(toml::v3::value<bool> const*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<long> >(toml::v3::value<long>*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<long, toml::v3::value<long> >(toml::v3::value<long>*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<double, toml::v3::value<long> >(toml::v3::value<long>*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<bool, toml::v3::value<long> >(toml::v3::value<long>*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<toml::v3::date, toml::v3::value<long> >(toml::v3::value<long>*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<toml::v3::time, toml::v3::value<long> >(toml::v3::value<long>*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<toml::v3::stdopt::date_time, toml::v3::value<long> >(toml::v3::value<long>*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<long> const>(toml::v3::value<long> const*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<long, toml::v3::value<long> const>(toml::v3::value<long> const*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<double, toml::v3::value<long> const>(toml::v3::value<long> const*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<bool, toml::v3::value<long> const>(toml::v3::value<long> const*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<toml::v3::date, toml::v3::value<long> const>(toml::v3::value<long> const*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<toml::v3::time, toml::v3::value<long> const>(toml::v3::value<long> const*) Unexecuted instantiation: auto toml::v3::value<long>::as_value<toml::v3::stdopt::date_time, toml::v3::value<long> const>(toml::v3::value<long> const*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<double> >(toml::v3::value<double>*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<long, toml::v3::value<double> >(toml::v3::value<double>*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<double, toml::v3::value<double> >(toml::v3::value<double>*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<bool, toml::v3::value<double> >(toml::v3::value<double>*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<toml::v3::date, toml::v3::value<double> >(toml::v3::value<double>*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<toml::v3::time, toml::v3::value<double> >(toml::v3::value<double>*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<toml::v3::stdopt::date_time, toml::v3::value<double> >(toml::v3::value<double>*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<double> const>(toml::v3::value<double> const*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<long, toml::v3::value<double> const>(toml::v3::value<double> const*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<double, toml::v3::value<double> const>(toml::v3::value<double> const*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<bool, toml::v3::value<double> const>(toml::v3::value<double> const*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<toml::v3::date, toml::v3::value<double> const>(toml::v3::value<double> const*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<toml::v3::time, toml::v3::value<double> const>(toml::v3::value<double> const*) Unexecuted instantiation: auto toml::v3::value<double>::as_value<toml::v3::stdopt::date_time, toml::v3::value<double> const>(toml::v3::value<double> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<toml::v3::time> >(toml::v3::value<toml::v3::time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<long, toml::v3::value<toml::v3::time> >(toml::v3::value<toml::v3::time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<double, toml::v3::value<toml::v3::time> >(toml::v3::value<toml::v3::time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<bool, toml::v3::value<toml::v3::time> >(toml::v3::value<toml::v3::time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<toml::v3::date, toml::v3::value<toml::v3::time> >(toml::v3::value<toml::v3::time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<toml::v3::time, toml::v3::value<toml::v3::time> >(toml::v3::value<toml::v3::time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<toml::v3::stdopt::date_time, toml::v3::value<toml::v3::time> >(toml::v3::value<toml::v3::time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<toml::v3::time> const>(toml::v3::value<toml::v3::time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<long, toml::v3::value<toml::v3::time> const>(toml::v3::value<toml::v3::time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<double, toml::v3::value<toml::v3::time> const>(toml::v3::value<toml::v3::time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<bool, toml::v3::value<toml::v3::time> const>(toml::v3::value<toml::v3::time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<toml::v3::date, toml::v3::value<toml::v3::time> const>(toml::v3::value<toml::v3::time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<toml::v3::time, toml::v3::value<toml::v3::time> const>(toml::v3::value<toml::v3::time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::time>::as_value<toml::v3::stdopt::date_time, toml::v3::value<toml::v3::time> const>(toml::v3::value<toml::v3::time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<toml::v3::date> >(toml::v3::value<toml::v3::date>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<long, toml::v3::value<toml::v3::date> >(toml::v3::value<toml::v3::date>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<double, toml::v3::value<toml::v3::date> >(toml::v3::value<toml::v3::date>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<bool, toml::v3::value<toml::v3::date> >(toml::v3::value<toml::v3::date>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<toml::v3::date, toml::v3::value<toml::v3::date> >(toml::v3::value<toml::v3::date>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<toml::v3::time, toml::v3::value<toml::v3::date> >(toml::v3::value<toml::v3::date>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<toml::v3::stdopt::date_time, toml::v3::value<toml::v3::date> >(toml::v3::value<toml::v3::date>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<toml::v3::date> const>(toml::v3::value<toml::v3::date> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<long, toml::v3::value<toml::v3::date> const>(toml::v3::value<toml::v3::date> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<double, toml::v3::value<toml::v3::date> const>(toml::v3::value<toml::v3::date> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<bool, toml::v3::value<toml::v3::date> const>(toml::v3::value<toml::v3::date> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<toml::v3::date, toml::v3::value<toml::v3::date> const>(toml::v3::value<toml::v3::date> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<toml::v3::time, toml::v3::value<toml::v3::date> const>(toml::v3::value<toml::v3::date> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::date>::as_value<toml::v3::stdopt::date_time, toml::v3::value<toml::v3::date> const>(toml::v3::value<toml::v3::date> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<toml::v3::stdopt::date_time> >(toml::v3::value<toml::v3::stdopt::date_time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<long, toml::v3::value<toml::v3::stdopt::date_time> >(toml::v3::value<toml::v3::stdopt::date_time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<double, toml::v3::value<toml::v3::stdopt::date_time> >(toml::v3::value<toml::v3::stdopt::date_time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<bool, toml::v3::value<toml::v3::stdopt::date_time> >(toml::v3::value<toml::v3::stdopt::date_time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<toml::v3::date, toml::v3::value<toml::v3::stdopt::date_time> >(toml::v3::value<toml::v3::stdopt::date_time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<toml::v3::time, toml::v3::value<toml::v3::stdopt::date_time> >(toml::v3::value<toml::v3::stdopt::date_time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<toml::v3::stdopt::date_time, toml::v3::value<toml::v3::stdopt::date_time> >(toml::v3::value<toml::v3::stdopt::date_time>*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, toml::v3::value<toml::v3::stdopt::date_time> const>(toml::v3::value<toml::v3::stdopt::date_time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<long, toml::v3::value<toml::v3::stdopt::date_time> const>(toml::v3::value<toml::v3::stdopt::date_time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<double, toml::v3::value<toml::v3::stdopt::date_time> const>(toml::v3::value<toml::v3::stdopt::date_time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<bool, toml::v3::value<toml::v3::stdopt::date_time> const>(toml::v3::value<toml::v3::stdopt::date_time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<toml::v3::date, toml::v3::value<toml::v3::stdopt::date_time> const>(toml::v3::value<toml::v3::stdopt::date_time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<toml::v3::time, toml::v3::value<toml::v3::stdopt::date_time> const>(toml::v3::value<toml::v3::stdopt::date_time> const*) Unexecuted instantiation: auto toml::v3::value<toml::v3::stdopt::date_time>::as_value<toml::v3::stdopt::date_time, toml::v3::value<toml::v3::stdopt::date_time> const>(toml::v3::value<toml::v3::stdopt::date_time> const*) |
240 | | |
241 | | ValueType val_; |
242 | | value_flags flags_ = value_flags::none; |
243 | | |
244 | | /// \endcond |
245 | | |
246 | | public: |
247 | | /// \brief The value's underlying data type. |
248 | | using value_type = ValueType; |
249 | | |
250 | | /// \brief A type alias for 'value arguments'. |
251 | | /// \details This differs according to the value's type argument: |
252 | | /// - ints, floats, booleans: `value_type` |
253 | | /// - strings: `string_view` |
254 | | /// - everything else: `const value_type&` |
255 | | using value_arg = POXY_IMPLEMENTATION_DETAIL( |
256 | | std::conditional_t< |
257 | | std::is_same_v<value_type, std::string>, |
258 | | std::string_view, |
259 | | std::conditional_t<impl::is_one_of<value_type, double, int64_t, bool>, value_type, const value_type&>>); |
260 | | |
261 | | /// \brief Constructs a toml value. |
262 | | /// |
263 | | /// \tparam Args Constructor argument types. |
264 | | /// \param args Arguments to forward to the internal value's constructor. |
265 | | TOML_HIDDEN_CONSTRAINT( |
266 | | (impl::value_variadic_ctor_allowed<value<ValueType>, impl::remove_cvref<Args>...>::value), |
267 | | typename... Args) |
268 | | TOML_NODISCARD_CTOR |
269 | | explicit value(Args&&... args) |
270 | | #if !TOML_DISABLE_NOEXCEPT_NOEXCEPT |
271 | | noexcept(noexcept(value_type( |
272 | | impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)))) |
273 | | #endif |
274 | 467k | : val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)) |
275 | 476k | { |
276 | | #if TOML_LIFETIME_HOOKS |
277 | | TOML_VALUE_CREATED; |
278 | | #endif |
279 | 476k | } _ZN4toml2v35valueINS0_4timeEEC2IJS2_ETnNSt3__19enable_ifIXsr4impl27value_variadic_ctor_allowedIS3_Dpu11__remove_cvIu20__remove_reference_tIT_EEEE5valueEiE4typeELi0EEEDpOS7_ Line | Count | Source | 274 | 1.72k | : val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)) | 275 | 1.72k | { | 276 | | #if TOML_LIFETIME_HOOKS | 277 | | TOML_VALUE_CREATED; | 278 | | #endif | 279 | 1.72k | } |
_ZN4toml2v35valueINS0_4dateEEC2IJS2_ETnNSt3__19enable_ifIXsr4impl27value_variadic_ctor_allowedIS3_Dpu11__remove_cvIu20__remove_reference_tIT_EEEE5valueEiE4typeELi0EEEDpOS7_ Line | Count | Source | 274 | 2.52k | : val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)) | 275 | 2.52k | { | 276 | | #if TOML_LIFETIME_HOOKS | 277 | | TOML_VALUE_CREATED; | 278 | | #endif | 279 | 2.52k | } |
_ZN4toml2v35valueINS0_6stdopt9date_timeEEC2IJS3_ETnNSt3__19enable_ifIXsr4impl27value_variadic_ctor_allowedIS4_Dpu11__remove_cvIu20__remove_reference_tIT_EEEE5valueEiE4typeELi0EEEDpOS8_ Line | Count | Source | 274 | 4.10k | : val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)) | 275 | 4.10k | { | 276 | | #if TOML_LIFETIME_HOOKS | 277 | | TOML_VALUE_CREATED; | 278 | | #endif | 279 | 4.10k | } |
_ZN4toml2v35valueINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEC2IJNS2_17basic_string_viewIcS5_EEETnNS2_9enable_ifIXsr4impl27value_variadic_ctor_allowedIS9_Dpu11__remove_cvIu20__remove_reference_tIT_EEEE5valueEiE4typeELi0EEEDpOSE_ Line | Count | Source | 274 | 8.32k | : val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)) | 275 | 8.32k | { | 276 | | #if TOML_LIFETIME_HOOKS | 277 | | TOML_VALUE_CREATED; | 278 | | #endif | 279 | 8.32k | } |
_ZN4toml2v35valueIbEC2IJbETnNSt3__19enable_ifIXsr4impl27value_variadic_ctor_allowedIS2_Dpu11__remove_cvIu20__remove_reference_tIT_EEEE5valueEiE4typeELi0EEEDpOS6_ Line | Count | Source | 274 | 696 | : val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)) | 275 | 696 | { | 276 | | #if TOML_LIFETIME_HOOKS | 277 | | TOML_VALUE_CREATED; | 278 | | #endif | 279 | 696 | } |
_ZN4toml2v35valueIlEC2IJlETnNSt3__19enable_ifIXsr4impl27value_variadic_ctor_allowedIS2_Dpu11__remove_cvIu20__remove_reference_tIT_EEEE5valueEiE4typeELi0EEEDpOS6_ Line | Count | Source | 274 | 444k | : val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)) | 275 | 444k | { | 276 | | #if TOML_LIFETIME_HOOKS | 277 | | TOML_VALUE_CREATED; | 278 | | #endif | 279 | 444k | } |
_ZN4toml2v35valueIdEC2IJdETnNSt3__19enable_ifIXsr4impl27value_variadic_ctor_allowedIS2_Dpu11__remove_cvIu20__remove_reference_tIT_EEEE5valueEiE4typeELi0EEEDpOS6_ Line | Count | Source | 274 | 7.61k | : val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)) | 275 | 7.61k | { | 276 | | #if TOML_LIFETIME_HOOKS | 277 | | TOML_VALUE_CREATED; | 278 | | #endif | 279 | 7.61k | } |
_ZN4toml2v35valueIlEC2IJRlETnNSt3__19enable_ifIXsr4impl27value_variadic_ctor_allowedIS2_Dpu11__remove_cvIu20__remove_reference_tIT_EEEE5valueEiE4typeELi0EEEDpOS7_ Line | Count | Source | 274 | 4.93k | : val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)) | 275 | 4.93k | { | 276 | | #if TOML_LIFETIME_HOOKS | 277 | | TOML_VALUE_CREATED; | 278 | | #endif | 279 | 4.93k | } |
_ZN4toml2v35valueIlEC2IJxETnNSt3__19enable_ifIXsr4impl27value_variadic_ctor_allowedIS2_Dpu11__remove_cvIu20__remove_reference_tIT_EEEE5valueEiE4typeELi0EEEDpOS6_ Line | Count | Source | 274 | 1.67k | : val_(impl::native_value_maker<value_type, std::decay_t<Args>...>::make(static_cast<Args&&>(args)...)) | 275 | 1.67k | { | 276 | | #if TOML_LIFETIME_HOOKS | 277 | | TOML_VALUE_CREATED; | 278 | | #endif | 279 | 1.67k | } |
|
280 | | |
281 | | /// \brief Copy constructor. |
282 | | TOML_NODISCARD_CTOR |
283 | | value(const value& other) noexcept // |
284 | | : node(other), |
285 | | val_{ other.val_ }, |
286 | | flags_{ other.flags_ } |
287 | | { |
288 | | #if TOML_LIFETIME_HOOKS |
289 | | TOML_VALUE_CREATED; |
290 | | #endif |
291 | | } |
292 | | |
293 | | /// \brief Copy constructor with flags override. |
294 | | TOML_NODISCARD_CTOR |
295 | | value(const value& other, value_flags flags) noexcept // |
296 | | : node(other), |
297 | | val_{ other.val_ }, |
298 | | flags_{ flags == preserve_source_value_flags ? other.flags_ : flags } |
299 | | { |
300 | | #if TOML_LIFETIME_HOOKS |
301 | | TOML_VALUE_CREATED; |
302 | | #endif |
303 | | } |
304 | | |
305 | | /// \brief Move constructor. |
306 | | TOML_NODISCARD_CTOR |
307 | | value(value&& other) noexcept // |
308 | | : node(std::move(other)), |
309 | | val_{ std::move(other.val_) }, |
310 | | flags_{ std::exchange(other.flags_, value_flags{}) } |
311 | | { |
312 | | #if TOML_LIFETIME_HOOKS |
313 | | TOML_VALUE_CREATED; |
314 | | #endif |
315 | | } |
316 | | |
317 | | /// \brief Move constructor with flags override. |
318 | | TOML_NODISCARD_CTOR |
319 | | value(value&& other, value_flags flags) noexcept // |
320 | | : node(std::move(other)), |
321 | | val_{ std::move(other.val_) }, |
322 | | flags_{ flags == preserve_source_value_flags ? other.flags_ : flags } |
323 | | { |
324 | | #if TOML_LIFETIME_HOOKS |
325 | | TOML_VALUE_CREATED; |
326 | | #endif |
327 | | other.flags_ = {}; |
328 | | } |
329 | | |
330 | | /// \brief Copy-assignment operator. |
331 | | value& operator=(const value& rhs) noexcept |
332 | | { |
333 | | node::operator=(rhs); |
334 | | val_ = rhs.val_; |
335 | | flags_ = rhs.flags_; |
336 | | return *this; |
337 | | } |
338 | | |
339 | | /// \brief Move-assignment operator. |
340 | | value& operator=(value&& rhs) noexcept |
341 | | { |
342 | | if (&rhs != this) |
343 | | { |
344 | | node::operator=(std::move(rhs)); |
345 | | val_ = std::move(rhs.val_); |
346 | | flags_ = std::exchange(rhs.flags_, value_flags{}); |
347 | | } |
348 | | return *this; |
349 | | } |
350 | | |
351 | | #if TOML_LIFETIME_HOOKS |
352 | | ~value() noexcept |
353 | | { |
354 | | TOML_VALUE_DESTROYED; |
355 | | } |
356 | | #endif |
357 | | |
358 | | /// \name Type checks |
359 | | /// @{ |
360 | | |
361 | | /// \brief Returns the value's node type identifier. |
362 | | /// |
363 | | /// \returns One of: |
364 | | /// - node_type::string |
365 | | /// - node_type::integer |
366 | | /// - node_type::floating_point |
367 | | /// - node_type::boolean |
368 | | /// - node_type::date |
369 | | /// - node_type::time |
370 | | /// - node_type::date_time |
371 | | TOML_CONST_INLINE_GETTER |
372 | | node_type type() const noexcept final |
373 | 465k | { |
374 | 465k | return impl::node_type_of<value_type>; |
375 | 465k | } toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::type() const Line | Count | Source | 373 | 7.86k | { | 374 | 7.86k | return impl::node_type_of<value_type>; | 375 | 7.86k | } |
toml::v3::value<bool>::type() const Line | Count | Source | 373 | 604 | { | 374 | 604 | return impl::node_type_of<value_type>; | 375 | 604 | } |
toml::v3::value<long>::type() const Line | Count | Source | 373 | 444k | { | 374 | 444k | return impl::node_type_of<value_type>; | 375 | 444k | } |
toml::v3::value<double>::type() const Line | Count | Source | 373 | 5.61k | { | 374 | 5.61k | return impl::node_type_of<value_type>; | 375 | 5.61k | } |
toml::v3::value<toml::v3::time>::type() const Line | Count | Source | 373 | 1.49k | { | 374 | 1.49k | return impl::node_type_of<value_type>; | 375 | 1.49k | } |
toml::v3::value<toml::v3::date>::type() const Line | Count | Source | 373 | 2.09k | { | 374 | 2.09k | return impl::node_type_of<value_type>; | 375 | 2.09k | } |
toml::v3::value<toml::v3::stdopt::date_time>::type() const Line | Count | Source | 373 | 3.03k | { | 374 | 3.03k | return impl::node_type_of<value_type>; | 375 | 3.03k | } |
|
376 | | |
377 | | TOML_PURE_GETTER |
378 | | bool is_homogeneous(node_type ntype) const noexcept final |
379 | 0 | { |
380 | 0 | return ntype == node_type::none || ntype == impl::node_type_of<value_type>; |
381 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_homogeneous(toml::v3::node_type) const Unexecuted instantiation: toml::v3::value<bool>::is_homogeneous(toml::v3::node_type) const Unexecuted instantiation: toml::v3::value<long>::is_homogeneous(toml::v3::node_type) const Unexecuted instantiation: toml::v3::value<double>::is_homogeneous(toml::v3::node_type) const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_homogeneous(toml::v3::node_type) const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_homogeneous(toml::v3::node_type) const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_homogeneous(toml::v3::node_type) const |
382 | | |
383 | | TOML_NODISCARD |
384 | | bool is_homogeneous(node_type ntype, node*& first_nonmatch) noexcept final |
385 | 0 | { |
386 | 0 | if (ntype != node_type::none && ntype != impl::node_type_of<value_type>) |
387 | 0 | { |
388 | 0 | first_nonmatch = this; |
389 | 0 | return false; |
390 | 0 | } |
391 | 0 | return true; |
392 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_homogeneous(toml::v3::node_type, toml::v3::node*&) Unexecuted instantiation: toml::v3::value<bool>::is_homogeneous(toml::v3::node_type, toml::v3::node*&) Unexecuted instantiation: toml::v3::value<long>::is_homogeneous(toml::v3::node_type, toml::v3::node*&) Unexecuted instantiation: toml::v3::value<double>::is_homogeneous(toml::v3::node_type, toml::v3::node*&) Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_homogeneous(toml::v3::node_type, toml::v3::node*&) Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_homogeneous(toml::v3::node_type, toml::v3::node*&) Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_homogeneous(toml::v3::node_type, toml::v3::node*&) |
393 | | |
394 | | TOML_NODISCARD |
395 | | bool is_homogeneous(node_type ntype, const node*& first_nonmatch) const noexcept final |
396 | 0 | { |
397 | 0 | if (ntype != node_type::none && ntype != impl::node_type_of<value_type>) |
398 | 0 | { |
399 | 0 | first_nonmatch = this; |
400 | 0 | return false; |
401 | 0 | } |
402 | 0 | return true; |
403 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_homogeneous(toml::v3::node_type, toml::v3::node const*&) const Unexecuted instantiation: toml::v3::value<bool>::is_homogeneous(toml::v3::node_type, toml::v3::node const*&) const Unexecuted instantiation: toml::v3::value<long>::is_homogeneous(toml::v3::node_type, toml::v3::node const*&) const Unexecuted instantiation: toml::v3::value<double>::is_homogeneous(toml::v3::node_type, toml::v3::node const*&) const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_homogeneous(toml::v3::node_type, toml::v3::node const*&) const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_homogeneous(toml::v3::node_type, toml::v3::node const*&) const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_homogeneous(toml::v3::node_type, toml::v3::node const*&) const |
404 | | |
405 | | /// \cond |
406 | | template <typename ElemType = void> |
407 | | TOML_PURE_GETTER |
408 | | bool is_homogeneous() const noexcept |
409 | | { |
410 | | using type = impl::remove_cvref<impl::unwrap_node<ElemType>>; |
411 | | static_assert(std::is_void_v<type> || toml::is_value<type> || toml::is_container<type>, |
412 | | "The template type argument of value::is_homogeneous() must be void or one " |
413 | | "of:" TOML_SA_UNWRAPPED_NODE_TYPE_LIST); |
414 | | |
415 | | if constexpr (std::is_void_v<type>) |
416 | | return true; |
417 | | else |
418 | | return impl::node_type_of<type> == impl::node_type_of<value_type>; |
419 | | } |
420 | | /// \endcond |
421 | | |
422 | | /// \brief Returns `false`. |
423 | | TOML_CONST_INLINE_GETTER |
424 | | bool is_table() const noexcept final |
425 | 5 | { |
426 | 5 | return false; |
427 | 5 | } toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_table() const Line | Count | Source | 425 | 1 | { | 426 | 1 | return false; | 427 | 1 | } |
toml::v3::value<bool>::is_table() const Line | Count | Source | 425 | 1 | { | 426 | 1 | return false; | 427 | 1 | } |
toml::v3::value<long>::is_table() const Line | Count | Source | 425 | 1 | { | 426 | 1 | return false; | 427 | 1 | } |
Unexecuted instantiation: toml::v3::value<double>::is_table() const toml::v3::value<toml::v3::time>::is_table() const Line | Count | Source | 425 | 1 | { | 426 | 1 | return false; | 427 | 1 | } |
toml::v3::value<toml::v3::date>::is_table() const Line | Count | Source | 425 | 1 | { | 426 | 1 | return false; | 427 | 1 | } |
Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_table() const |
428 | | |
429 | | /// \brief Returns `false`. |
430 | | TOML_CONST_INLINE_GETTER |
431 | | bool is_array() const noexcept final |
432 | 0 | { |
433 | 0 | return false; |
434 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_array() const Unexecuted instantiation: toml::v3::value<bool>::is_array() const Unexecuted instantiation: toml::v3::value<long>::is_array() const Unexecuted instantiation: toml::v3::value<double>::is_array() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_array() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_array() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_array() const |
435 | | |
436 | | /// \brief Returns `false`. |
437 | | TOML_CONST_INLINE_GETTER |
438 | | bool is_array_of_tables() const noexcept final |
439 | 5 | { |
440 | 5 | return false; |
441 | 5 | } toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_array_of_tables() const Line | Count | Source | 439 | 1 | { | 440 | 1 | return false; | 441 | 1 | } |
toml::v3::value<bool>::is_array_of_tables() const Line | Count | Source | 439 | 1 | { | 440 | 1 | return false; | 441 | 1 | } |
toml::v3::value<long>::is_array_of_tables() const Line | Count | Source | 439 | 1 | { | 440 | 1 | return false; | 441 | 1 | } |
Unexecuted instantiation: toml::v3::value<double>::is_array_of_tables() const toml::v3::value<toml::v3::time>::is_array_of_tables() const Line | Count | Source | 439 | 1 | { | 440 | 1 | return false; | 441 | 1 | } |
toml::v3::value<toml::v3::date>::is_array_of_tables() const Line | Count | Source | 439 | 1 | { | 440 | 1 | return false; | 441 | 1 | } |
Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_array_of_tables() const |
442 | | |
443 | | /// \brief Returns `true`. |
444 | | TOML_CONST_INLINE_GETTER |
445 | | bool is_value() const noexcept final |
446 | 0 | { |
447 | 0 | return true; |
448 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_value() const Unexecuted instantiation: toml::v3::value<bool>::is_value() const Unexecuted instantiation: toml::v3::value<long>::is_value() const Unexecuted instantiation: toml::v3::value<double>::is_value() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_value() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_value() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_value() const |
449 | | |
450 | | /// \brief Returns `true` if the #value_type is std::string. |
451 | | TOML_CONST_INLINE_GETTER |
452 | | bool is_string() const noexcept final |
453 | 0 | { |
454 | 0 | return std::is_same_v<value_type, std::string>; |
455 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_string() const Unexecuted instantiation: toml::v3::value<bool>::is_string() const Unexecuted instantiation: toml::v3::value<long>::is_string() const Unexecuted instantiation: toml::v3::value<double>::is_string() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_string() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_string() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_string() const |
456 | | |
457 | | /// \brief Returns `true` if the #value_type is int64_t. |
458 | | TOML_CONST_INLINE_GETTER |
459 | | bool is_integer() const noexcept final |
460 | 0 | { |
461 | 0 | return std::is_same_v<value_type, int64_t>; |
462 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_integer() const Unexecuted instantiation: toml::v3::value<bool>::is_integer() const Unexecuted instantiation: toml::v3::value<long>::is_integer() const Unexecuted instantiation: toml::v3::value<double>::is_integer() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_integer() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_integer() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_integer() const |
463 | | |
464 | | /// \brief Returns `true` if the #value_type is `double`. |
465 | | TOML_CONST_INLINE_GETTER |
466 | | bool is_floating_point() const noexcept final |
467 | 0 | { |
468 | 0 | return std::is_same_v<value_type, double>; |
469 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_floating_point() const Unexecuted instantiation: toml::v3::value<bool>::is_floating_point() const Unexecuted instantiation: toml::v3::value<long>::is_floating_point() const Unexecuted instantiation: toml::v3::value<double>::is_floating_point() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_floating_point() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_floating_point() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_floating_point() const |
470 | | |
471 | | /// \brief Returns `true` if the #value_type is int64_t or `double`. |
472 | | TOML_CONST_INLINE_GETTER |
473 | | bool is_number() const noexcept final |
474 | 0 | { |
475 | 0 | return impl::is_one_of<value_type, int64_t, double>; |
476 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_number() const Unexecuted instantiation: toml::v3::value<bool>::is_number() const Unexecuted instantiation: toml::v3::value<long>::is_number() const Unexecuted instantiation: toml::v3::value<double>::is_number() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_number() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_number() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_number() const |
477 | | |
478 | | /// \brief Returns `true` if the #value_type is `bool`. |
479 | | TOML_CONST_INLINE_GETTER |
480 | | bool is_boolean() const noexcept final |
481 | 0 | { |
482 | 0 | return std::is_same_v<value_type, bool>; |
483 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_boolean() const Unexecuted instantiation: toml::v3::value<bool>::is_boolean() const Unexecuted instantiation: toml::v3::value<long>::is_boolean() const Unexecuted instantiation: toml::v3::value<double>::is_boolean() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_boolean() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_boolean() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_boolean() const |
484 | | |
485 | | /// \brief Returns `true` if the #value_type is toml::date. |
486 | | TOML_CONST_INLINE_GETTER |
487 | | bool is_date() const noexcept final |
488 | 0 | { |
489 | 0 | return std::is_same_v<value_type, date>; |
490 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_date() const Unexecuted instantiation: toml::v3::value<bool>::is_date() const Unexecuted instantiation: toml::v3::value<long>::is_date() const Unexecuted instantiation: toml::v3::value<double>::is_date() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_date() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_date() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_date() const |
491 | | |
492 | | /// \brief Returns `true` if the #value_type is toml::time. |
493 | | TOML_CONST_INLINE_GETTER |
494 | | bool is_time() const noexcept final |
495 | 0 | { |
496 | 0 | return std::is_same_v<value_type, time>; |
497 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_time() const Unexecuted instantiation: toml::v3::value<bool>::is_time() const Unexecuted instantiation: toml::v3::value<long>::is_time() const Unexecuted instantiation: toml::v3::value<double>::is_time() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_time() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_time() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_time() const |
498 | | |
499 | | /// \brief Returns `true` if the #value_type is toml_date_time. |
500 | | TOML_CONST_INLINE_GETTER |
501 | | bool is_date_time() const noexcept final |
502 | 0 | { |
503 | 0 | return std::is_same_v<value_type, date_time>; |
504 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::is_date_time() const Unexecuted instantiation: toml::v3::value<bool>::is_date_time() const Unexecuted instantiation: toml::v3::value<long>::is_date_time() const Unexecuted instantiation: toml::v3::value<double>::is_date_time() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::is_date_time() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::is_date_time() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::is_date_time() const |
505 | | |
506 | | /// @} |
507 | | |
508 | | /// \name Type casts |
509 | | /// @{ |
510 | | |
511 | | /// \brief Returns `nullptr`. |
512 | | TOML_CONST_INLINE_GETTER |
513 | | table* as_table() noexcept final |
514 | 21 | { |
515 | 21 | return nullptr; |
516 | 21 | } toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_table() Line | Count | Source | 514 | 2 | { | 515 | 2 | return nullptr; | 516 | 2 | } |
toml::v3::value<bool>::as_table() Line | Count | Source | 514 | 4 | { | 515 | 4 | return nullptr; | 516 | 4 | } |
toml::v3::value<long>::as_table() Line | Count | Source | 514 | 6 | { | 515 | 6 | return nullptr; | 516 | 6 | } |
toml::v3::value<double>::as_table() Line | Count | Source | 514 | 1 | { | 515 | 1 | return nullptr; | 516 | 1 | } |
toml::v3::value<toml::v3::time>::as_table() Line | Count | Source | 514 | 2 | { | 515 | 2 | return nullptr; | 516 | 2 | } |
toml::v3::value<toml::v3::date>::as_table() Line | Count | Source | 514 | 3 | { | 515 | 3 | return nullptr; | 516 | 3 | } |
toml::v3::value<toml::v3::stdopt::date_time>::as_table() Line | Count | Source | 514 | 3 | { | 515 | 3 | return nullptr; | 516 | 3 | } |
|
517 | | |
518 | | /// \brief Returns `nullptr`. |
519 | | TOML_CONST_INLINE_GETTER |
520 | | array* as_array() noexcept final |
521 | 15 | { |
522 | 15 | return nullptr; |
523 | 15 | } toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_array() Line | Count | Source | 521 | 1 | { | 522 | 1 | return nullptr; | 523 | 1 | } |
toml::v3::value<bool>::as_array() Line | Count | Source | 521 | 4 | { | 522 | 4 | return nullptr; | 523 | 4 | } |
toml::v3::value<long>::as_array() Line | Count | Source | 521 | 3 | { | 522 | 3 | return nullptr; | 523 | 3 | } |
toml::v3::value<double>::as_array() Line | Count | Source | 521 | 1 | { | 522 | 1 | return nullptr; | 523 | 1 | } |
toml::v3::value<toml::v3::time>::as_array() Line | Count | Source | 521 | 2 | { | 522 | 2 | return nullptr; | 523 | 2 | } |
toml::v3::value<toml::v3::date>::as_array() Line | Count | Source | 521 | 2 | { | 522 | 2 | return nullptr; | 523 | 2 | } |
toml::v3::value<toml::v3::stdopt::date_time>::as_array() Line | Count | Source | 521 | 2 | { | 522 | 2 | return nullptr; | 523 | 2 | } |
|
524 | | |
525 | | /// \brief Returns a pointer to the value if it is a value<std::string>, otherwise `nullptr`. |
526 | | TOML_CONST_INLINE_GETTER |
527 | | value<std::string>* as_string() noexcept final |
528 | 0 | { |
529 | 0 | return as_value<std::string>(this); |
530 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_string() Unexecuted instantiation: toml::v3::value<bool>::as_string() Unexecuted instantiation: toml::v3::value<long>::as_string() Unexecuted instantiation: toml::v3::value<double>::as_string() Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_string() Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_string() Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_string() |
531 | | |
532 | | /// \brief Returns a pointer to the value if it is a value<int64_t>, otherwise `nullptr`. |
533 | | TOML_CONST_INLINE_GETTER |
534 | | value<int64_t>* as_integer() noexcept final |
535 | 0 | { |
536 | 0 | return as_value<int64_t>(this); |
537 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_integer() Unexecuted instantiation: toml::v3::value<bool>::as_integer() Unexecuted instantiation: toml::v3::value<long>::as_integer() Unexecuted instantiation: toml::v3::value<double>::as_integer() Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_integer() Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_integer() Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_integer() |
538 | | |
539 | | /// \brief Returns a pointer to the value if it is a value<double>, otherwise `nullptr`. |
540 | | TOML_CONST_INLINE_GETTER |
541 | | value<double>* as_floating_point() noexcept final |
542 | 0 | { |
543 | 0 | return as_value<double>(this); |
544 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_floating_point() Unexecuted instantiation: toml::v3::value<bool>::as_floating_point() Unexecuted instantiation: toml::v3::value<long>::as_floating_point() Unexecuted instantiation: toml::v3::value<double>::as_floating_point() Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_floating_point() Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_floating_point() Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_floating_point() |
545 | | |
546 | | /// \brief Returns a pointer to the value if it is a value<bool>, otherwise `nullptr`. |
547 | | TOML_CONST_INLINE_GETTER |
548 | | value<bool>* as_boolean() noexcept final |
549 | 0 | { |
550 | 0 | return as_value<bool>(this); |
551 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_boolean() Unexecuted instantiation: toml::v3::value<bool>::as_boolean() Unexecuted instantiation: toml::v3::value<long>::as_boolean() Unexecuted instantiation: toml::v3::value<double>::as_boolean() Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_boolean() Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_boolean() Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_boolean() |
552 | | |
553 | | /// \brief Returns a pointer to the value if it is a value<date>, otherwise `nullptr`. |
554 | | TOML_CONST_INLINE_GETTER |
555 | | value<date>* as_date() noexcept final |
556 | 0 | { |
557 | 0 | return as_value<date>(this); |
558 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_date() Unexecuted instantiation: toml::v3::value<bool>::as_date() Unexecuted instantiation: toml::v3::value<long>::as_date() Unexecuted instantiation: toml::v3::value<double>::as_date() Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_date() Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_date() Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_date() |
559 | | |
560 | | /// \brief Returns a pointer to the value if it is a value<time>, otherwise `nullptr`. |
561 | | TOML_CONST_INLINE_GETTER |
562 | | value<time>* as_time() noexcept final |
563 | 0 | { |
564 | 0 | return as_value<time>(this); |
565 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_time() Unexecuted instantiation: toml::v3::value<bool>::as_time() Unexecuted instantiation: toml::v3::value<long>::as_time() Unexecuted instantiation: toml::v3::value<double>::as_time() Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_time() Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_time() Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_time() |
566 | | |
567 | | /// \brief Returns a pointer to the value if it is a value<date_time>, otherwise `nullptr`. |
568 | | TOML_CONST_INLINE_GETTER |
569 | | value<date_time>* as_date_time() noexcept final |
570 | 0 | { |
571 | 0 | return as_value<date_time>(this); |
572 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_date_time() Unexecuted instantiation: toml::v3::value<bool>::as_date_time() Unexecuted instantiation: toml::v3::value<long>::as_date_time() Unexecuted instantiation: toml::v3::value<double>::as_date_time() Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_date_time() Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_date_time() Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_date_time() |
573 | | |
574 | | /// \brief Returns `nullptr`. |
575 | | TOML_CONST_INLINE_GETTER |
576 | | const table* as_table() const noexcept final |
577 | 0 | { |
578 | 0 | return nullptr; |
579 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_table() const Unexecuted instantiation: toml::v3::value<bool>::as_table() const Unexecuted instantiation: toml::v3::value<long>::as_table() const Unexecuted instantiation: toml::v3::value<double>::as_table() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_table() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_table() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_table() const |
580 | | |
581 | | /// \brief Returns `nullptr`. |
582 | | TOML_CONST_INLINE_GETTER |
583 | | const array* as_array() const noexcept final |
584 | 0 | { |
585 | 0 | return nullptr; |
586 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_array() const Unexecuted instantiation: toml::v3::value<bool>::as_array() const Unexecuted instantiation: toml::v3::value<long>::as_array() const Unexecuted instantiation: toml::v3::value<double>::as_array() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_array() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_array() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_array() const |
587 | | |
588 | | /// \brief Returns a const-qualified pointer to the value if it is a value<std::string>, otherwise `nullptr`. |
589 | | TOML_CONST_INLINE_GETTER |
590 | | const value<std::string>* as_string() const noexcept final |
591 | 0 | { |
592 | 0 | return as_value<std::string>(this); |
593 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_string() const Unexecuted instantiation: toml::v3::value<bool>::as_string() const Unexecuted instantiation: toml::v3::value<long>::as_string() const Unexecuted instantiation: toml::v3::value<double>::as_string() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_string() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_string() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_string() const |
594 | | |
595 | | /// \brief Returns a const-qualified pointer to the value if it is a value<int64_t>, otherwise `nullptr`. |
596 | | TOML_CONST_INLINE_GETTER |
597 | | const value<int64_t>* as_integer() const noexcept final |
598 | 0 | { |
599 | 0 | return as_value<int64_t>(this); |
600 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_integer() const Unexecuted instantiation: toml::v3::value<bool>::as_integer() const Unexecuted instantiation: toml::v3::value<long>::as_integer() const Unexecuted instantiation: toml::v3::value<double>::as_integer() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_integer() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_integer() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_integer() const |
601 | | |
602 | | /// \brief Returns a const-qualified pointer to the value if it is a value<double>, otherwise `nullptr`. |
603 | | TOML_CONST_INLINE_GETTER |
604 | | const value<double>* as_floating_point() const noexcept final |
605 | 0 | { |
606 | 0 | return as_value<double>(this); |
607 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_floating_point() const Unexecuted instantiation: toml::v3::value<bool>::as_floating_point() const Unexecuted instantiation: toml::v3::value<long>::as_floating_point() const Unexecuted instantiation: toml::v3::value<double>::as_floating_point() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_floating_point() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_floating_point() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_floating_point() const |
608 | | |
609 | | /// \brief Returns a const-qualified pointer to the value if it is a value<bool>, otherwise `nullptr`. |
610 | | TOML_CONST_INLINE_GETTER |
611 | | const value<bool>* as_boolean() const noexcept final |
612 | 0 | { |
613 | 0 | return as_value<bool>(this); |
614 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_boolean() const Unexecuted instantiation: toml::v3::value<bool>::as_boolean() const Unexecuted instantiation: toml::v3::value<long>::as_boolean() const Unexecuted instantiation: toml::v3::value<double>::as_boolean() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_boolean() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_boolean() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_boolean() const |
615 | | |
616 | | /// \brief Returns a const-qualified pointer to the value if it is a value<date>, otherwise `nullptr`. |
617 | | TOML_CONST_INLINE_GETTER |
618 | | const value<date>* as_date() const noexcept final |
619 | 0 | { |
620 | 0 | return as_value<date>(this); |
621 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_date() const Unexecuted instantiation: toml::v3::value<bool>::as_date() const Unexecuted instantiation: toml::v3::value<long>::as_date() const Unexecuted instantiation: toml::v3::value<double>::as_date() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_date() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_date() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_date() const |
622 | | |
623 | | /// \brief Returns a const-qualified pointer to the value if it is a value<time>, otherwise `nullptr`. |
624 | | TOML_CONST_INLINE_GETTER |
625 | | const value<time>* as_time() const noexcept final |
626 | 0 | { |
627 | 0 | return as_value<time>(this); |
628 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_time() const Unexecuted instantiation: toml::v3::value<bool>::as_time() const Unexecuted instantiation: toml::v3::value<long>::as_time() const Unexecuted instantiation: toml::v3::value<double>::as_time() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_time() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_time() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_time() const |
629 | | |
630 | | /// \brief Returns a const-qualified pointer to the value if it is a value<date_time>, otherwise `nullptr`. |
631 | | TOML_CONST_INLINE_GETTER |
632 | | const value<date_time>* as_date_time() const noexcept final |
633 | 0 | { |
634 | 0 | return as_value<date_time>(this); |
635 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::as_date_time() const Unexecuted instantiation: toml::v3::value<bool>::as_date_time() const Unexecuted instantiation: toml::v3::value<long>::as_date_time() const Unexecuted instantiation: toml::v3::value<double>::as_date_time() const Unexecuted instantiation: toml::v3::value<toml::v3::time>::as_date_time() const Unexecuted instantiation: toml::v3::value<toml::v3::date>::as_date_time() const Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::as_date_time() const |
636 | | |
637 | | /// @} |
638 | | |
639 | | /// \name Value retrieval |
640 | | /// @{ |
641 | | |
642 | | /// \brief Returns a reference to the underlying value. |
643 | | TOML_PURE_INLINE_GETTER |
644 | | value_type& get() & noexcept |
645 | | { |
646 | | return val_; |
647 | | } |
648 | | |
649 | | /// \brief Returns a reference to the underlying value (rvalue overload). |
650 | | TOML_PURE_INLINE_GETTER |
651 | | value_type&& get() && noexcept |
652 | | { |
653 | | return static_cast<value_type&&>(val_); |
654 | | } |
655 | | |
656 | | /// \brief Returns a reference to the underlying value (const overload). |
657 | | TOML_PURE_INLINE_GETTER |
658 | | const value_type& get() const& noexcept |
659 | 0 | { |
660 | 0 | return val_; |
661 | 0 | } Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::get() const & Unexecuted instantiation: toml::v3::value<long>::get() const & Unexecuted instantiation: toml::v3::value<double>::get() const & |
662 | | |
663 | | /// \brief Returns a reference to the underlying value (const rvalue overload). |
664 | | TOML_PURE_INLINE_GETTER |
665 | | const value_type&& get() const&& noexcept |
666 | | { |
667 | | return static_cast<const value_type&&>(val_); |
668 | | } |
669 | | |
670 | | /// \brief Returns a reference to the underlying value. |
671 | | TOML_PURE_INLINE_GETTER |
672 | | value_type& operator*() & noexcept |
673 | | { |
674 | | return val_; |
675 | | } |
676 | | |
677 | | /// \brief Returns a reference to the underlying value (rvalue overload). |
678 | | TOML_PURE_INLINE_GETTER |
679 | | value_type&& operator*() && noexcept |
680 | | { |
681 | | return static_cast<value_type&&>(val_); |
682 | | } |
683 | | |
684 | | /// \brief Returns a reference to the underlying value (const overload). |
685 | | TOML_PURE_INLINE_GETTER |
686 | | const value_type& operator*() const& noexcept |
687 | 0 | { |
688 | 0 | return val_; |
689 | 0 | } Unexecuted instantiation: toml::v3::value<long>::operator*() const & Unexecuted instantiation: toml::v3::value<double>::operator*() const & Unexecuted instantiation: toml::v3::value<bool>::operator*() const & Unexecuted instantiation: toml::v3::value<toml::v3::date>::operator*() const & Unexecuted instantiation: toml::v3::value<toml::v3::time>::operator*() const & Unexecuted instantiation: toml::v3::value<toml::v3::stdopt::date_time>::operator*() const & Unexecuted instantiation: toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::operator*() const & |
690 | | |
691 | | /// \brief Returns a reference to the underlying value (const rvalue overload). |
692 | | TOML_PURE_INLINE_GETTER |
693 | | const value_type&& operator*() const&& noexcept |
694 | | { |
695 | | return static_cast<const value_type&&>(val_); |
696 | | } |
697 | | |
698 | | /// \brief Returns a reference to the underlying value. |
699 | | TOML_PURE_INLINE_GETTER |
700 | | explicit operator value_type&() & noexcept |
701 | | { |
702 | | return val_; |
703 | | } |
704 | | |
705 | | /// \brief Returns a reference to the underlying value (rvalue overload). |
706 | | TOML_PURE_INLINE_GETTER |
707 | | explicit operator value_type&&() && noexcept |
708 | | { |
709 | | return static_cast<value_type&&>(val_); |
710 | | } |
711 | | |
712 | | /// \brief Returns a reference to the underlying value (const overload). |
713 | | TOML_PURE_INLINE_GETTER |
714 | | explicit operator const value_type&() const& noexcept |
715 | | { |
716 | | return val_; |
717 | | } |
718 | | |
719 | | /// \brief Returns a reference to the underlying value (const rvalue overload). |
720 | | TOML_PURE_INLINE_GETTER |
721 | | explicit operator const value_type&&() && noexcept |
722 | | { |
723 | | return static_cast<const value_type&&>(val_); |
724 | | } |
725 | | |
726 | | /// \brief Returns a pointer to the underlying value. |
727 | | /// |
728 | | /// \availability This operator is only available when #value_type is a class/struct. |
729 | | TOML_HIDDEN_CONSTRAINT(std::is_class_v<T>, typename T = value_type) |
730 | | TOML_PURE_INLINE_GETTER |
731 | | value_type* operator->() noexcept |
732 | | { |
733 | | return &val_; |
734 | | } |
735 | | |
736 | | /// \brief Returns a pointer to the underlying value (const overload). |
737 | | /// |
738 | | /// \availability This operator is only available when #value_type is a class/struct. |
739 | | TOML_HIDDEN_CONSTRAINT(std::is_class_v<T>, typename T = value_type) |
740 | | TOML_PURE_INLINE_GETTER |
741 | | const value_type* operator->() const noexcept |
742 | 0 | { |
743 | 0 | return &val_; |
744 | 0 | } |
745 | | |
746 | | /// @} |
747 | | |
748 | | /// \name Metadata |
749 | | /// @{ |
750 | | |
751 | | /// \brief Returns the metadata flags associated with this value. |
752 | | TOML_NODISCARD |
753 | | value_flags flags() const noexcept |
754 | 0 | { |
755 | 0 | return flags_; |
756 | 0 | } |
757 | | |
758 | | /// \brief Sets the metadata flags associated with this value. |
759 | | /// \returns A reference to the value object. |
760 | | value& flags(value_flags new_flags) noexcept |
761 | 4.93k | { |
762 | 4.93k | flags_ = new_flags; |
763 | 4.93k | return *this; |
764 | 4.93k | } |
765 | | |
766 | | /// @} |
767 | | |
768 | | /// \brief Value-assignment operator. |
769 | | value& operator=(value_arg rhs) noexcept |
770 | | { |
771 | | if constexpr (std::is_same_v<value_type, std::string>) |
772 | | val_.assign(rhs); |
773 | | else |
774 | | val_ = rhs; |
775 | | return *this; |
776 | | } |
777 | | |
778 | | TOML_CONSTRAINED_TEMPLATE((std::is_same_v<T, std::string>), typename T = value_type) |
779 | | value& operator=(std::string&& rhs) noexcept |
780 | | { |
781 | | val_ = std::move(rhs); |
782 | | return *this; |
783 | | } |
784 | | |
785 | | /// \name Equality and Comparison |
786 | | /// @{ |
787 | | |
788 | | /// \brief Value equality operator. |
789 | | TOML_PURE_GETTER |
790 | | friend bool operator==(const value& lhs, value_arg rhs) noexcept |
791 | 0 | { |
792 | 0 | if constexpr (std::is_same_v<value_type, double>) |
793 | 0 | { |
794 | 0 | const auto lhs_nan = impl::fpclassify(lhs.val_) == impl::fp_class::nan; |
795 | 0 | const auto rhs_nan = impl::fpclassify(rhs) == impl::fp_class::nan; |
796 | 0 | if (lhs_nan != rhs_nan) |
797 | 0 | return false; |
798 | 0 | if (lhs_nan) |
799 | 0 | return true; |
800 | 0 | } |
801 | 0 | return lhs.val_ == rhs; |
802 | 0 | } Unexecuted instantiation: toml::v3::operator==(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const&, std::__1::basic_string_view<char, std::__1::char_traits<char> >) Unexecuted instantiation: toml::v3::operator==(toml::v3::value<long> const&, long) Unexecuted instantiation: toml::v3::operator==(toml::v3::value<double> const&, double) Unexecuted instantiation: toml::v3::operator==(toml::v3::value<bool> const&, bool) Unexecuted instantiation: toml::v3::operator==(toml::v3::value<toml::v3::date> const&, toml::v3::date const&) Unexecuted instantiation: toml::v3::operator==(toml::v3::value<toml::v3::time> const&, toml::v3::time const&) Unexecuted instantiation: toml::v3::operator==(toml::v3::value<toml::v3::stdopt::date_time> const&, toml::v3::stdopt::date_time const&) |
803 | | TOML_ASYMMETRICAL_EQUALITY_OPS(const value&, value_arg, ); |
804 | | |
805 | | /// \brief Value less-than operator. |
806 | | TOML_PURE_GETTER |
807 | | friend bool operator<(const value& lhs, value_arg rhs) noexcept |
808 | | { |
809 | | return lhs.val_ < rhs; |
810 | | } |
811 | | |
812 | | /// \brief Value less-than operator. |
813 | | TOML_PURE_GETTER |
814 | | friend bool operator<(value_arg lhs, const value& rhs) noexcept |
815 | | { |
816 | | return lhs < rhs.val_; |
817 | | } |
818 | | |
819 | | /// \brief Value less-than-or-equal-to operator. |
820 | | TOML_PURE_GETTER |
821 | | friend bool operator<=(const value& lhs, value_arg rhs) noexcept |
822 | | { |
823 | | return lhs.val_ <= rhs; |
824 | | } |
825 | | |
826 | | /// \brief Value less-than-or-equal-to operator. |
827 | | TOML_PURE_GETTER |
828 | | friend bool operator<=(value_arg lhs, const value& rhs) noexcept |
829 | | { |
830 | | return lhs <= rhs.val_; |
831 | | } |
832 | | |
833 | | /// \brief Value greater-than operator. |
834 | | TOML_PURE_GETTER |
835 | | friend bool operator>(const value& lhs, value_arg rhs) noexcept |
836 | | { |
837 | | return lhs.val_ > rhs; |
838 | | } |
839 | | |
840 | | /// \brief Value greater-than operator. |
841 | | TOML_PURE_GETTER |
842 | | friend bool operator>(value_arg lhs, const value& rhs) noexcept |
843 | | { |
844 | | return lhs > rhs.val_; |
845 | | } |
846 | | |
847 | | /// \brief Value greater-than-or-equal-to operator. |
848 | | TOML_PURE_GETTER |
849 | | friend bool operator>=(const value& lhs, value_arg rhs) noexcept |
850 | | { |
851 | | return lhs.val_ >= rhs; |
852 | | } |
853 | | |
854 | | /// \brief Value greater-than-or-equal-to operator. |
855 | | TOML_PURE_GETTER |
856 | | friend bool operator>=(value_arg lhs, const value& rhs) noexcept |
857 | | { |
858 | | return lhs >= rhs.val_; |
859 | | } |
860 | | |
861 | | /// \brief Equality operator. |
862 | | /// |
863 | | /// \param lhs The LHS value. |
864 | | /// \param rhs The RHS value. |
865 | | /// |
866 | | /// \returns True if the values were of the same type and contained the same value. |
867 | | template <typename T> |
868 | | TOML_PURE_GETTER |
869 | | friend bool operator==(const value& lhs, const value<T>& rhs) noexcept |
870 | 0 | { |
871 | 0 | if constexpr (std::is_same_v<value_type, T>) |
872 | 0 | return lhs == rhs.val_; // calls asymmetrical value-equality operator defined above |
873 | 0 | else |
874 | 0 | return false; |
875 | 0 | } Unexecuted instantiation: bool toml::v3::operator==<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const&, toml::v3::value<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const&) Unexecuted instantiation: bool toml::v3::operator==<long>(toml::v3::value<long> const&, toml::v3::value<long> const&) Unexecuted instantiation: bool toml::v3::operator==<double>(toml::v3::value<double> const&, toml::v3::value<double> const&) Unexecuted instantiation: bool toml::v3::operator==<bool>(toml::v3::value<bool> const&, toml::v3::value<bool> const&) Unexecuted instantiation: bool toml::v3::operator==<toml::v3::date>(toml::v3::value<toml::v3::date> const&, toml::v3::value<toml::v3::date> const&) Unexecuted instantiation: bool toml::v3::operator==<toml::v3::time>(toml::v3::value<toml::v3::time> const&, toml::v3::value<toml::v3::time> const&) Unexecuted instantiation: bool toml::v3::operator==<toml::v3::stdopt::date_time>(toml::v3::value<toml::v3::stdopt::date_time> const&, toml::v3::value<toml::v3::stdopt::date_time> const&) |
876 | | |
877 | | /// \brief Inequality operator. |
878 | | /// |
879 | | /// \param lhs The LHS value. |
880 | | /// \param rhs The RHS value. |
881 | | /// |
882 | | /// \returns True if the values were not of the same type, or did not contain the same value. |
883 | | template <typename T> |
884 | | TOML_PURE_INLINE_GETTER |
885 | | friend bool operator!=(const value& lhs, const value<T>& rhs) noexcept |
886 | | { |
887 | | return !(lhs == rhs); |
888 | | } |
889 | | |
890 | | /// \brief Less-than operator. |
891 | | /// |
892 | | /// \param lhs The LHS toml::value. |
893 | | /// \param rhs The RHS toml::value. |
894 | | /// |
895 | | /// \returns \conditional_return{Same value types} |
896 | | /// `lhs.get() < rhs.get()` |
897 | | /// \conditional_return{Different value types} |
898 | | /// `lhs.type() < rhs.type()` |
899 | | template <typename T> |
900 | | TOML_PURE_GETTER |
901 | | friend bool operator<(const value& lhs, const value<T>& rhs) noexcept |
902 | | { |
903 | | if constexpr (std::is_same_v<value_type, T>) |
904 | | return lhs.val_ < rhs.val_; |
905 | | else |
906 | | return impl::node_type_of<value_type> < impl::node_type_of<T>; |
907 | | } |
908 | | |
909 | | /// \brief Less-than-or-equal-to operator. |
910 | | /// |
911 | | /// \param lhs The LHS toml::value. |
912 | | /// \param rhs The RHS toml::value. |
913 | | /// |
914 | | /// \returns \conditional_return{Same value types} |
915 | | /// `lhs.get() <= rhs.get()` |
916 | | /// \conditional_return{Different value types} |
917 | | /// `lhs.type() <= rhs.type()` |
918 | | template <typename T> |
919 | | TOML_PURE_GETTER |
920 | | friend bool operator<=(const value& lhs, const value<T>& rhs) noexcept |
921 | | { |
922 | | if constexpr (std::is_same_v<value_type, T>) |
923 | | return lhs.val_ <= rhs.val_; |
924 | | else |
925 | | return impl::node_type_of<value_type> <= impl::node_type_of<T>; |
926 | | } |
927 | | |
928 | | /// \brief Greater-than operator. |
929 | | /// |
930 | | /// \param lhs The LHS toml::value. |
931 | | /// \param rhs The RHS toml::value. |
932 | | /// |
933 | | /// \returns \conditional_return{Same value types} |
934 | | /// `lhs.get() > rhs.get()` |
935 | | /// \conditional_return{Different value types} |
936 | | /// `lhs.type() > rhs.type()` |
937 | | template <typename T> |
938 | | TOML_PURE_GETTER |
939 | | friend bool operator>(const value& lhs, const value<T>& rhs) noexcept |
940 | | { |
941 | | if constexpr (std::is_same_v<value_type, T>) |
942 | | return lhs.val_ > rhs.val_; |
943 | | else |
944 | | return impl::node_type_of<value_type> > impl::node_type_of<T>; |
945 | | } |
946 | | |
947 | | /// \brief Greater-than-or-equal-to operator. |
948 | | /// |
949 | | /// \param lhs The LHS toml::value. |
950 | | /// \param rhs The RHS toml::value. |
951 | | /// |
952 | | /// \returns \conditional_return{Same value types} |
953 | | /// `lhs.get() >= rhs.get()` |
954 | | /// \conditional_return{Different value types} |
955 | | /// `lhs.type() >= rhs.type()` |
956 | | template <typename T> |
957 | | TOML_PURE_GETTER |
958 | | friend bool operator>=(const value& lhs, const value<T>& rhs) noexcept |
959 | | { |
960 | | if constexpr (std::is_same_v<value_type, T>) |
961 | | return lhs.val_ >= rhs.val_; |
962 | | else |
963 | | return impl::node_type_of<value_type> >= impl::node_type_of<T>; |
964 | | } |
965 | | |
966 | | /// @} |
967 | | |
968 | | #if TOML_ENABLE_FORMATTERS |
969 | | |
970 | | /// \brief Prints the value out to a stream as formatted TOML. |
971 | | /// |
972 | | /// \availability This operator is only available when #TOML_ENABLE_FORMATTERS is enabled. |
973 | | friend std::ostream& operator<<(std::ostream& lhs, const value& rhs) |
974 | | { |
975 | | impl::print_to_stream(lhs, rhs); |
976 | | return lhs; |
977 | | } |
978 | | |
979 | | #endif |
980 | | }; |
981 | | |
982 | | /// \cond |
983 | | |
984 | | template <typename T> |
985 | | value(T) -> value<impl::native_type_of<impl::remove_cvref<T>>>; |
986 | | template <typename T> |
987 | | value(T, value_flags) -> value<impl::native_type_of<impl::remove_cvref<T>>>; |
988 | | |
989 | | template <typename T> |
990 | | TOML_NODISCARD |
991 | | inline decltype(auto) node::get_value_exact() const noexcept(impl::value_retrieval_is_nothrow<T>) |
992 | | { |
993 | | using namespace impl; |
994 | | |
995 | | static_assert(node_type_of<T> != node_type::none); |
996 | | static_assert(node_type_of<T> != node_type::table); |
997 | | static_assert(node_type_of<T> != node_type::array); |
998 | | static_assert(is_native<T> || can_represent_native<T>); |
999 | | static_assert(!is_cvref<T>); |
1000 | | TOML_ASSERT(this->type() == node_type_of<T>); |
1001 | | |
1002 | | if constexpr (node_type_of<T> == node_type::string) |
1003 | | { |
1004 | | const auto& str = *ref_cast<std::string>(); |
1005 | | if constexpr (std::is_same_v<T, std::string>) |
1006 | | return str; |
1007 | | else if constexpr (std::is_same_v<T, std::string_view>) |
1008 | | return T{ str }; |
1009 | | else if constexpr (std::is_same_v<T, const char*>) |
1010 | | return str.c_str(); |
1011 | | |
1012 | | else if constexpr (std::is_same_v<T, std::wstring>) |
1013 | | { |
1014 | | #if TOML_ENABLE_WINDOWS_COMPAT |
1015 | | return widen(str); |
1016 | | #else |
1017 | | static_assert(always_false<T>, "Evaluated unreachable branch!"); |
1018 | | #endif |
1019 | | } |
1020 | | |
1021 | | #if TOML_HAS_CHAR8 |
1022 | | |
1023 | | // char -> char8_t (potentially unsafe - the feature is 'experimental'!) |
1024 | | else if constexpr (is_one_of<T, std::u8string, std::u8string_view>) |
1025 | | return T(reinterpret_cast<const char8_t*>(str.c_str()), str.length()); |
1026 | | else if constexpr (std::is_same_v<T, const char8_t*>) |
1027 | | return reinterpret_cast<const char8_t*>(str.c_str()); |
1028 | | else |
1029 | | static_assert(always_false<T>, "Evaluated unreachable branch!"); |
1030 | | |
1031 | | #endif |
1032 | | } |
1033 | | else |
1034 | | return static_cast<T>(*ref_cast<native_type_of<T>>()); |
1035 | | } |
1036 | | |
1037 | | template <typename T> |
1038 | | TOML_NODISCARD |
1039 | | inline optional<T> node::value_exact() const noexcept(impl::value_retrieval_is_nothrow<T>) |
1040 | | { |
1041 | | using namespace impl; |
1042 | | |
1043 | | static_assert(!is_wide_string<T> || TOML_ENABLE_WINDOWS_COMPAT, |
1044 | | "Retrieving values as wide-character strings with node::value_exact() is only " |
1045 | | "supported on Windows with TOML_ENABLE_WINDOWS_COMPAT enabled."); |
1046 | | |
1047 | | static_assert((is_native<T> || can_represent_native<T>) && !is_cvref<T>, |
1048 | | TOML_SA_VALUE_EXACT_FUNC_MESSAGE("return type of node::value_exact()")); |
1049 | | |
1050 | | // prevent additional compiler error spam when the static_assert fails by gating behind if constexpr |
1051 | | if constexpr ((is_native<T> || can_represent_native<T>) && !is_cvref<T>) |
1052 | | { |
1053 | | if (type() == node_type_of<T>) |
1054 | | return { this->get_value_exact<T>() }; |
1055 | | else |
1056 | | return {}; |
1057 | | } |
1058 | | } |
1059 | | |
1060 | | template <typename T> |
1061 | | TOML_NODISCARD |
1062 | | inline optional<T> node::value() const noexcept(impl::value_retrieval_is_nothrow<T>) |
1063 | | { |
1064 | | using namespace impl; |
1065 | | |
1066 | | static_assert(!is_wide_string<T> || TOML_ENABLE_WINDOWS_COMPAT, |
1067 | | "Retrieving values as wide-character strings with node::value() is only " |
1068 | | "supported on Windows with TOML_ENABLE_WINDOWS_COMPAT enabled."); |
1069 | | static_assert((is_native<T> || can_represent_native<T> || can_partially_represent_native<T>) && !is_cvref<T>, |
1070 | | TOML_SA_VALUE_FUNC_MESSAGE("return type of node::value()")); |
1071 | | |
1072 | | // when asking for strings, dates, times and date_times there's no 'fuzzy' conversion |
1073 | | // semantics to be mindful of so the exact retrieval is enough. |
1074 | | if constexpr (is_natively_one_of<T, std::string, time, date, date_time>) |
1075 | | { |
1076 | | if (type() == node_type_of<T>) |
1077 | | return { this->get_value_exact<T>() }; |
1078 | | else |
1079 | | return {}; |
1080 | | } |
1081 | | |
1082 | | // everything else requires a bit of logicking. |
1083 | | else |
1084 | | { |
1085 | | switch (type()) |
1086 | | { |
1087 | | // int -> * |
1088 | | case node_type::integer: |
1089 | | { |
1090 | | // int -> int |
1091 | | if constexpr (is_natively_one_of<T, int64_t>) |
1092 | | { |
1093 | | if constexpr (is_native<T> || can_represent_native<T>) |
1094 | | return static_cast<T>(*ref_cast<int64_t>()); |
1095 | | else |
1096 | | return node_integer_cast<T>(*ref_cast<int64_t>()); |
1097 | | } |
1098 | | |
1099 | | // int -> float |
1100 | | else if constexpr (is_natively_one_of<T, double>) |
1101 | | { |
1102 | | const int64_t val = *ref_cast<int64_t>(); |
1103 | | if constexpr (std::numeric_limits<T>::digits < 64) |
1104 | | { |
1105 | | constexpr auto largest_whole_float = (int64_t{ 1 } << std::numeric_limits<T>::digits); |
1106 | | if (val < -largest_whole_float || val > largest_whole_float) |
1107 | | return {}; |
1108 | | } |
1109 | | return static_cast<T>(val); |
1110 | | } |
1111 | | |
1112 | | // int -> bool |
1113 | | else if constexpr (is_natively_one_of<T, bool>) |
1114 | | return static_cast<bool>(*ref_cast<int64_t>()); |
1115 | | |
1116 | | // int -> anything else |
1117 | | else |
1118 | | return {}; |
1119 | | } |
1120 | | |
1121 | | // float -> * |
1122 | | case node_type::floating_point: |
1123 | | { |
1124 | | // float -> float |
1125 | | if constexpr (is_natively_one_of<T, double>) |
1126 | | { |
1127 | | if constexpr (is_native<T> || can_represent_native<T>) |
1128 | | return { static_cast<T>(*ref_cast<double>()) }; |
1129 | | else |
1130 | | { |
1131 | | const double val = *ref_cast<double>(); |
1132 | | if (impl::fpclassify(val) == fp_class::ok |
1133 | | && (val < (std::numeric_limits<T>::lowest)() || val > (std::numeric_limits<T>::max)())) |
1134 | | return {}; |
1135 | | return { static_cast<T>(val) }; |
1136 | | } |
1137 | | } |
1138 | | |
1139 | | // float -> int |
1140 | | else if constexpr (is_natively_one_of<T, int64_t>) |
1141 | | { |
1142 | | const double val = *ref_cast<double>(); |
1143 | | if (impl::fpclassify(val) == fp_class::ok |
1144 | | && static_cast<double>(static_cast<int64_t>(val)) == val) |
1145 | | return node_integer_cast<T>(static_cast<int64_t>(val)); |
1146 | | else |
1147 | | return {}; |
1148 | | } |
1149 | | |
1150 | | // float -> anything else |
1151 | | else |
1152 | | return {}; |
1153 | | } |
1154 | | |
1155 | | // bool -> * |
1156 | | case node_type::boolean: |
1157 | | { |
1158 | | // bool -> bool |
1159 | | if constexpr (is_natively_one_of<T, bool>) |
1160 | | return { *ref_cast<bool>() }; |
1161 | | |
1162 | | // bool -> int |
1163 | | else if constexpr (is_natively_one_of<T, int64_t>) |
1164 | | return { static_cast<T>(*ref_cast<bool>()) }; |
1165 | | |
1166 | | // bool -> anything else |
1167 | | else |
1168 | | return {}; |
1169 | | } |
1170 | | } |
1171 | | |
1172 | | // non-values, or 'exact' types covered above |
1173 | | return {}; |
1174 | | } |
1175 | | } |
1176 | | |
1177 | | template <typename T> |
1178 | | TOML_NODISCARD |
1179 | | inline auto node::value_or(T && default_value) const noexcept(impl::value_retrieval_is_nothrow<T>) |
1180 | | { |
1181 | | using namespace impl; |
1182 | | |
1183 | | static_assert(!is_wide_string<T> || TOML_ENABLE_WINDOWS_COMPAT, |
1184 | | "Retrieving values as wide-character strings with node::value_or() is only " |
1185 | | "supported on Windows with TOML_ENABLE_WINDOWS_COMPAT enabled."); |
1186 | | |
1187 | | if constexpr (is_wide_string<T>) |
1188 | | { |
1189 | | #if TOML_ENABLE_WINDOWS_COMPAT |
1190 | | |
1191 | | if (type() == node_type::string) |
1192 | | return widen(*ref_cast<std::string>()); |
1193 | | return std::wstring{ static_cast<T&&>(default_value) }; |
1194 | | |
1195 | | #else |
1196 | | |
1197 | | static_assert(always_false<T>, "Evaluated unreachable branch!"); |
1198 | | |
1199 | | #endif |
1200 | | } |
1201 | | else |
1202 | | { |
1203 | | using value_type = |
1204 | | std::conditional_t<std::is_pointer_v<std::decay_t<T>>, |
1205 | | std::add_pointer_t<std::add_const_t<std::remove_pointer_t<std::decay_t<T>>>>, |
1206 | | std::decay_t<T>>; |
1207 | | using traits = value_traits<value_type>; |
1208 | | |
1209 | | // clang-format off |
1210 | | |
1211 | | static_assert( |
1212 | | traits::is_native || traits::can_represent_native || traits::can_partially_represent_native, |
1213 | | "The default value type of node::value_or() must be one of:" |
1214 | | TOML_SA_LIST_NEW "A native TOML value type" |
1215 | | TOML_SA_NATIVE_VALUE_TYPE_LIST |
1216 | | |
1217 | | TOML_SA_LIST_NXT "A non-view type capable of losslessly representing a native TOML value type" |
1218 | | TOML_SA_LIST_BEG "std::string" |
1219 | | #if TOML_ENABLE_WINDOWS_COMPAT |
1220 | | TOML_SA_LIST_SEP "std::wstring" |
1221 | | #endif |
1222 | | TOML_SA_LIST_SEP "any signed integer type >= 64 bits" |
1223 | | TOML_SA_LIST_SEP "any floating-point type >= 64 bits" |
1224 | | TOML_SA_LIST_END |
1225 | | |
1226 | | TOML_SA_LIST_NXT "A non-view type capable of (reasonably) representing a native TOML value type" |
1227 | | TOML_SA_LIST_BEG "any other integral type" |
1228 | | TOML_SA_LIST_SEP "any floating-point type" |
1229 | | TOML_SA_LIST_END |
1230 | | |
1231 | | TOML_SA_LIST_NXT "A compatible view type" |
1232 | | TOML_SA_LIST_BEG "std::string_view" |
1233 | | #if TOML_HAS_CHAR8 |
1234 | | TOML_SA_LIST_SEP "std::u8string_view" |
1235 | | #endif |
1236 | | #if TOML_ENABLE_WINDOWS_COMPAT |
1237 | | TOML_SA_LIST_SEP "std::wstring_view" |
1238 | | #endif |
1239 | | TOML_SA_LIST_SEP "const char*" |
1240 | | #if TOML_HAS_CHAR8 |
1241 | | TOML_SA_LIST_SEP "const char8_t*" |
1242 | | #endif |
1243 | | #if TOML_ENABLE_WINDOWS_COMPAT |
1244 | | TOML_SA_LIST_SEP "const wchar_t*" |
1245 | | #endif |
1246 | | TOML_SA_LIST_END |
1247 | | ); |
1248 | | |
1249 | | // clang-format on |
1250 | | |
1251 | | // prevent additional compiler error spam when the static_assert fails by gating behind if constexpr |
1252 | | if constexpr (traits::is_native || traits::can_represent_native || traits::can_partially_represent_native) |
1253 | | { |
1254 | | if constexpr (traits::is_native) |
1255 | | { |
1256 | | if (type() == node_type_of<value_type>) |
1257 | | return *ref_cast<typename traits::native_type>(); |
1258 | | } |
1259 | | if (auto val = this->value<value_type>()) |
1260 | | return *val; |
1261 | | if constexpr (std::is_pointer_v<value_type>) |
1262 | | return value_type{ default_value }; |
1263 | | else |
1264 | | return static_cast<T&&>(default_value); |
1265 | | } |
1266 | | } |
1267 | | } |
1268 | | |
1269 | | /// \endcond |
1270 | | } |
1271 | | TOML_NAMESPACE_END; |
1272 | | |
1273 | | #include "header_end.hpp" |