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>;
53 template<
typename ParseState>
54 [[nodiscard]]
constexpr zstring_policy_t<ParseState>
55 to_zstring_state( ParseState
const &state ) {
56 return zstring_policy_t<ParseState>( state.first,
73 template<
typename JsonElement,
typename ParseState,
typename =
void>
76 static constexpr ParseState
get_range( daw::string_view data,
77 daw::string_view member_path ) {
78 auto [result, is_found] = json_details::find_range<ParseState>(
79 data, { std::data( member_path ), std::size( member_path ) } );
82 result.front( ) ==
'[', ErrorReason::InvalidArrayStart, result );
88 static_assert( not std::is_same_v<element_type, void>,
89 "Unknown JsonElement type." );
90 using value_type = json_details::json_result_t<element_type>;
92 using pointer = json_details::arrow_proxy<value_type>;
98 ParseState m_state = ParseState( );
103 mutable char const *m_can_skip =
nullptr;
105 static constexpr bool can_use_zstring =
106 json_details::can_use_runtime_zstring_v<ParseState, daw::string_view>;
109 bool m_is_zstring =
false;
111 template<
typename State>
113 auto const run_after_parse =
114 json_details::assign_on_dtor{ m_can_skip, tmp.first };
115 (void)run_after_parse;
116 return json_details::
117 parse_value<element_type, false, element_type::expected_type>( tmp );
124 : m_state( ParseState(
std::data( jd ),
daw::data_end( jd ) ) )
125 , m_is_zstring( json_details::is_runtime_zstring<ParseState>( jd ) ) {
127 m_state.trim_left( );
129 ErrorReason::InvalidArrayStart,
132 m_state.remove_prefix( );
133 m_state.trim_left( );
135 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
139 daw::string_view start_path )
140 : m_state( get_range( jd, start_path ) )
141 , m_is_zstring( json_details::is_runtime_zstring<ParseState>( jd ) ) {
143 m_state.trim_left( );
145 ErrorReason::InvalidArrayStart,
148 m_state.remove_prefix( );
149 m_state.trim_left( );
151 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
169 ErrorReason::UnexpectedEndOfData,
172 if constexpr( can_use_zstring ) {
174 return parse_current( json_details::to_zstring_state( m_state ) );
177 return parse_current( m_state );
186 return pointer{ operator*( ) };
195 ErrorReason::UnexpectedEndOfData,
197 if constexpr( can_use_zstring ) {
199 auto state = json_details::to_zstring_state( m_state );
201 m_state.first = state.first;
205 move_next( m_state );
210 template<
typename State>
213 state.first = m_can_skip;
214 m_can_skip =
nullptr;
216 (void)json_details::skip_known_value<element_type>( state );
220 state.is_at_next_array_element( ),
221 ErrorReason::UnexpectedEndOfData,
224 state.move_next_member_or_end( );
227 state.has_more( ), ErrorReason::UnexpectedEndOfData, state );
243 [[nodiscard]]
constexpr bool good( )
const {
244 return not m_state.is_null( ) and m_state.has_more( ) and
245 m_state.front( ) !=
']';
250 [[nodiscard]]
explicit constexpr operator bool( )
const {
257 [[nodiscard]]
constexpr bool
259 auto const not_lhs = not( *
this );
260 auto const not_rhs = not( rhs );
267 return ( m_state.first == rhs.
m_state.first );
273 [[nodiscard]]
constexpr bool
276 return static_cast<bool>( rhs );
281 return m_state.first != rhs.
m_state.first;
285 template<
typename JsonElement,
auto... PolicyFlags>
289 options::details::make_parse_flags<PolicyFlags...>( ).value>>>;
298 template<
typename JsonElement,
auto... PolicyFlags>
301 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
304 daw::string_view member_path ) {
305 auto [result, is_found] = json_details::find_range<ParseState>(
306 data, { std::data( member_path ), std::size( member_path ) } );
309 result.front( ) ==
'[', ErrorReason::InvalidArrayStart, result );
315 static_assert( not std::is_same_v<element_type, void>,
316 "Unknown JsonElement type." );
317 using value_type = json_details::json_result_t<element_type>;
319 using pointer = json_details::arrow_proxy<value_type>;
325 static constexpr bool can_use_zstring =
326 json_details::can_use_runtime_zstring_v<ParseState, daw::string_view>;
329 bool m_is_zstring =
false;
336 , m_is_zstring( json_details::is_runtime_zstring<
ParseState>( jd ) ) {
338 m_state.trim_left( );
340 ErrorReason::InvalidArrayStart,
343 m_state.remove_prefix( );
344 m_state.trim_left( );
346 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
350 daw::string_view start_path )
351 : m_state( get_range( jd, start_path ) )
352 , m_is_zstring( json_details::is_runtime_zstring<
ParseState>( jd ) ) {
354 m_state.trim_left( );
356 ErrorReason::InvalidArrayStart,
359 m_state.remove_prefix( );
360 m_state.trim_left( );
362 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
370 ErrorReason::UnexpectedEndOfData,
373 if constexpr( can_use_zstring ) {
375 auto state = json_details::to_zstring_state( m_state );
376 auto const run_after_parse =
377 json_details::assign_on_dtor{ m_state.first, state.first };
378 (void)run_after_parse;
379 return json_details::
380 parse_value<element_type, false, element_type::expected_type>(
384 return json_details::
385 parse_value<element_type, false, element_type::expected_type>(
395 m_state.is_at_next_array_element( ),
396 ErrorReason::UnexpectedEndOfData,
398 if constexpr( can_use_zstring ) {
400 auto state = json_details::to_zstring_state( m_state );
401 state.move_next_member_or_end( );
402 m_state.first = state.first;
404 m_state.move_next_member_or_end( );
407 m_state.move_next_member_or_end( );
410 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
425 [[nodiscard]]
constexpr bool good( )
const {
426 return not m_state.is_null( ) and m_state.has_more( ) and
427 m_state.front( ) !=
']';
432 [[nodiscard]]
explicit constexpr operator bool( )
const {
439 [[nodiscard]]
constexpr bool
441 auto const not_lhs = not( *
this );
442 auto const not_rhs = not( rhs );
449 return ( m_state.first == rhs.
m_state.first );
455 [[nodiscard]]
constexpr bool
457 auto const not_lhs = not( *
this );
458 auto const not_rhs = not( rhs );
465 return m_state.first != rhs.
m_state.first;
471 template<
typename JsonElement,
auto... PolicyFlags>
474 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
488 daw::string_view start_path )
489 : m_first( jd, start_path ) {}
503 [[nodiscard]]
constexpr bool empty( )
const {
504 return m_first == m_last;
511 template<
typename JsonElement,
auto... PolicyFlags>
514 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
528 daw::string_view start_path )
529 : m_first( jd, start_path ) {}
543 [[nodiscard]]
constexpr bool empty( )
const {
544 return m_first == m_last;
Iterator for iterating over JSON arrays. Requires that operator* and operator++ be called in that seq...
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 value_type parse_current(State tmp) const
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 void move_next(State &state)
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
string_writer grows its string with resize_and_overwrite, leaving the new bytes uninitialized,...
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.