21 friend class TOML_PARSER_TYPENAME;
26 noexcept(impl::value_retrieval_is_nothrow<T>);
28 template <
typename T,
typename N>
29 using ref_type_ = std::conditional_t<
30 std::is_reference_v<T>,
31 impl::copy_ref<impl::copy_cv<impl::unwrap_node<T>, std::remove_reference_t<N>>,
T>,
32 impl::copy_cvref<impl::unwrap_node<T>,
N>
35 template <
typename T,
typename N>
36 using ref_type = std::conditional_t<
37 std::is_reference_v<N>,
39 ref_type_<T, std::add_lvalue_reference_t<N>>
42 template <
typename T,
typename N>
44 using unwrapped_type = impl::unwrap_node<T>;
45 static_assert(toml::is_value<unwrapped_type> || toml::is_container<unwrapped_type>,
46 "The template type argument of node::ref() must be one "
47 "of:" TOML_SA_UNWRAPPED_NODE_TYPE_LIST);
50 "template type argument provided to toml::node::ref() didn't match the "
51 "node's actual type");
53 using node_ref = std::remove_volatile_t<std::remove_reference_t<N>>&;
54 using val_type = std::remove_volatile_t<unwrapped_type>;
55 using out_ref = ref_type<T, N&&>;
56 static_assert(std::is_reference_v<out_ref>);
58 if constexpr (toml::is_value<unwrapped_type>)
59 return static_cast<out_ref
>(
const_cast<node_ref
>(
n).template ref_cast<val_type>().get());
61 return static_cast<out_ref
>(
const_cast<node_ref
>(
n).
template ref_cast<val_type>());
69 node(
const node&)
noexcept;
72 node(node&&)
noexcept;
75 node& operator=(
const node&)
noexcept;
78 node& operator=(node&&)
noexcept;
80 template <
typename T,
typename N>
81 using ref_cast_type_ = std::conditional_t<
82 std::is_reference_v<T>,
83 impl::copy_ref<impl::copy_cv<impl::wrap_node<T>, std::remove_reference_t<N>>,
T>,
84 impl::copy_cvref<impl::wrap_node<T>,
N>
87 template <
typename T,
typename N>
88 using ref_cast_type = std::conditional_t<
89 std::is_reference_v<N>,
91 ref_cast_type_<T, std::add_lvalue_reference_t<N>>
96 using out_ref = ref_cast_type<T, node&>;
97 using out_type = std::remove_reference_t<out_ref>;
98 return static_cast<out_ref
>(*
reinterpret_cast<out_type*
>(
this));
101 template <
typename T>
103 using out_ref = ref_cast_type<T, node&&>;
104 using out_type = std::remove_reference_t<out_ref>;
105 return static_cast<out_ref
>(*
reinterpret_cast<out_type*
>(
this));
108 template <
typename T>
110 using out_ref = ref_cast_type<T, const node&>;
111 using out_type = std::remove_reference_t<out_ref>;
112 return static_cast<out_ref
>(*
reinterpret_cast<out_type*
>(
this));
115 template <
typename T>
117 using out_ref = ref_cast_type<T, const node&&>;
118 using out_type = std::remove_reference_t<out_ref>;
119 return static_cast<out_ref
>(*
reinterpret_cast<out_type*
>(
this));
126 virtual ~node()
noexcept;
163 virtual bool is_homogeneous(node_type ntype, node*& first_nonmatch)
noexcept = 0;
167 virtual bool is_homogeneous(node_type ntype,
const node*& first_nonmatch)
const noexcept = 0;
196 virtual bool is_homogeneous(node_type ntype)
const noexcept = 0;
224 template <
typename ElemType =
void>
226 using type = impl::remove_cvref<impl::unwrap_node<ElemType>>;
227 static_assert(std::is_void_v<type> || toml::is_value<type> || toml::is_container<type>,
228 "The template type argument of node::is_homogeneous() must be void or one "
229 "of:" TOML_SA_UNWRAPPED_NODE_TYPE_LIST);
231 return is_homogeneous(impl::node_type_of<type>);
236 virtual node_type type()
const noexcept = 0;
240 virtual bool is_table()
const noexcept = 0;
244 virtual bool is_array()
const noexcept = 0;
248 virtual bool is_array_of_tables()
const noexcept = 0;
252 virtual bool is_value()
const noexcept = 0;
256 virtual bool is_string()
const noexcept = 0;
268 virtual bool is_number()
const noexcept = 0;
276 virtual bool is_date()
const noexcept = 0;
280 virtual bool is_time()
const noexcept = 0;
291 template <
typename T>
293 using type = impl::remove_cvref<impl::unwrap_node<T>>;
294 static_assert(toml::is_value<type> || toml::is_container<type>,
295 "The template type argument of node::is() must be one "
296 "of:" TOML_SA_UNWRAPPED_NODE_TYPE_LIST);
298 if constexpr (std::is_same_v<type, table>)
300 else if constexpr (std::is_same_v<type, array>)
302 else if constexpr (std::is_same_v<type, std::string>)
304 else if constexpr (std::is_same_v<type, int64_t>)
306 else if constexpr (std::is_same_v<type, double>)
308 else if constexpr (std::is_same_v<type, bool>)
310 else if constexpr (std::is_same_v<type, date>)
312 else if constexpr (std::is_same_v<type, time>)
314 else if constexpr (std::is_same_v<type, date_time>)
325 virtual table* as_table()
noexcept = 0;
329 virtual array* as_array()
noexcept = 0;
333 virtual toml::value<std::string>* as_string()
noexcept = 0;
337 virtual toml::value<int64_t>* as_integer()
noexcept = 0;
341 virtual toml::value<double>* as_floating_point()
noexcept = 0;
345 virtual toml::value<bool>* as_boolean()
noexcept = 0;
349 virtual toml::value<date>* as_date()
noexcept = 0;
353 virtual toml::value<time>* as_time()
noexcept = 0;
357 virtual toml::value<date_time>* as_date_time()
noexcept = 0;
361 virtual const table* as_table()
const noexcept = 0;
365 virtual const array* as_array()
const noexcept = 0;
370 virtual const toml::value<std::string>* as_string()
const noexcept = 0;
375 virtual const toml::value<int64_t>* as_integer()
const noexcept = 0;
380 virtual const toml::value<double>* as_floating_point()
const noexcept = 0;
384 virtual const toml::value<bool>* as_boolean()
const noexcept = 0;
389 virtual const toml::value<date>* as_date()
const noexcept = 0;
394 virtual const toml::value<time>* as_time()
const noexcept = 0;
399 virtual const toml::value<date_time>* as_date_time()
const noexcept = 0;
421 template <
typename T>
423 using unwrapped_type = impl::unwrap_node<impl::remove_cvref<T>>;
424 static_assert(toml::is_value<unwrapped_type> || toml::is_container<unwrapped_type>,
425 "The template type argument of node::as() must be one "
426 "of:" TOML_SA_UNWRAPPED_NODE_TYPE_LIST);
428 if constexpr (std::is_same_v<unwrapped_type, table>)
430 else if constexpr (std::is_same_v<unwrapped_type, array>)
432 else if constexpr (std::is_same_v<unwrapped_type, std::string>)
434 else if constexpr (std::is_same_v<unwrapped_type, int64_t>)
436 else if constexpr (std::is_same_v<unwrapped_type, double>)
437 return as_floating_point();
438 else if constexpr (std::is_same_v<unwrapped_type, bool>)
440 else if constexpr (std::is_same_v<unwrapped_type, date>)
442 else if constexpr (std::is_same_v<unwrapped_type, time>)
444 else if constexpr (std::is_same_v<unwrapped_type, date_time>)
445 return as_date_time();
449 template <
typename T>
451 using unwrapped_type = impl::unwrap_node<impl::remove_cvref<T>>;
452 static_assert(toml::is_value<unwrapped_type> || toml::is_container<unwrapped_type>,
453 "The template type argument of node::as() must be one "
454 "of:" TOML_SA_UNWRAPPED_NODE_TYPE_LIST);
456 if constexpr (std::is_same_v<unwrapped_type, table>)
458 else if constexpr (std::is_same_v<unwrapped_type, array>)
460 else if constexpr (std::is_same_v<unwrapped_type, std::string>)
462 else if constexpr (std::is_same_v<unwrapped_type, int64_t>)
464 else if constexpr (std::is_same_v<unwrapped_type, double>)
465 return as_floating_point();
466 else if constexpr (std::is_same_v<unwrapped_type, bool>)
468 else if constexpr (std::is_same_v<unwrapped_type, date>)
470 else if constexpr (std::is_same_v<unwrapped_type, time>)
472 else if constexpr (std::is_same_v<unwrapped_type, date_time>)
473 return as_date_time();
494 template <
typename T>
495 TOML_NODISCARD optional<T> value_exact()
const noexcept(impl::value_retrieval_is_nothrow<T>);
623 template <
typename T>
643 template <
typename T>
645 noexcept(impl::value_retrieval_is_nothrow<T>);
675 template <
typename T>
677 return do_ref<T>(*
this);
681 template <
typename T>
683 return do_ref<T>(std::move(*
this));
687 template <
typename T>
689 return do_ref<T>(*
this);
693 template <
typename T>
695 return do_ref<T>(std::move(*
this));
705 const source_region& source()
const noexcept {
return source_; }
712 template <
typename Func,
typename Node,
typename T>
713 static constexpr bool can_visit = std::is_invocable_v<Func, ref_cast_type<T, Node>>;
715 template <
typename Func,
typename Node,
typename T>
716 static constexpr bool can_visit_nothrow =
717 std::is_nothrow_invocable_v<Func, ref_cast_type<T, Node>>;
719 template <
typename Func,
typename Node>
720 static constexpr bool can_visit_any = can_visit<Func, Node, table>
721 || can_visit<Func, Node, array>
722 || can_visit<Func, Node, std::string>
723 || can_visit<Func, Node, int64_t>
724 || can_visit<Func, Node, double>
725 || can_visit<Func, Node, bool>
726 || can_visit<Func, Node, date>
727 || can_visit<Func, Node, time>
728 || can_visit<Func, Node, date_time>;
732 template <
typename Func,
typename Node>
733 static constexpr bool can_visit_all = can_visit<Func, Node, table>
734 && can_visit<Func, Node, array>
735 && can_visit<Func, Node, std::string>
736 && can_visit<Func, Node, int64_t>
737 && can_visit<Func, Node, double>
738 && can_visit<Func, Node, bool>
739 && can_visit<Func, Node, date>
740 && can_visit<Func, Node, time>
741 && can_visit<Func, Node, date_time>;
743 template <
typename Func,
typename Node,
typename T>
744 static constexpr bool visit_is_nothrow_one = !can_visit<Func, Node, T> || can_visit_nothrow<Func, Node, T>;
746 template <
typename Func,
typename Node>
747 static constexpr bool visit_is_nothrow = visit_is_nothrow_one<Func, Node, table>
748 && visit_is_nothrow_one<Func, Node, array>
749 && visit_is_nothrow_one<Func, Node, std::string>
750 && visit_is_nothrow_one<Func, Node, int64_t>
751 && visit_is_nothrow_one<Func, Node, double>
752 && visit_is_nothrow_one<Func, Node, bool>
753 && visit_is_nothrow_one<Func, Node, date>
754 && visit_is_nothrow_one<Func, Node, time>
755 && visit_is_nothrow_one<Func, Node, date_time>;
759 template <
typename Func,
typename Node,
typename T,
bool = can_visit<Func, Node, T>>
760 struct visit_return_type_ {
761 using type =
decltype(std::declval<Func>()(std::declval<ref_cast_type<T, Node>>()));
763 template <
typename Func,
typename Node,
typename T>
764 struct visit_return_type_<Func, Node,
T,
false> {
768 template <
typename Func,
typename Node,
typename T>
769 using visit_return_type =
typename visit_return_type_<Func, Node, T>::type;
771 template <
typename A,
typename B>
772 using nonvoid = std::conditional_t<std::is_void_v<A>,
B,
A>;
774 template <
typename Func,
typename Node>
775 static decltype(
auto) do_visit(Func&& visitor,
776 Node&&
n)
noexcept(visit_is_nothrow<Func&&, Node&&>) {
777 static_assert(can_visit_any<Func&&, Node&&>,
778 "TOML node visitors must be invocable for at least one of the toml::node "
779 "specializations:" TOML_SA_NODE_TYPE_LIST);
782 case node_type::table:
783 if constexpr (can_visit<Func&&, Node&&, table>)
784 return static_cast<Func&&
>(visitor)(
static_cast<Node&&
>(
n).
template ref_cast<table>());
787 case node_type::array:
788 if constexpr (can_visit<Func&&, Node&&, array>)
789 return static_cast<Func&&
>(visitor)(
static_cast<Node&&
>(
n).
template ref_cast<array>());
792 case node_type::string:
793 if constexpr (can_visit<Func&&, Node&&, std::string>)
794 return static_cast<Func&&
>(visitor)(
795 static_cast<Node&&
>(
n).
template ref_cast<std::string>());
798 case node_type::integer:
799 if constexpr (can_visit<Func&&, Node&&, int64_t>)
800 return static_cast<Func&&
>(visitor)(
801 static_cast<Node&&
>(
n).
template ref_cast<int64_t>());
804 case node_type::floating_point:
805 if constexpr (can_visit<Func&&, Node&&, double>)
806 return static_cast<Func&&
>(visitor)(
static_cast<Node&&
>(
n).
template ref_cast<double>());
809 case node_type::boolean:
810 if constexpr (can_visit<Func&&, Node&&, bool>)
811 return static_cast<Func&&
>(visitor)(
static_cast<Node&&
>(
n).
template ref_cast<bool>());
814 case node_type::date:
815 if constexpr (can_visit<Func&&, Node&&, date>)
816 return static_cast<Func&&
>(visitor)(
static_cast<Node&&
>(
n).
template ref_cast<date>());
819 case node_type::time:
820 if constexpr (can_visit<Func&&, Node&&, time>)
821 return static_cast<Func&&
>(visitor)(
static_cast<Node&&
>(
n).
template ref_cast<time>());
824 case node_type::date_time:
825 if constexpr (can_visit<Func&&, Node&&, date_time>)
826 return static_cast<Func&&
>(visitor)(
827 static_cast<Node&&
>(
n).
template ref_cast<date_time>());
830 case node_type::none:
836 if constexpr (!can_visit_all<Func&&, Node&&>) {
840 nonvoid<visit_return_type<Func&&, Node&&, table>,
841 nonvoid<visit_return_type<Func&&, Node&&, array>,
842 nonvoid<visit_return_type<Func&&, Node&&, std::string>,
843 nonvoid<visit_return_type<Func&&, Node&&, int64_t>,
844 nonvoid<visit_return_type<Func&&, Node&&, double>,
845 nonvoid<visit_return_type<Func&&, Node&&, bool>,
846 nonvoid<visit_return_type<Func&&, Node&&, date>,
847 nonvoid<visit_return_type<Func&&, Node&&, time>,
848 visit_return_type<Func&&, Node&&, date_time>
853 if constexpr (!std::is_void_v<return_type>) {
855 std::is_default_constructible_v<return_type>,
856 "Non-exhaustive visitors must return a default-constructible type, or void");
857 return return_type{};
899 template <
typename Func>
900 decltype(
auto) visit(Func&& visitor) &
noexcept(visit_is_nothrow<Func&&, node&>) {
901 return do_visit(
static_cast<Func&&
>(visitor), *
this);
905 template <
typename Func>
906 decltype(
auto) visit(Func&& visitor) &&
noexcept(visit_is_nothrow<Func&&, node&&>) {
907 return do_visit(
static_cast<Func&&
>(visitor),
static_cast<node&&
>(*
this));
912 template <
typename Func>
913 decltype(
auto) visit(Func&& visitor)
const&
noexcept(visit_is_nothrow<Func&&, const node&>) {
914 return do_visit(
static_cast<Func&&
>(visitor), *
this);
919 template <
typename Func>
920 decltype(
auto) visit(Func&& visitor)
const&&
noexcept(visit_is_nothrow<Func&&, const node&&>) {
921 return do_visit(
static_cast<Func&&
>(visitor),
static_cast<const node&&
>(*
this));
931 explicit operator node_view<node>()
noexcept;
935 explicit operator node_view<const node>()
const noexcept;
976 node_view<node>
at_path(std::string_view
path)
noexcept;
983 node_view<const node>
at_path(std::string_view
path)
const noexcept;
1026 node_view<node>
at_path(
const toml::path&
path)
noexcept;
1033 node_view<const node>
at_path(
const toml::path&
path)
const noexcept;
1035#if TOML_ENABLE_WINDOWS_COMPAT
1053 node_view<const node>
at_path(std::wstring_view
path)
const;
1066 node_view<node> operator[](
const toml::path&
path)
noexcept;
1077 node_view<const node> operator[](
const toml::path&
path)
const noexcept;
1088 bool TOML_CALLCONV node_deep_equality(
const node*,
const node*)
noexcept;
TOML_NODISCARD TOML_EXPORTED_FREE_FUNCTION node_view< const node > TOML_CALLCONV at_path(const node &root, std::string_view path) noexcept
Returns a const view of the node matching a fully-qualified "TOML path".
constexpr bool is_number
Metafunction for determining if a type satisfies either toml::is_integer or toml::is_floating_point.
constexpr bool is_boolean
Metafunction for determining if a type is, or is a reference to, a bool or toml::value<bool>.
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>.
constexpr bool is_string
Metafunction for determining if a type is, or is a reference to, a std::string or toml::value<std::st...
constexpr bool is_array
Metafunction for determining if a type is, or is a reference to, a toml::array.
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...
constexpr bool is_integer
Metafunction for determining if a type is, or is a reference to, a int64_t or toml::value<int64_t>.
constexpr bool is_time
Metafunction for determining if a type is, or is a reference to, a toml::time or toml::value<time>.
constexpr bool is_value
Metafunction for determining if a type is, or is a reference to, any of the toml value types....
#define TOML_CALLCONV
Calling convention to apply to exported free/static functions. \detail Not defined by default (let th...
#define TOML_EXPORTED_CLASS
An 'export' annotation to add to classes. \detail Not defined by default.
#define TOML_ASSERT_ASSUME(expr)
#define TOML_EXPORTED_FREE_FUNCTION
An 'export' annotation to add to free functions. \detail Not defined by default.
#define TOML_EXPORTED_MEMBER_FUNCTION
An 'export' annotation to add to non-static class member functions. \detail Not defined by default.
#define TOML_PURE_INLINE_GETTER
#define TOML_IMPL_NAMESPACE_END
#define TOML_IMPL_NAMESPACE_START
#define TOML_ABSTRACT_INTERFACE
A source document region.