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>
30 #include <type_traits>
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>
62 using CharT =
typename ParseState::CharT;
64 static constexpr ParseState get_range( daw::string_view data,
65 daw::string_view member_path ) {
66 auto [result, is_found] = json_details::find_range<ParseState>(
68 { std::data( member_path ), std::size( member_path ) } );
70 daw_json_ensure( result.front( ) ==
'[', ErrorReason::InvalidArrayStart,
77 static_assert( not std::is_same_v<element_type, void>,
78 "Unknown JsonElement type." );
79 using value_type = json_details::json_result_t<element_type>;
81 using pointer = json_details::arrow_proxy<value_type>;
87 ParseState m_state = ParseState( );
92 mutable CharT *m_can_skip =
nullptr;
98 : m_state( ParseState(
std::data( jd ),
daw::data_end( jd ) ) ) {
100 m_state.trim_left( );
102 ErrorReason::InvalidArrayStart, m_state );
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, m_state );
116 m_state.remove_prefix( );
117 m_state.trim_left( );
135 ErrorReason::UnexpectedEndOfData, m_state );
139 auto const run_after_parse =
140 json_details::assign_on_dtor{ m_can_skip, tmp.first };
141 (void)run_after_parse;
143 element_type::expected_type>( tmp );
152 return pointer{ operator*( ) };
161 ErrorReason::UnexpectedEndOfData, m_state );
163 m_state.first = m_can_skip;
164 m_can_skip =
nullptr;
166 (void)json_details::skip_known_value<element_type>( m_state );
168 m_state.move_next_member_or_end( );
175 constexpr
void operator++(
int ) & {
183 [[nodiscard]] constexpr
bool good( )
const {
184 return not m_state.is_null( ) and m_state.has_more( ) and
185 m_state.front( ) !=
']';
190 [[nodiscard]]
explicit constexpr
operator bool( )
const {
197 [[nodiscard]] constexpr
bool
205 return ( m_state.first == rhs.
m_state.first );
211 [[nodiscard]] constexpr
bool
214 return static_cast<bool>( rhs );
219 return m_state.first != rhs.
m_state.first;
223 template<
typename JsonElement,
auto... PolicyFlags>
233 template<
typename JsonElement,
auto... PolicyFlags>
237 using CharT =
typename ParseState::CharT;
239 static constexpr
ParseState get_range( daw::string_view data,
240 daw::string_view member_path ) {
241 auto [result, is_found] = json_details::find_range<ParseState>(
243 { std::data( member_path ), std::size( member_path ) } );
245 daw_json_ensure( result.front( ) ==
'[', ErrorReason::InvalidArrayStart,
252 static_assert( not std::is_same_v<element_type, void>,
253 "Unknown JsonElement type." );
254 using value_type = json_details::json_result_t<element_type>;
256 using pointer = json_details::arrow_proxy<value_type>;
268 m_state.trim_left( );
270 ErrorReason::InvalidArrayStart, m_state );
272 m_state.remove_prefix( );
273 m_state.trim_left( );
277 daw::string_view start_path )
278 : m_state( get_range( jd, start_path ) ) {
280 m_state.trim_left( );
282 ErrorReason::InvalidArrayStart, m_state );
284 m_state.remove_prefix( );
285 m_state.trim_left( );
293 ErrorReason::UnexpectedEndOfData, m_state );
296 element_type::expected_type>(
306 ErrorReason::UnexpectedEndOfData, m_state );
307 m_state.move_next_member_or_end( );
314 constexpr
void operator++(
int ) & {
322 [[nodiscard]] constexpr
bool good( )
const {
323 return not m_state.is_null( ) and m_state.has_more( ) and
324 m_state.front( ) !=
']';
329 [[nodiscard]]
explicit constexpr
operator bool( )
const {
336 [[nodiscard]] constexpr
bool
339 return static_cast<bool>( rhs );
344 return ( m_state.first == rhs.
m_state.first );
350 [[nodiscard]] constexpr
bool
358 return m_state.first != rhs.
m_state.first;
365 template<
typename JsonElement,
auto... PolicyFlags>
370 using CharT =
typename ParsePolicy::CharT;
383 daw::string_view start_path )
384 : m_first( jd, start_path ) {}
398 [[nodiscard]] constexpr
bool empty( )
const {
399 return m_first == m_last;
407 template<
typename JsonElement,
auto... PolicyFlags>
412 using CharT =
typename ParsePolicy::CharT;
425 daw::string_view start_path )
426 : m_first( jd, start_path ) {}
440 [[nodiscard]] constexpr
bool empty( )
const {
441 return m_first == m_last;
Iterator for iterating over JSON array's. Requires that op op++ be called in that sequence one time u...
typename ParseState::CharT CharT
constexpr bool operator!=(json_array_iterator_once const &rhs) const
Check if the other iterator is not equivalent.
TryDefaultParsePolicy< BasicParsePolicy< options::details::make_parse_flags< PolicyFlags... >().value > > ParseState
json_details::json_result_t< element_type > value_type
json_array_iterator_once()=default
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.
std::ptrdiff_t difference_type
std::input_iterator_tag iterator_category
typename ParseState::CharT CharT
constexpr bool operator==(json_array_iterator_t const &rhs) const
Compare rhs for equivalence.
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
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
#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_CONSTEVAL auto make_parse_flags()
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...
json_array_range_once()=default
typename ParsePolicy::CharT CharT
TryDefaultParsePolicy< BasicParsePolicy< options::details::make_parse_flags< PolicyFlags... >().value > > ParsePolicy
A range of json_array_iterators.
typename ParsePolicy::CharT CharT
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.