6 #include <nlohmann/detail/exceptions.hpp>
7 #include <nlohmann/detail/iterators/internal_iterator.hpp>
8 #include <nlohmann/detail/iterators/primitive_iterator.hpp>
9 #include <nlohmann/detail/macro_scope.hpp>
10 #include <nlohmann/detail/meta/cpp_future.hpp>
11 #include <nlohmann/detail/meta/type_traits.hpp>
12 #include <nlohmann/detail/value_t.hpp>
19 template<
typename IteratorType>
class iteration_proxy;
20 template<
typename IteratorType>
class iteration_proxy_value;
38 template<
typename BasicJsonType>
49 using object_t =
typename BasicJsonType::object_t;
50 using array_t =
typename BasicJsonType::array_t;
53 "iter_impl only accepts (const) basic_json");
69 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
70 typename BasicJsonType::const_pointer,
71 typename BasicJsonType::pointer>::type;
74 typename std::conditional<std::is_const<BasicJsonType>::value,
75 typename BasicJsonType::const_reference,
76 typename BasicJsonType::reference>::type;
91 JSON_ASSERT(m_object !=
nullptr);
93 switch (m_object->m_type)
140 : m_object(other.m_object),
m_it(other.m_it)
153 m_object = other.m_object;
165 : m_object(other.m_object),
m_it(other.m_it)
176 m_object = other.m_object;
181 JSON_PRIVATE_UNLESS_TESTED:
186 void set_begin() noexcept
188 JSON_ASSERT(m_object !=
nullptr);
190 switch (m_object->m_type)
232 JSON_ASSERT(m_object !=
nullptr);
234 switch (m_object->m_type)
271 JSON_ASSERT(m_object !=
nullptr);
273 switch (m_object->m_type)
288 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
304 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
315 JSON_ASSERT(m_object !=
nullptr);
317 switch (m_object->m_type)
346 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
368 JSON_ASSERT(m_object !=
nullptr);
370 switch (m_object->m_type)
419 JSON_ASSERT(m_object !=
nullptr);
421 switch (m_object->m_type)
457 template <
typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::
nullptr_t > =
nullptr >
461 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
463 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
466 JSON_ASSERT(m_object !=
nullptr);
468 switch (m_object->m_type)
493 template <
typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::
nullptr_t > =
nullptr >
506 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
508 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
511 JSON_ASSERT(m_object !=
nullptr);
513 switch (m_object->m_type)
516 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", *m_object));
540 return !other.operator < (*this);
567 JSON_ASSERT(m_object !=
nullptr);
569 switch (m_object->m_type)
572 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
646 JSON_ASSERT(m_object !=
nullptr);
648 switch (m_object->m_type)
651 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
675 JSON_ASSERT(m_object !=
nullptr);
677 switch (m_object->m_type)
680 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", *m_object));
686 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
702 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
711 const typename object_t::key_type&
key()
const
713 JSON_ASSERT(m_object !=
nullptr);
715 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
720 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", *m_object));
732 JSON_PRIVATE_UNLESS_TESTED:
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
Definition: iter_impl.hpp:40
bool operator<(const iter_impl &other) const
comparison: smaller
Definition: iter_impl.hpp:503
iter_impl operator-(difference_type i) const
subtract from iterator
Definition: iter_impl.hpp:633
const object_t::key_type & key() const
return the key of an object iterator
Definition: iter_impl.hpp:711
bool operator!=(const IterImpl &other) const
comparison: not equal
Definition: iter_impl.hpp:494
iter_impl const operator--(int)
post-decrement (it–)
Definition: iter_impl.hpp:406
void set_end() noexcept
set the iterator past the last value
Definition: iter_impl.hpp:230
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition: iter_impl.hpp:67
iter_impl & operator+=(difference_type i)
add to iterator
Definition: iter_impl.hpp:565
difference_type operator-(const iter_impl &other) const
return difference
Definition: iter_impl.hpp:644
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference >::type reference
defines a reference to the type iterated over (value_type)
Definition: iter_impl.hpp:76
reference operator*() const
return a reference to the value pointed to by the iterator
Definition: iter_impl.hpp:269
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition: iter_impl.hpp:556
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer >::type pointer
defines a pointer to the type iterated over (value_type)
Definition: iter_impl.hpp:71
pointer operator->() const
dereference the iterator
Definition: iter_impl.hpp:313
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition: iter_impl.hpp:174
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition: iter_impl.hpp:139
iter_impl const operator++(int)
post-increment (it++)
Definition: iter_impl.hpp:355
iter_impl & operator--()
pre-decrement (–it)
Definition: iter_impl.hpp:417
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition: iter_impl.hpp:164
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: iter_impl.hpp:736
iter_impl operator+(difference_type i) const
add to iterator
Definition: iter_impl.hpp:611
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition: iter_impl.hpp:622
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition: iter_impl.hpp:149
bool operator==(const IterImpl &other) const
comparison: equal
Definition: iter_impl.hpp:458
bool operator>(const iter_impl &other) const
comparison: greater than
Definition: iter_impl.hpp:547
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition: iter_impl.hpp:65
reference value() const
return the value of an iterator
Definition: iter_impl.hpp:727
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition: iter_impl.hpp:602
iter_impl & operator++()
pre-increment (++it)
Definition: iter_impl.hpp:366
reference operator[](difference_type n) const
access to successor
Definition: iter_impl.hpp:673
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition: iter_impl.hpp:538
std::bidirectional_iterator_tag iterator_category
The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17.
Definition: iter_impl.hpp:62
Definition: iteration_proxy.hpp:24
proxy class for the items() function
Definition: iteration_proxy.hpp:122
Definition: primitive_iterator.hpp:22
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition: primitive_iterator.hpp:51
void set_begin() noexcept
set iterator to a defined beginning
Definition: primitive_iterator.hpp:39
void set_end() noexcept
set iterator to a defined past the end
Definition: primitive_iterator.hpp:45
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)
namespace for Niels Lohmann
Definition: adl_serializer.hpp:12
an iterator value
Definition: internal_iterator.hpp:16
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: internal_iterator.hpp:22
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: internal_iterator.hpp:20
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: internal_iterator.hpp:18
Definition: type_traits.hpp:42