Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
forward_declarations.hpp
Go to the documentation of this file.
1// # This file is a part of toml++ and is subject to the the terms of the MIT license.
2// # Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
3// # See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
4// SPDX-License-Identifier: MIT
5#pragma once
6
7#include "std_new.hpp"
8#include "std_string.hpp"
10#include <cfloat>
11#include <climits>
12#include <cmath>
13#include <cstddef>
14#include <cstdint>
15#include <cstring>
16#include <iosfwd>
17#include <limits>
18#include <memory>
19#include <type_traits>
21#include "header_start.hpp"
22
23// #---------------------------------------------------------------------------------------------------------------------
24// # ENVIRONMENT GROUND-TRUTHS
25// #---------------------------------------------------------------------------------------------------------------------
27
28#ifndef TOML_DISABLE_ENVIRONMENT_CHECKS
29#define TOML_ENV_MESSAGE \
30 "If you're seeing this error it's because you're building toml++ for an environment that " \
31 "doesn't conform to " \
32 "one of the 'ground truths' assumed by the library. Essentially this just means that I don't " \
33 "have the " \
34 "resources to test on more platforms, but I wish I did! You can try disabling the checks by " \
35 "defining " \
36 "TOML_DISABLE_ENVIRONMENT_CHECKS, but your mileage may vary. Please consider filing an issue " \
37 "at " \
38 "https://github.com/marzer/tomlplusplus/issues to help me improve support for your target " \
39 "environment. " \
40 "Thanks!"
41
42static_assert(CHAR_BIT == 8, TOML_ENV_MESSAGE);
43#ifdef FLT_RADIX
44static_assert(FLT_RADIX == 2, TOML_ENV_MESSAGE);
45#endif
46static_assert('A' == 65, TOML_ENV_MESSAGE);
47static_assert(sizeof(double) == 8, TOML_ENV_MESSAGE);
48static_assert(std::numeric_limits<double>::is_iec559, TOML_ENV_MESSAGE);
49static_assert(std::numeric_limits<double>::digits == 53, TOML_ENV_MESSAGE);
50static_assert(std::numeric_limits<double>::digits10 == 15, TOML_ENV_MESSAGE);
51static_assert(std::numeric_limits<double>::radix == 2, TOML_ENV_MESSAGE);
52
53#undef TOML_ENV_MESSAGE
54#endif // !TOML_DISABLE_ENVIRONMENT_CHECKS
55
57
58// #---------------------------------------------------------------------------------------------------------------------
59// # UNDOCUMENTED TYPEDEFS AND FORWARD DECLARATIONS
60// #---------------------------------------------------------------------------------------------------------------------
62// undocumented forward declarations are hidden from doxygen because they fuck it up =/
63
64namespace toml // non-abi namespace; this is not an error
65{
66using ::std::int16_t;
67using ::std::int32_t;
68using ::std::int64_t;
69using ::std::int8_t;
70using ::std::intptr_t;
71using ::std::nullptr_t;
72using ::std::ptrdiff_t;
73using ::std::size_t;
74using ::std::uint16_t;
75using ::std::uint32_t;
76using ::std::uint64_t;
77using ::std::uint8_t;
78using ::std::uint_least32_t;
79using ::std::uint_least64_t;
80using ::std::uintptr_t;
81} // namespace toml
82
84 struct date;
85 struct time;
86 struct time_offset;
87
89 struct date_time;
91
92 struct source_position;
93 struct source_region;
94
95 class node;
96 template <typename>
97 class node_view;
98
99 class key;
100 class array;
101 class table;
102 template <typename>
103 class value;
104
105 class path;
106
107 class toml_formatter;
108 class json_formatter;
109 class yaml_formatter;
110
112#if TOML_EXCEPTIONS
113 using parse_result = table;
114#else
115 class parse_result;
116#endif
117 TOML_ABI_NAMESPACE_END; // TOML_EXCEPTIONS
118}
120
122 using node_ptr = std::unique_ptr<node>;
123
124 TOML_ABI_NAMESPACE_BOOL(TOML_EXCEPTIONS, impl_ex, impl_noex);
125 class parser;
126 TOML_ABI_NAMESPACE_END; // TOML_EXCEPTIONS
127
128 // clang-format off
129
130 inline constexpr std::string_view control_char_escapes[] =
131 {
132 "\\u0000"sv,
133 "\\u0001"sv,
134 "\\u0002"sv,
135 "\\u0003"sv,
136 "\\u0004"sv,
137 "\\u0005"sv,
138 "\\u0006"sv,
139 "\\u0007"sv,
140 "\\b"sv,
141 "\\t"sv,
142 "\\n"sv,
143 "\\u000B"sv,
144 "\\f"sv,
145 "\\r"sv,
146 "\\u000E"sv,
147 "\\u000F"sv,
148 "\\u0010"sv,
149 "\\u0011"sv,
150 "\\u0012"sv,
151 "\\u0013"sv,
152 "\\u0014"sv,
153 "\\u0015"sv,
154 "\\u0016"sv,
155 "\\u0017"sv,
156 "\\u0018"sv,
157 "\\u0019"sv,
158 "\\u001A"sv,
159 "\\u001B"sv,
160 "\\u001C"sv,
161 "\\u001D"sv,
162 "\\u001E"sv,
163 "\\u001F"sv,
164 };
165
166 inline constexpr std::string_view node_type_friendly_names[] =
167 {
168 "none"sv,
169 "table"sv,
170 "array"sv,
171 "string"sv,
172 "integer"sv,
173 "floating-point"sv,
174 "boolean"sv,
175 "date"sv,
176 "time"sv,
177 "date-time"sv
178 };
179
180 // clang-format on
181}
183
184#if TOML_ABI_NAMESPACES
185#if TOML_EXCEPTIONS
186#define TOML_PARSER_TYPENAME TOML_NAMESPACE::impl::impl_ex::parser
187#else
188#define TOML_PARSER_TYPENAME TOML_NAMESPACE::impl::impl_noex::parser
189#endif
190#else
191#define TOML_PARSER_TYPENAME TOML_NAMESPACE::impl::parser
192#endif
193
195
196// #---------------------------------------------------------------------------------------------------------------------
197// # DOCUMENTED TYPEDEFS AND FORWARD DECLARATIONS
198// #---------------------------------------------------------------------------------------------------------------------
199
201namespace toml {}
202
203TOML_NAMESPACE_START // abi namespace
204{
223 inline namespace literals {}
224
226 enum class TOML_CLOSED_ENUM node_type : uint8_t {
227 none,
228 table,
229 array,
230 string,
231 integer,
232 floating_point,
233 boolean,
234 date,
235 time,
236 date_time
237 };
238
253 template <typename Char>
254 inline std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& lhs, node_type rhs) {
255 const auto str =
256 impl::node_type_friendly_names[static_cast<std::underlying_type_t<node_type>>(rhs)];
257 using str_char_t = decltype(str)::value_type;
258 if constexpr (std::is_same_v<Char, str_char_t>)
259 return lhs << str;
260 else {
261 if constexpr (sizeof(Char) == sizeof(str_char_t))
262 return lhs << std::basic_string_view<Char>{reinterpret_cast<const Char*>(str.data()),
263 str.length()};
264 else
265 return lhs << str.data();
266 }
267 }
268
270 enum class TOML_OPEN_FLAGS_ENUM
271 value_flags : uint16_t // being an "OPEN" flags enum is not an error
272 {
274 none,
275
278
281
284 };
286
291 POXY_IMPLEMENTATION_DETAIL(value_flags{static_cast<std::underlying_type_t<value_flags>>(-1)});
292
298 enum class TOML_CLOSED_FLAGS_ENUM format_flags : uint64_t {
300 none,
301
304
307
310
314
317
321
324
326 allow_octal_integers = (1ull << 7),
327
330
332 indent_sub_tables = (1ull << 9),
333
336 indent_array_elements = (1ull << 10),
337
340
346
348 terse_key_value_pairs = (1ull << 12),
349 };
351
367 template <typename T>
369 static_assert(std::is_reference_v<T>);
370
372 };
373 template <typename T>
375 template <typename T>
377
380 using default_formatter = toml_formatter;
381}
383
384// #---------------------------------------------------------------------------------------------------------------------
385// # METAFUNCTIONS & TYPE TRAITS
386// #---------------------------------------------------------------------------------------------------------------------
389 template <typename T>
390 using remove_cvref = std::remove_cv_t<std::remove_reference_t<T>>;
391
392 template <typename... T>
393 using common_signed_type = std::common_type_t<std::make_signed_t<T>...>;
394
395 template <typename T, typename... U>
396 inline constexpr bool is_one_of = (false || ... || std::is_same_v<T, U>);
397
398 template <typename... T>
399 inline constexpr bool all_integral = (std::is_integral_v<T> && ...);
400
401 template <typename T>
402 inline constexpr bool is_cvref =
403 std::is_reference_v<T> || std::is_const_v<T> || std::is_volatile_v<T>;
404
405 template <typename T>
406 inline constexpr bool is_wide_string =
407 is_one_of<std::decay_t<T>, const wchar_t*, wchar_t*, std::wstring_view, std::wstring>;
408
409 template <typename T>
410 inline constexpr bool value_retrieval_is_nothrow =
411 !std::is_same_v<remove_cvref<T>, std::string>
412#if TOML_HAS_CHAR8
413 && !std::is_same_v<remove_cvref<T>, std::u8string>
414#endif
415
416 && !is_wide_string<T>;
417
418 template <typename, typename>
419 struct copy_ref_;
420 template <typename Dest, typename Src>
421 using copy_ref = typename copy_ref_<Dest, Src>::type;
422
423 template <typename Dest, typename Src>
424 struct copy_ref_ {
425 using type = Dest;
426 };
427
428 template <typename Dest, typename Src>
429 struct copy_ref_<Dest, Src&> {
430 using type = std::add_lvalue_reference_t<Dest>;
431 };
432
433 template <typename Dest, typename Src>
434 struct copy_ref_<Dest, Src&&> {
435 using type = std::add_rvalue_reference_t<Dest>;
436 };
437
438 template <typename, typename>
439 struct copy_cv_;
440 template <typename Dest, typename Src>
441 using copy_cv = typename copy_cv_<Dest, Src>::type;
442
443 template <typename Dest, typename Src>
444 struct copy_cv_ {
445 using type = Dest;
446 };
447
448 template <typename Dest, typename Src>
449 struct copy_cv_<Dest, const Src> {
450 using type = std::add_const_t<Dest>;
451 };
452
453 template <typename Dest, typename Src>
454 struct copy_cv_<Dest, volatile Src> {
455 using type = std::add_volatile_t<Dest>;
456 };
457
458 template <typename Dest, typename Src>
459 struct copy_cv_<Dest, const volatile Src> {
460 using type = std::add_cv_t<Dest>;
461 };
462
463 template <typename Dest, typename Src>
464 using copy_cvref =
465 copy_ref<copy_ref<copy_cv<std::remove_reference_t<Dest>, std::remove_reference_t<Src>>, Dest>,
466 Src>;
467
468 template <typename...>
469 inline constexpr bool always_false = false;
470
471 template <typename T, typename... U>
472 inline constexpr bool first_is_same = false;
473 template <typename T, typename... U>
474 inline constexpr bool first_is_same<T, T, U...> = true;
475
476 template <typename T, bool = std::is_enum_v<T>>
477 struct underlying_type_ {
478 using type = std::underlying_type_t<T>;
479 };
480 template <typename T>
481 struct underlying_type_<T, false> {
482 using type = T;
483 };
484 template <typename T>
485 using underlying_type = typename underlying_type_<T>::type;
486
487 // general value traits
488 // (as they relate to their equivalent native TOML type)
489 struct default_value_traits {
490 using native_type = void;
491 static constexpr bool is_native = false;
492 static constexpr bool is_losslessly_convertible_to_native = false;
493 static constexpr bool can_represent_native = false;
494 static constexpr bool can_partially_represent_native = false;
495 static constexpr auto type = node_type::none;
496 };
497
498 template <typename T>
499 struct value_traits;
500
501 template <typename T, bool = std::is_enum_v<T>>
502 struct value_traits_base_selector {
503 static_assert(!is_cvref<T>);
504
505 using type = default_value_traits;
506 };
507 template <typename T>
508 struct value_traits_base_selector<T, true> {
509 static_assert(!is_cvref<T>);
510
511 using type = value_traits<underlying_type<T>>;
512 };
513
514 template <typename T>
515 struct value_traits : value_traits_base_selector<T>::type {};
516 template <typename T>
517 struct value_traits<const T> : value_traits<T> {};
518 template <typename T>
519 struct value_traits<volatile T> : value_traits<T> {};
520 template <typename T>
521 struct value_traits<const volatile T> : value_traits<T> {};
522 template <typename T>
523 struct value_traits<T&> : value_traits<T> {};
524 template <typename T>
525 struct value_traits<T&&> : value_traits<T> {};
526
527 // integer value_traits specializations - standard types
528 template <typename T>
529 struct integer_limits {
530 static constexpr T min = T{(std::numeric_limits<underlying_type<T>>::min)()};
531 static constexpr T max = T{(std::numeric_limits<underlying_type<T>>::max)()};
532 };
533 template <typename T>
534 struct integer_traits_base : integer_limits<T> {
535 using native_type = int64_t;
536 static constexpr bool is_native = std::is_same_v<underlying_type<T>, native_type>;
537 static constexpr bool is_signed = static_cast<underlying_type<T>>(-1) < underlying_type<T>{};
538 static constexpr auto type = node_type::integer;
539 static constexpr bool can_partially_represent_native = true;
540 };
541 template <typename T>
542 struct unsigned_integer_traits : integer_traits_base<T> {
543 static constexpr bool is_losslessly_convertible_to_native =
544 integer_limits<underlying_type<T>>::max <= 9223372036854775807ULL;
545 static constexpr bool can_represent_native = false;
546 };
547 template <typename T>
548 struct signed_integer_traits : integer_traits_base<T> {
549 using native_type = int64_t;
550 static constexpr bool is_losslessly_convertible_to_native =
551 integer_limits<underlying_type<T>>::min >= (-9223372036854775807LL - 1LL) &&
552 integer_limits<underlying_type<T>>::max <= 9223372036854775807LL;
553 static constexpr bool can_represent_native =
554 integer_limits<underlying_type<T>>::min <= (-9223372036854775807LL - 1LL) &&
555 integer_limits<underlying_type<T>>::max >= 9223372036854775807LL;
556 };
557 template <typename T, bool S = integer_traits_base<T>::is_signed>
558 struct integer_traits : signed_integer_traits<T> {};
559 template <typename T>
560 struct integer_traits<T, false> : unsigned_integer_traits<T> {};
561 template <>
562 struct value_traits<signed char> : integer_traits<signed char> {};
563 template <>
564 struct value_traits<unsigned char> : integer_traits<unsigned char> {};
565 template <>
566 struct value_traits<signed short> : integer_traits<signed short> {};
567 template <>
568 struct value_traits<unsigned short> : integer_traits<unsigned short> {};
569 template <>
570 struct value_traits<signed int> : integer_traits<signed int> {};
571 template <>
572 struct value_traits<unsigned int> : integer_traits<unsigned int> {};
573 template <>
574 struct value_traits<signed long> : integer_traits<signed long> {};
575 template <>
576 struct value_traits<unsigned long> : integer_traits<unsigned long> {};
577 template <>
578 struct value_traits<signed long long> : integer_traits<signed long long> {};
579 template <>
580 struct value_traits<unsigned long long> : integer_traits<unsigned long long> {};
581 static_assert(value_traits<int64_t>::is_native);
582 static_assert(value_traits<int64_t>::is_signed);
583 static_assert(value_traits<int64_t>::is_losslessly_convertible_to_native);
584 static_assert(value_traits<int64_t>::can_represent_native);
585 static_assert(value_traits<int64_t>::can_partially_represent_native);
586
587 // integer value_traits specializations - non-standard types
588#ifdef TOML_INT128
589 template <>
590 struct integer_limits<TOML_INT128> {
591 static constexpr TOML_INT128 max =
592 static_cast<TOML_INT128>((TOML_UINT128{1u} << ((__SIZEOF_INT128__ * CHAR_BIT) - 1)) - 1);
593 static constexpr TOML_INT128 min = -max - TOML_INT128{1};
594 };
595 template <>
596 struct integer_limits<TOML_UINT128> {
597 static constexpr TOML_UINT128 min = TOML_UINT128{};
598 static constexpr TOML_UINT128 max =
599 (2u * static_cast<TOML_UINT128>(integer_limits<TOML_INT128>::max)) + 1u;
600 };
601 template <>
602 struct value_traits<TOML_INT128> : integer_traits<TOML_INT128> {};
603 template <>
604 struct value_traits<TOML_UINT128> : integer_traits<TOML_UINT128> {};
605#endif
606#ifdef TOML_SMALL_INT_TYPE
607 template <>
608 struct value_traits<TOML_SMALL_INT_TYPE> : signed_integer_traits<TOML_SMALL_INT_TYPE> {};
609#endif
610
611 // floating-point traits base
612 template <typename T, int MantissaDigits, int DecimalDigits>
613 struct float_traits_base {
614 static constexpr auto type = node_type::floating_point;
615 using native_type = double;
616 static constexpr bool is_native = std::is_same_v<T, native_type>;
617 static constexpr bool is_signed = true;
618
619 static constexpr int bits = static_cast<int>(sizeof(T) * CHAR_BIT);
620 static constexpr int digits = MantissaDigits;
621 static constexpr int digits10 = DecimalDigits;
622
623 static constexpr bool is_losslessly_convertible_to_native = bits <= 64 //
624 && digits <= 53 // DBL_MANT_DIG
625 && digits10 <= 15; // DBL_DIG
626
627 static constexpr bool can_represent_native = digits >= 53 // DBL_MANT_DIG
628 && digits10 >= 15; // DBL_DIG
629
630 static constexpr bool can_partially_represent_native = digits > 0 && digits10 > 0;
631 };
632 template <typename T>
633 struct float_traits
634 : float_traits_base<T, std::numeric_limits<T>::digits, std::numeric_limits<T>::digits10> {};
635#if TOML_ENABLE_FLOAT16
636 template <>
637 struct float_traits<_Float16> : float_traits_base<_Float16, __FLT16_MANT_DIG__, __FLT16_DIG__> {};
638#endif
639#ifdef TOML_FLOAT128
640 template <>
641 struct float_traits<TOML_FLOAT128>
642 : float_traits_base<TOML_FLOAT128, __FLT128_MANT_DIG__, __FLT128_DIG__> {};
643#endif
644
645 // floating-point traits
646 template <>
647 struct value_traits<float> : float_traits<float> {};
648 template <>
649 struct value_traits<double> : float_traits<double> {};
650 template <>
651 struct value_traits<long double> : float_traits<long double> {};
652#if TOML_ENABLE_FLOAT16
653 template <>
654 struct value_traits<_Float16> : float_traits<_Float16> {};
655#endif
656#ifdef TOML_FLOAT128
657 template <>
658 struct value_traits<TOML_FLOAT128> : float_traits<TOML_FLOAT128> {};
659#endif
660#ifdef TOML_SMALL_FLOAT_TYPE
661 template <>
662 struct value_traits<TOML_SMALL_FLOAT_TYPE> : float_traits<TOML_SMALL_FLOAT_TYPE> {};
663#endif
664 static_assert(value_traits<double>::is_native);
665 static_assert(value_traits<double>::is_losslessly_convertible_to_native);
666 static_assert(value_traits<double>::can_represent_native);
667 static_assert(value_traits<double>::can_partially_represent_native);
668
669 // string value_traits specializations - char-based strings
670 template <typename T>
671 struct string_traits {
672 using native_type = std::string;
673 static constexpr bool is_native = std::is_same_v<T, native_type>;
674 static constexpr bool is_losslessly_convertible_to_native = true;
675 static constexpr bool can_represent_native =
676 !std::is_array_v<T> && (!std::is_pointer_v<T> || std::is_const_v<std::remove_pointer_t<T>>);
677 static constexpr bool can_partially_represent_native = can_represent_native;
678 static constexpr auto type = node_type::string;
679 };
680 template <>
681 struct value_traits<std::string> : string_traits<std::string> {};
682 template <>
683 struct value_traits<std::string_view> : string_traits<std::string_view> {};
684 template <>
685 struct value_traits<const char*> : string_traits<const char*> {};
686 template <size_t N>
687 struct value_traits<const char[N]> : string_traits<const char[N]> {};
688 template <>
689 struct value_traits<char*> : string_traits<char*> {};
690 template <size_t N>
691 struct value_traits<char[N]> : string_traits<char[N]> {};
692
693 // string value_traits specializations - char8_t-based strings
694#if TOML_HAS_CHAR8
695 template <>
696 struct value_traits<std::u8string> : string_traits<std::u8string> {};
697 template <>
698 struct value_traits<std::u8string_view> : string_traits<std::u8string_view> {};
699 template <>
700 struct value_traits<const char8_t*> : string_traits<const char8_t*> {};
701 template <size_t N>
702 struct value_traits<const char8_t[N]> : string_traits<const char8_t[N]> {};
703 template <>
704 struct value_traits<char8_t*> : string_traits<char8_t*> {};
705 template <size_t N>
706 struct value_traits<char8_t[N]> : string_traits<char8_t[N]> {};
707#endif
708
709 // string value_traits specializations - wchar_t-based strings on Windows
710#if TOML_ENABLE_WINDOWS_COMPAT
711 template <typename T>
712 struct wstring_traits {
713 using native_type = std::string;
714 static constexpr bool is_native = false;
715 static constexpr bool is_losslessly_convertible_to_native = true; // narrow
716 static constexpr bool can_represent_native = std::is_same_v<T, std::wstring>; // widen
717 static constexpr bool can_partially_represent_native = can_represent_native;
718 static constexpr auto type = node_type::string;
719 };
720 template <>
721 struct value_traits<std::wstring> : wstring_traits<std::wstring> {};
722 template <>
723 struct value_traits<std::wstring_view> : wstring_traits<std::wstring_view> {};
724 template <>
725 struct value_traits<const wchar_t*> : wstring_traits<const wchar_t*> {};
726 template <size_t N>
727 struct value_traits<const wchar_t[N]> : wstring_traits<const wchar_t[N]> {};
728 template <>
729 struct value_traits<wchar_t*> : wstring_traits<wchar_t*> {};
730 template <size_t N>
731 struct value_traits<wchar_t[N]> : wstring_traits<wchar_t[N]> {};
732#endif
733
734 // other 'native' value_traits specializations
735 template <typename T, node_type NodeType>
736 struct native_value_traits {
737 using native_type = T;
738 static constexpr bool is_native = true;
739 static constexpr bool is_losslessly_convertible_to_native = true;
740 static constexpr bool can_represent_native = true;
741 static constexpr bool can_partially_represent_native = true;
742 static constexpr auto type = NodeType;
743 };
744 template <>
745 struct value_traits<bool> : native_value_traits<bool, node_type::boolean> {};
746 template <>
747 struct value_traits<date> : native_value_traits<date, node_type::date> {};
748 template <>
749 struct value_traits<time> : native_value_traits<time, node_type::time> {};
750 template <>
751 struct value_traits<date_time> : native_value_traits<date_time, node_type::date_time> {};
752
753 // native value category queries
754 template <typename T>
755 using native_type_of = typename value_traits<T>::native_type;
756 template <typename T>
757 inline constexpr bool is_native = value_traits<T>::is_native;
758 template <typename T>
759 inline constexpr bool can_represent_native = value_traits<T>::can_represent_native;
760 template <typename T>
761 inline constexpr bool can_partially_represent_native =
762 value_traits<T>::can_partially_represent_native;
763 template <typename T>
764 inline constexpr bool is_losslessly_convertible_to_native =
765 value_traits<T>::is_losslessly_convertible_to_native;
766 template <typename T, typename... U>
767 inline constexpr bool is_natively_one_of = is_one_of<native_type_of<T>, U...>;
768
769 // native value types => nodes
770 template <typename T>
771 struct node_wrapper {
772 using type = T;
773 };
774 template <typename T>
775 struct node_wrapper<const T> {
776 using type = std::add_const_t<typename node_wrapper<T>::type>;
777 };
778 template <typename T>
779 struct node_wrapper<volatile T> {
780 using type = std::add_volatile_t<typename node_wrapper<T>::type>;
781 };
782 template <typename T>
783 struct node_wrapper<const volatile T> {
784 using type = std::add_const_t<std::add_volatile_t<typename node_wrapper<T>::type>>;
785 };
786 template <>
787 struct node_wrapper<std::string> {
788 using type = value<std::string>;
789 };
790 template <>
791 struct node_wrapper<int64_t> {
792 using type = value<int64_t>;
793 };
794 template <>
795 struct node_wrapper<double> {
796 using type = value<double>;
797 };
798 template <>
799 struct node_wrapper<bool> {
800 using type = value<bool>;
801 };
802 template <>
803 struct node_wrapper<date> {
804 using type = value<date>;
805 };
806 template <>
807 struct node_wrapper<time> {
808 using type = value<time>;
809 };
810 template <>
811 struct node_wrapper<date_time> {
812 using type = value<date_time>;
813 };
814 template <typename T>
815 using wrap_node = typename node_wrapper<std::remove_reference_t<T>>::type;
816
817 // nodes => native value types
818 template <typename T>
819 struct node_unwrapper {
820 using type = T;
821 };
822 template <typename T>
823 struct node_unwrapper<value<T>> {
824 using type = T;
825 };
826 template <typename T>
827 struct node_unwrapper<const value<T>> {
828 using type = std::add_const_t<T>;
829 };
830 template <typename T>
831 struct node_unwrapper<volatile value<T>> {
832 using type = std::add_volatile_t<T>;
833 };
834 template <typename T>
835 struct node_unwrapper<const volatile value<T>> {
836 using type = std::add_volatile_t<std::add_const_t<T>>;
837 };
838 template <typename T>
839 using unwrap_node = typename node_unwrapper<std::remove_reference_t<T>>::type;
840
841 template <typename T>
842 struct node_type_getter {
843 static constexpr auto value = value_traits<T>::type;
844 };
845 template <>
846 struct node_type_getter<table> {
847 static constexpr auto value = node_type::table;
848 };
849 template <>
850 struct node_type_getter<array> {
851 static constexpr auto value = node_type::array;
852 };
853 template <>
854 struct node_type_getter<void> {
855 static constexpr auto value = node_type::none;
856 };
857 template <typename T>
858 inline constexpr node_type node_type_of = node_type_getter<unwrap_node<remove_cvref<T>>>::value;
859
860 template <typename T, typename ConvertFrom>
861 inline constexpr bool is_constructible_or_convertible =
862 std::is_constructible_v<T, ConvertFrom> //
863 || std::is_convertible_v<ConvertFrom, T>;
864}
867
870 template <typename T>
871 inline constexpr bool is_table = std::is_same_v<impl::remove_cvref<T>, table>;
872
874 template <typename T>
875 inline constexpr bool is_array = std::is_same_v<impl::remove_cvref<T>, array>;
876
879 template <typename T>
880 inline constexpr bool is_container = is_table<T> || is_array<T>;
881
884 template <typename T>
885 inline constexpr bool is_string = std::is_same_v< //
886 impl::remove_cvref<impl::wrap_node<impl::remove_cvref<T>>>, //
887 value<std::string>>;
888
891 template <typename T>
892 inline constexpr bool is_integer = std::is_same_v< //
893 impl::remove_cvref<impl::wrap_node<impl::remove_cvref<T>>>, //
894 value<int64_t>>;
895
898 template <typename T>
899 inline constexpr bool is_floating_point = std::is_same_v< //
900 impl::remove_cvref<impl::wrap_node<impl::remove_cvref<T>>>, //
901 value<double>>;
902
905 template <typename T>
906 inline constexpr bool is_number = is_integer<T> || is_floating_point<T>;
907
910 template <typename T>
911 inline constexpr bool is_boolean = std::is_same_v< //
912 impl::remove_cvref<impl::wrap_node<impl::remove_cvref<T>>>, //
913 value<bool>>;
914
917 template <typename T>
918 inline constexpr bool is_date = std::is_same_v< //
919 impl::remove_cvref<impl::wrap_node<impl::remove_cvref<T>>>, //
920 value<date>>;
921
924 template <typename T>
925 inline constexpr bool is_time = std::is_same_v< //
926 impl::remove_cvref<impl::wrap_node<impl::remove_cvref<T>>>, //
927 value<time>>;
928
931 template <typename T>
932 inline constexpr bool is_date_time = std::is_same_v< //
933 impl::remove_cvref<impl::wrap_node<impl::remove_cvref<T>>>, //
934 value<date_time>>;
935
938 template <typename T>
939 inline constexpr bool is_chronological = is_date<T> || is_time<T> || is_date_time<T>;
940
943 template <typename T>
944 inline constexpr bool is_value =
945 is_string<T> || is_number<T> || is_boolean<T> || is_chronological<T>;
946
949 template <typename T>
950 inline constexpr bool is_node = std::is_same_v<toml::node, impl::remove_cvref<T>> //
951 || std::is_base_of_v<toml::node, impl::remove_cvref<T>>;
952
954 template <typename T>
955 inline constexpr bool is_node_view =
956 impl::is_one_of<impl::remove_cvref<T>, node_view<node>, node_view<const node>>;
957}
959
960// #---------------------------------------------------------------------------------------------------------------------
961// # INTERNAL HELPERS
962// #---------------------------------------------------------------------------------------------------------------------
965 template <typename T>
966 TOML_CONST_INLINE_GETTER constexpr std::underlying_type_t<T> unwrap_enum(T val) noexcept {
967 return static_cast<std::underlying_type_t<T>>(val);
968 }
969
970 // Q: "why not use std::fpclassify?"
971 // A: Because it gets broken by -ffast-math and friends
972 enum class TOML_CLOSED_ENUM fp_class : unsigned { ok, neg_inf, pos_inf, nan };
973
975 inline fp_class fpclassify(const double& val) noexcept {
976 static_assert(sizeof(uint64_t) == sizeof(double));
977
978 static constexpr uint64_t sign =
979 0b1000000000000000000000000000000000000000000000000000000000000000ull;
980 static constexpr uint64_t exponent =
981 0b0111111111110000000000000000000000000000000000000000000000000000ull;
982 static constexpr uint64_t mantissa =
983 0b0000000000001111111111111111111111111111111111111111111111111111ull;
984
985 uint64_t val_bits;
986 std::memcpy(&val_bits, &val, sizeof(val));
987 if ((val_bits & exponent) != exponent) return fp_class::ok;
988 if ((val_bits & mantissa)) return fp_class::nan;
989 return (val_bits & sign) ? fp_class::neg_inf : fp_class::pos_inf;
990 }
991
992 // Q: "why not use std::find and std::min?"
993 // A: Because <algorithm> is _huge_ and these would be the only things I used from it.
994 // I don't want to impose such a heavy compile-time burden on users.
995
996 template <typename Iterator, typename T>
997 TOML_PURE_GETTER inline auto find(Iterator start, Iterator end, const T& needle) noexcept //
998 -> decltype(&(*start)) {
999 for (; start != end; start++)
1000 if (*start == needle) return &(*start);
1001 return nullptr;
1002 }
1003
1004 template <typename T>
1005 TOML_PURE_INLINE_GETTER constexpr const T& min(const T& a, const T& b) noexcept //
1006 {
1007 return a < b ? a : b;
1008 }
1009}
1012
1013#include "header_end.hpp"
#define N
Definition 17.names.cpp:157
#define T
Definition 17.names.cpp:163
#define rhs
Definition 17.names.cpp:536
#define start
Definition 17.names.cpp:547
#define Char
Definition 17.names.cpp:455
#define a
Definition 17.names.cpp:109
#define array
Definition 17.names.cpp:447
#define lhs
Definition 17.names.cpp:489
#define b
Definition 17.names.cpp:110
#define val
Definition 17.names.cpp:570
#define U
Definition 17.names.cpp:164
T value(const T &val)
const int end
#define FLT_RADIX
Definition _cfloat.h:45
unsigned short wchar_t
A TOML array.
Definition array.hpp:258
The result of a parsing operation.
A TOML path.
Definition path.hpp:209
A TOML table.
Definition table.hpp:190
const char * str
Definition exec.cpp:170
enum TOML_OPEN_FLAGS_ENUM format_as_hexadecimal
Format integer values as hexadecimal.
toml_formatter default_formatter
The 'default' formatter used by TOML objects when they are printed to a stream. \detail This is an al...
enum TOML_OPEN_FLAGS_ENUM value_flags
Metadata associated with TOML values.
constexpr bool is_number
Metafunction for determining if a type satisfies either toml::is_integer or toml::is_floating_point.
enum TOML_OPEN_FLAGS_ENUM format_as_octal
Format integer values as octal.
enum TOML_CLOSED_FLAGS_ENUM allow_multi_line_strings
Strings containing newlines will be emitted as triple-quoted 'multi-line' strings where possible.
enum TOML_CLOSED_FLAGS_ENUM quote_dates_and_times
Dates and times will be emitted as quoted strings.
enum TOML_CLOSED_FLAGS_ENUM allow_unicode_strings
Allow non-ASCII characters in strings (as opposed to their escaped form, e.g. \u00DA).
constexpr bool is_boolean
Metafunction for determining if a type is, or is a reference to, a bool or toml::value<bool>.
enum TOML_CLOSED_FLAGS_ENUM allow_real_tabs_in_strings
Allow real tab characters in string literals (as opposed to the escaped form \t).
constexpr bool is_floating_point
Metafunction for determining if a type is, or is a reference to, a double or toml::value<double>.
constexpr bool is_date
Metafunction for determining if a type is, or is a reference to, a toml::date or toml::value<date>.
enum TOML_CLOSED_FLAGS_ENUM allow_octal_integers
Allow integers with #value_flags::format_as_octal to be emitted as octal.
enum TOML_CLOSED_FLAGS_ENUM allow_binary_integers
Allow integers with #value_flags::format_as_binary to be emitted as binary.
constexpr bool is_string
Metafunction for determining if a type is, or is a reference to, a std::string or toml::value<std::st...
TOML_DISABLE_WARNINGS
constexpr bool is_array
Metafunction for determining if a type is, or is a reference to, a toml::array.
enum TOML_CLOSED_FLAGS_ENUM quote_infinities_and_nans
Infinities and NaNs will be emitted as quoted strings.
constexpr bool is_chronological
Metafunction for determining if a type satisfies any of toml::is_date, toml::is_time or toml::is_date...
constexpr bool is_date_time
Metafunction for determining if a type is, or is a reference to, a toml::date_time or toml::value<dat...
enum TOML_CLOSED_FLAGS_ENUM allow_hexadecimal_integers
Allow integers with #value_flags::format_as_hexadecimal to be emitted as hexadecimal.
enum TOML_CLOSED_FLAGS_ENUM allow_literal_strings
Strings will be emitted as single-quoted literal strings where possible.
constexpr bool is_integer
Metafunction for determining if a type is, or is a reference to, a int64_t or toml::value<int64_t>.
enum TOML_CLOSED_FLAGS_ENUM terse_key_value_pairs
Avoids the use of whitespace around key-value pairs.
constexpr bool is_container
Metafunction for determining if a type satisfies either toml::is_table or toml::is_array.
constexpr value_flags preserve_source_value_flags
Special #toml::value_flags constant used for array + table insert functions to specify that any value...
enum TOML_CLOSED_FLAGS_ENUM relaxed_float_precision
Emit floating-point values with relaxed (human-friendly) precision.
enum TOML_OPEN_FLAGS_ENUM format_as_binary
Format integer values as binary.
constexpr bool is_node_view
Metafunction for determining if a type is, or is a reference to, a toml::node_view.
enum TOML_CLOSED_FLAGS_ENUM format_flags
Format flags for modifying how TOML data is printed to streams.
constexpr bool is_node
Metafunction for determining if a type is, or is a reference to, a toml::node (or one of its subclass...
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &lhs, node_type rhs)
Pretty-prints the value of a node_type to a stream.
enum TOML_CLOSED_FLAGS_ENUM indent_sub_tables
Apply indentation to tables nested within other tables/arrays.
constexpr bool is_time
Metafunction for determining if a type is, or is a reference to, a toml::time or toml::value<time>.
enum TOML_CLOSED_FLAGS_ENUM indentation
Combination mask of all indentation-enabling flags.
enum TOML_CLOSED_FLAGS_ENUM indent_array_elements
Apply indentation to array elements when the array is forced to wrap over multiple lines.
constexpr bool is_value
Metafunction for determining if a type is, or is a reference to, any of the toml value types....
#define TOML_HAS_CUSTOM_OPTIONAL_TYPE
#define TOML_EXCEPTIONS
Sets whether the library uses exceptions to report parsing failures. \detail Defaults to 1 or 0 accor...
#define CHAR_BIT
Definition limits.h:40
Definition json.h:5363
The root namespace for all toml++ functions and types.
#define TOML_TRIVIAL_ABI
#define POXY_IMPLEMENTATION_DETAIL(...)
#define TOML_ABI_NAMESPACE_BOOL(cond, T, F)
#define TOML_ABI_NAMESPACE_END
#define TOML_CLOSED_ENUM
#define TOML_PURE_GETTER
#define TOML_OPEN_FLAGS_ENUM
#define TOML_CLOSED_FLAGS_ENUM
#define TOML_PURE_INLINE_GETTER
#define TOML_IMPL_NAMESPACE_END
#define TOML_IMPL_NAMESPACE_START
#define TOML_CONST_INLINE_GETTER
#define TOML_MAKE_FLAGS(T)
#define true
Definition stdbool.h:25
#define false
Definition stdbool.h:26
#define bool
Definition stdbool.h:24
A date-time.
Helper class for suppressing move-construction in single-argument array constructors.
A source document line-and-column pair.
A source document region.
A timezone offset.
A local time-of-day.
#define min(a, b)
#define max(a, b)