25#include <initializer_list>
43class borrowed_subtree;
55template <
typename T,
typename E>
56struct is_expected<
std::expected<T, E>> :
61inline constexpr bool is_expected_v = is_expected<T>::value;
64struct expected_value_or_self
69template <
typename T,
typename E>
70struct expected_value_or_self<
std::expected<T, E>>
76using expected_value_or_self_t =
typename expected_value_or_self<T>::type;
86 public std::runtime_error
130 std::string _message;
131 std::exception_ptr _cause;
134 using problem_list = std::vector<problem>;
169 template <
typename...
TArgs>
173 problem_list _problems;
180 using size_type = extraction_error::problem_list::size_type;
265 on_error _failure_mode = on_error::fail_immediately;
266 size_type _max_failures = 10U;
267 duplicate_key_action _on_duplicate_key = duplicate_key_action::replace;
315 using problem_list = extraction_error::problem_list;
330 std::optional<jsonv::version>
ver = std::nullopt,
379 template <
typename...
TArgs>
383 _problems.emplace_back(std::forward<TArgs>(
args)...);
384 return std::unexpected(ast_node_type::error);
392 problem_list&& problems() && {
return std::move(_problems); }
441 problem_list take_problems_since(problem_list::size_type
mark);
471 return std::unexpected(
matched.error());
493 template <
typename T>
497 alignas(T) std::byte
place[
sizeof(T)];
499 return std::unexpected(
result.error());
501 T* ptr = std::launder(
reinterpret_cast<T*
>(
place));
502 auto destroy = detail::on_scope_exit([ptr] { std::destroy_at(ptr); });
503 return std::move(*ptr);
520 template <
typename T>
524 alignas(T) std::byte
place[
sizeof(T)];
526 T* ptr = std::launder(
reinterpret_cast<T*
>(
place));
527 auto destroy = detail::on_scope_exit([ptr] { std::destroy_at(ptr); });
528 return std::move(*ptr);
539 template <
typename T>
543 alignas(T) std::byte
place[
sizeof(T)];
544 extract_sub(
typeid(T),
from, std::move(
subpath),
static_cast<void*
>(
place));
545 T* ptr = std::launder(
reinterpret_cast<T*
>(
place));
546 auto destroy = detail::on_scope_exit([ptr] { std::destroy_at(ptr); });
547 return std::move(*ptr);
552 template <
typename T>
613 jsonv::
path _base_path;
615 std::
size_t _materialised_depth = 0
U;
622 problem_list _problems;
666 borrowed_subtree(
const borrowed_subtree&) =
delete;
667 borrowed_subtree& operator=(
const borrowed_subtree&) =
delete;
669 ~borrowed_subtree()
noexcept;
672 const value& get()
const noexcept {
return _borrowed ? *_borrowed : _owned; }
681 const value* _borrowed;
684 int _uncaught_on_entry;
694template <
typename T,
typename FExtract>
700 if constexpr (is_expected_v<std::remove_cvref_t<
decltype(
result)>>)
703 return std::move(
result).value();
705 return std::unexpected(
result.error());
709 return std::forward<decltype(result)>(
result);
713 if constexpr (std::invocable<const FExtract&, extraction_context&, reader&>)
717 else if constexpr (std::invocable<const FExtract&, reader&>)
721 else if constexpr (std::invocable<const FExtract&, extraction_context&, const value&>)
733 static_assert(std::invocable<const FExtract&, const value&>,
734 "An extraction function must be callable as (extraction_context&, reader&), (reader&), "
735 "(extraction_context&, const value&) or (const value&)"
748template <
typename FExtract>
749struct extract_function_result
753 if constexpr (std::invocable<const FExtract&, extraction_context&, reader&>)
754 return std::type_identity<std::invoke_result_t<const FExtract&, extraction_context&, reader&>>();
755 else if constexpr (std::invocable<const FExtract&, reader&>)
756 return std::type_identity<std::invoke_result_t<const FExtract&, reader&>>();
757 else if constexpr (std::invocable<const FExtract&, extraction_context&, const value&>)
758 return std::type_identity<std::invoke_result_t<const FExtract&, extraction_context&, const value&>>();
760 return std::type_identity<std::invoke_result_t<const FExtract&, const value&>>();
763 using type = expected_value_or_self_t<std::remove_cvref_t<
typename decltype(deduce())::type>>;
766template <
typename FExtract>
767using extract_function_result_t =
typename extract_function_result<FExtract>::type;
Utilities for directly dealing with a JSON AST.
Provides extra information to routines used for extraction and serialization.
An adapter for enumeration types.
Represents an exact path in some JSON structure.
A reader instance reads from some form of JSON source (probably a string) and converts it into a JSON...
Represents a single JSON value, which can be any one of a potential kind, each behaving slightly diff...
Copyright (c) 2014-2020 by Travis Gockel.
#define JSONV_NODISCARD
Warn if the caller discards the result of this function.
#define JSONV_PUBLIC
This function or class is part of the public API for JSON Voorhees.
Copyright (c) 2015-2020 by Travis Gockel.
T extract(const value &from, const formats &fmts)
Extract a C++ value from from using the provided fmts.
@ exception
A duplicate_type_error should be thrown.
@ ignore
The existing extractor or serializer should be kept, but no exception should be thrown.
@ replace
The new extractor or serializer should be inserted, and no exception should be thrown.
ast_node_type
Marker type for an encountered token type.
Definition of the on_scope_exit utility.
Copyright (c) 2012-2020 by Travis Gockel.