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>;
64 template<
typename JsonElement,
typename ParseState,
typename =
void>
67 static constexpr ParseState
get_range( daw::string_view data,
68 daw::string_view member_path ) {
69 auto [result, is_found] = json_details::find_range<ParseState>(
70 data, { std::data( member_path ), std::size( member_path ) } );
73 result.front( ) ==
'[', ErrorReason::InvalidArrayStart, result );
79 static_assert( not std::is_same_v<element_type, void>,
80 "Unknown JsonElement type." );
81 using value_type = json_details::json_result_t<element_type>;
83 using pointer = json_details::arrow_proxy<value_type>;
89 ParseState m_state = ParseState( );
94 mutable char const *m_can_skip =
nullptr;
100 : m_state( ParseState(
std::data( jd ),
daw::data_end( jd ) ) ) {
102 m_state.trim_left( );
104 ErrorReason::InvalidArrayStart,
107 m_state.remove_prefix( );
108 m_state.trim_left( );
110 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
114 daw::string_view start_path )
115 : m_state( get_range( jd, start_path ) ) {
117 m_state.trim_left( );
119 ErrorReason::InvalidArrayStart,
122 m_state.remove_prefix( );
123 m_state.trim_left( );
125 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
143 ErrorReason::UnexpectedEndOfData,
148 auto const run_after_parse =
149 json_details::assign_on_dtor{ m_can_skip, tmp.first };
150 (void)run_after_parse;
151 return json_details::
152 parse_value<element_type, false, element_type::expected_type>( tmp );
161 return pointer{ operator*( ) };
170 ErrorReason::UnexpectedEndOfData,
173 m_state.first = m_can_skip;
174 m_can_skip =
nullptr;
176 (void)json_details::skip_known_value<element_type>( m_state );
178 m_state.trim_left( );
180 m_state.is_at_next_array_element( ),
181 ErrorReason::UnexpectedEndOfData,
184 m_state.move_next_member_or_end( );
185 m_state.trim_left( );
187 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
203 [[nodiscard]]
constexpr bool good( )
const {
204 return not m_state.is_null( ) and m_state.has_more( ) and
205 m_state.front( ) !=
']';
210 [[nodiscard]]
explicit constexpr operator bool( )
const {
217 [[nodiscard]]
constexpr bool
219 auto const not_lhs = not( *
this );
220 auto const not_rhs = not( rhs );
227 return ( m_state.first == rhs.
m_state.first );
233 [[nodiscard]]
constexpr bool
236 return static_cast<bool>( rhs );
241 return m_state.first != rhs.
m_state.first;
245 template<
typename JsonElement,
auto... PolicyFlags>
249 options::details::make_parse_flags<PolicyFlags...>( ).value>>>;
258 template<
typename JsonElement,
auto... PolicyFlags>
261 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
264 daw::string_view member_path ) {
265 auto [result, is_found] = json_details::find_range<ParseState>(
266 data, { std::data( member_path ), std::size( member_path ) } );
269 result.front( ) ==
'[', ErrorReason::InvalidArrayStart, result );
275 static_assert( not std::is_same_v<element_type, void>,
276 "Unknown JsonElement type." );
277 using value_type = json_details::json_result_t<element_type>;
279 using pointer = json_details::arrow_proxy<value_type>;
291 m_state.trim_left( );
293 ErrorReason::InvalidArrayStart,
296 m_state.remove_prefix( );
297 m_state.trim_left( );
299 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
303 daw::string_view start_path )
304 : m_state( get_range( jd, start_path ) ) {
306 m_state.trim_left( );
308 ErrorReason::InvalidArrayStart,
311 m_state.remove_prefix( );
312 m_state.trim_left( );
314 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
322 ErrorReason::UnexpectedEndOfData,
325 return json_details::
326 parse_value<element_type, false, element_type::expected_type>(
336 m_state.is_at_next_array_element( ),
337 ErrorReason::UnexpectedEndOfData,
339 m_state.move_next_member_or_end( );
341 m_state.has_more( ), ErrorReason::UnexpectedEndOfData, m_state );
356 [[nodiscard]]
constexpr bool good( )
const {
357 return not m_state.is_null( ) and m_state.has_more( ) and
358 m_state.front( ) !=
']';
363 [[nodiscard]]
explicit constexpr operator bool( )
const {
370 [[nodiscard]]
constexpr bool
372 auto const not_lhs = not( *
this );
373 auto const not_rhs = not( rhs );
380 return ( m_state.first == rhs.
m_state.first );
386 [[nodiscard]]
constexpr bool
388 auto const not_lhs = not( *
this );
389 auto const not_rhs = not( rhs );
396 return m_state.first != rhs.
m_state.first;
402 template<
typename JsonElement,
auto... PolicyFlags>
405 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
419 daw::string_view start_path )
420 : m_first( jd, start_path ) {}
434 [[nodiscard]]
constexpr bool empty( )
const {
435 return m_first == m_last;
442 template<
typename JsonElement,
auto... PolicyFlags>
445 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
459 daw::string_view start_path )
460 : m_first( jd, start_path ) {}
474 [[nodiscard]]
constexpr bool empty( )
const {
475 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 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.