7 #include <nlohmann/detail/exceptions.hpp>
8 #include <nlohmann/detail/iterators/internal_iterator.hpp>
9 #include <nlohmann/detail/iterators/primitive_iterator.hpp>
10 #include <nlohmann/detail/macro_scope.hpp>
11 #include <nlohmann/detail/meta.hpp>
12 #include <nlohmann/detail/value_t.hpp>
41 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;
89 assert(m_object !=
nullptr);
91 switch (m_object->m_type)
128 : m_object(other.m_object), m_it(other.m_it) {}
138 m_object = other.m_object;
148 void set_begin() noexcept
150 assert(m_object !=
nullptr);
152 switch (m_object->m_type)
185 void set_end() noexcept
187 assert(m_object !=
nullptr);
189 switch (m_object->m_type)
218 assert(m_object !=
nullptr);
220 switch (m_object->m_type)
235 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
244 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
255 assert(m_object !=
nullptr);
257 switch (m_object->m_type)
278 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
300 assert(m_object !=
nullptr);
302 switch (m_object->m_type)
343 assert(m_object !=
nullptr);
345 switch (m_object->m_type)
376 if (JSON_UNLIKELY(m_object != other.m_object))
378 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
381 assert(m_object !=
nullptr);
383 switch (m_object->m_type)
412 if (JSON_UNLIKELY(m_object != other.m_object))
414 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
417 assert(m_object !=
nullptr);
419 switch (m_object->m_type)
422 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators"));
438 return not other.operator < (*this);
465 assert(m_object !=
nullptr);
467 switch (m_object->m_type)
470 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
536 assert(m_object !=
nullptr);
538 switch (m_object->m_type)
541 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
557 assert(m_object !=
nullptr);
559 switch (m_object->m_type)
562 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators"));
568 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
577 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
586 typename object_t::key_type
key()
const
588 assert(m_object !=
nullptr);
590 if (JSON_LIKELY(m_object->is_object()))
595 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators"));
difference_type operator-(const iter_impl &other) const
return difference
Definition: iter_impl.hpp:534
pointer operator->() const
dereference the iterator
Definition: iter_impl.hpp:253
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition: iter_impl.hpp:127
iter_impl & operator--()
pre-decrement (–it)
Definition: iter_impl.hpp:341
const iter_impl operator++(int)
post-increment (it++)
Definition: iter_impl.hpp:287
bool operator==(const iter_impl &other) const
comparison: equal
Definition: iter_impl.hpp:373
object (unordered set of name/value pairs)
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: internal_iterator.hpp:18
namespace for Niels Lohmann
Definition: adl_serializer.hpp:8
void set_end() noexcept
set iterator to a defined past the end
Definition: primitive_iterator.hpp:42
iter_impl operator-(difference_type i) const
subtract from iterator
Definition: iter_impl.hpp:523
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
object_t::key_type key() const
return the key of an object iterator
Definition: iter_impl.hpp:586
bool operator!=(const iter_impl &other) const
comparison: not equal
Definition: iter_impl.hpp:400
void set_begin() noexcept
set iterator to a defined beginning
Definition: primitive_iterator.hpp:36
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition: primitive_iterator.hpp:48
a template for a bidirectional iterator for the basic_json class
Definition: iter_impl.hpp:42
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: internal_iterator.hpp:20
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
iter_impl & operator++()
pre-increment (++it)
Definition: iter_impl.hpp:298
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition: iter_impl.hpp:454
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition: iter_impl.hpp:436
reference operator*() const
return a reference to the value pointed to by the iterator
Definition: iter_impl.hpp:216
bool operator<(const iter_impl &other) const
comparison: smaller
Definition: iter_impl.hpp:409
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: internal_iterator.hpp:22
array (ordered collection of values)
Definition: primitive_iterator.hpp:19
iter_impl(pointer object) noexcept
constructor for a given JSON instance
Definition: iter_impl.hpp:87
iter_impl()=default
default constructor
Definition: iter_impl.hpp:45
bool operator>(const iter_impl &other) const
comparison: greater than
Definition: iter_impl.hpp:445
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition: iter_impl.hpp:512
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition: iter_impl.hpp:136
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition: iter_impl.hpp:492
an iterator value
Definition: internal_iterator.hpp:15
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition: iter_impl.hpp:65
iter_impl operator+(difference_type i) const
add to iterator
Definition: iter_impl.hpp:501
reference operator[](difference_type n) const
access to successor
Definition: iter_impl.hpp:555
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition: iter_impl.hpp:67
proxy class for the items() function
Definition: iter_impl.hpp:19
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
const iter_impl operator--(int)
post-decrement (it–)
Definition: iter_impl.hpp:330
reference value() const
return the value of an iterator
Definition: iter_impl.hpp:602
iter_impl & operator+=(difference_type i)
add to iterator
Definition: iter_impl.hpp:463