17#include <daw/daw_cxmath.h>
18#include <daw/daw_move.h>
19#include <daw/daw_string_view.h>
20#include <daw/daw_traits.h>
21#include <daw/daw_utility.h>
34 namespace json_details {
36 struct assign_on_dtor {
40 DAW_ATTRIB_INLINE
constexpr assign_on_dtor( T &Lhs,
41 T
const &Rhs ) noexcept
51 assign_on_dtor( T
const &, T
const & ) -> assign_on_dtor<T>;
60 template<
typename JsonElement,
typename ParseState,
typename =
void>
63 static constexpr ParseState
get_range( daw::string_view data,
64 daw::string_view member_path ) {
65 auto [result, is_found] = json_details::find_range<ParseState>(
67 { std::data( member_path ), std::size( member_path ) } );
70 result.front( ) ==
'[', ErrorReason::InvalidArrayStart, result );
76 static_assert( not std::is_same_v<element_type, void>,
77 "Unknown JsonElement type." );
78 using value_type = json_details::json_result_t<element_type>;
80 using pointer = json_details::arrow_proxy<value_type>;
86 ParseState m_state = ParseState( );
91 mutable char const *m_can_skip =
nullptr;
97 : m_state( ParseState(
std::data( jd ),
daw::data_end( jd ) ) ) {
101 ErrorReason::InvalidArrayStart,
104 m_state.remove_prefix( );
105 m_state.trim_left( );
109 daw::string_view start_path )
110 : m_state( get_range( jd, start_path ) ) {
112 m_state.trim_left( );
114 ErrorReason::InvalidArrayStart,
117 m_state.remove_prefix( );
118 m_state.trim_left( );
136 ErrorReason::UnexpectedEndOfData,
141 auto const run_after_parse =
142 json_details::assign_on_dtor{ m_can_skip, tmp.first };
143 (void)run_after_parse;
144 return json_details::
145 parse_value<element_type, false, element_type::expected_type>( tmp );
154 return pointer{ operator*( ) };
163 ErrorReason::UnexpectedEndOfData,
166 m_state.first = m_can_skip;
167 m_can_skip =
nullptr;
169 (void)json_details::skip_known_value<element_type>( m_state );
171 m_state.move_next_member_or_end( );
186 [[nodiscard]]
constexpr bool good( )
const {
187 return not m_state.is_null( ) and m_state.has_more( ) and
188 m_state.front( ) !=
']';
193 [[nodiscard]]
explicit constexpr operator bool( )
const {
200 [[nodiscard]]
constexpr bool
208 return ( m_state.first == rhs.
m_state.first );
214 [[nodiscard]]
constexpr bool
217 return static_cast<bool>( rhs );
222 return m_state.first != rhs.
m_state.first;
226 template<
typename JsonElement,
auto... PolicyFlags>
230 options::details::make_parse_flags<PolicyFlags...>( ).value>>>;
236 template<
typename JsonElement,
auto... PolicyFlags>
239 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
242 daw::string_view member_path ) {
243 auto [result, is_found] = json_details::find_range<ParseState>(
245 { std::data( member_path ), std::size( member_path ) } );
248 result.front( ) ==
'[', ErrorReason::InvalidArrayStart, result );
254 static_assert( not std::is_same_v<element_type, void>,
255 "Unknown JsonElement type." );
256 using value_type = json_details::json_result_t<element_type>;
258 using pointer = json_details::arrow_proxy<value_type>;
270 m_state.trim_left( );
272 ErrorReason::InvalidArrayStart,
275 m_state.remove_prefix( );
276 m_state.trim_left( );
280 daw::string_view start_path )
281 : m_state( get_range( jd, start_path ) ) {
283 m_state.trim_left( );
285 ErrorReason::InvalidArrayStart,
288 m_state.remove_prefix( );
289 m_state.trim_left( );
297 ErrorReason::UnexpectedEndOfData,
300 return json_details::
301 parse_value<element_type, false, element_type::expected_type>(
311 ErrorReason::UnexpectedEndOfData,
313 m_state.move_next_member_or_end( );
328 [[nodiscard]]
constexpr bool good( )
const {
329 return not m_state.is_null( ) and m_state.has_more( ) and
330 m_state.front( ) !=
']';
335 [[nodiscard]]
explicit constexpr operator bool( )
const {
342 [[nodiscard]]
constexpr bool
345 return static_cast<bool>( rhs );
350 return ( m_state.first == rhs.
m_state.first );
356 [[nodiscard]]
constexpr bool
364 return m_state.first != rhs.
m_state.first;
371 template<
typename JsonElement,
auto... PolicyFlags>
374 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
388 daw::string_view start_path )
389 : m_first( jd, start_path ) {}
403 [[nodiscard]]
constexpr bool empty( )
const {
404 return m_first == m_last;
412 template<
typename JsonElement,
auto... PolicyFlags>
415 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
429 daw::string_view start_path )
430 : m_first( jd, start_path ) {}
444 [[nodiscard]]
constexpr bool empty( )
const {
445 return m_first == m_last;
Iterator for iterating over JSON array's. Requires that op op++ be called in that sequence one time u...
constexpr json_array_iterator_once & operator++()
constexpr bool operator!=(json_array_iterator_once const &rhs) const
Check if the other iterator is not equivalent.
constexpr bool good() const
constexpr void operator++(int) &
Move the parse state to the next element.
static constexpr ParseState get_range(daw::string_view data, daw::string_view member_path)
TryDefaultParsePolicy< BasicParsePolicy< options::details::make_parse_flags< PolicyFlags... >().value > > ParseState
json_details::json_result_t< element_type > value_type
json_array_iterator_once()=default
constexpr value_type operator*() const
Parse the current element.
constexpr json_array_iterator_once(daw::string_view jd)
std::ptrdiff_t difference_type
json_details::json_deduced_type< JsonElement > element_type
json_details::arrow_proxy< value_type > pointer
constexpr bool operator==(json_array_iterator_once const &rhs) const
Compare rhs for equivalence.
constexpr json_array_iterator_once(daw::string_view jd, daw::string_view start_path)
constexpr void operator++(int) &
Move the parse state to the next element.
constexpr bool good() const
std::ptrdiff_t difference_type
std::input_iterator_tag iterator_category
constexpr json_array_iterator_t begin() const
constexpr value_type operator*() const
Parse the current element.
constexpr bool operator==(json_array_iterator_t const &rhs) const
Compare rhs for equivalence.
static constexpr ParseState get_range(daw::string_view data, daw::string_view member_path)
constexpr json_array_iterator_t(daw::string_view jd)
json_array_iterator_t()=default
constexpr bool operator!=(json_array_iterator_t const &rhs) const
Check if the other iterator is not equivalent.
json_details::arrow_proxy< value_type > pointer
json_details::json_deduced_type< JsonElement > element_type
constexpr json_array_iterator_t end() const
pointer operator->() const
A dereferencable value proxy holding the result of operator* This is for compatibility with the Itera...
json_details::json_result_t< element_type > value_type
constexpr json_array_iterator_t(daw::string_view jd, daw::string_view start_path)
constexpr json_array_iterator_t & operator++()
#define daw_json_assert_weak(Bool,...)
Assert that Bool is true when in Checked Input mode If false pass rest of args to daw_json_error.
#define daw_json_ensure(Bool,...)
Ensure that Bool is true. If false pass rest of args to daw_json_error.
#define DAW_JSON_CPP20_CX_DTOR
daw::conditional_t< ParsePolicy::is_default_parse_policy, DefaultParsePolicy, ParsePolicy > TryDefaultParsePolicy
Customization point traits.
A range of json_array_iterator_onces. Requires that op*/op++ be called in that sequence one time unt...
constexpr iterator end() const
constexpr json_array_range_once(daw::string_view jd, daw::string_view start_path)
json_array_range_once()=default
TryDefaultParsePolicy< BasicParsePolicy< options::details::make_parse_flags< PolicyFlags... >().value > > ParsePolicy
constexpr iterator begin() const
constexpr json_array_range_once(daw::string_view jd)
constexpr bool empty() const
Are there any elements in range.
A range of json_array_iterators.
constexpr iterator end() const
constexpr json_array_range(daw::string_view jd)
constexpr bool empty() const
Are there any elements in range.
constexpr json_array_range(daw::string_view jd, daw::string_view start_path)
constexpr iterator begin() const
TryDefaultParsePolicy< BasicParsePolicy< options::details::make_parse_flags< PolicyFlags... >().value > > ParsePolicy
json_array_range()=default
Handles the bounds and policy items for parsing execution and comments.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.