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/cpp_future.hpp>
12 #include <nlohmann/detail/meta/type_traits.hpp>
13 #include <nlohmann/detail/value_t.hpp>
20 template<
typename IteratorType>
class iteration_proxy;
21 template<
typename IteratorType>
class iteration_proxy_value;
39 template<
typename BasicJsonType>
48 using object_t =
typename BasicJsonType::object_t;
49 using array_t =
typename BasicJsonType::array_t;
52 "iter_impl only accepts (const) basic_json");
68 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
69 typename BasicJsonType::const_pointer,
70 typename BasicJsonType::pointer>::type;
73 typename std::conditional<std::is_const<BasicJsonType>::value,
74 typename BasicJsonType::const_reference,
75 typename BasicJsonType::reference>::type;
88 assert(m_object !=
nullptr);
90 switch (m_object->m_type)
129 : m_object(other.m_object), m_it(other.m_it)
140 m_object = other.m_object;
151 : m_object(other.m_object), m_it(other.m_it)
162 m_object = other.m_object;
172 void set_begin() noexcept
174 assert(m_object !=
nullptr);
176 switch (m_object->m_type)
209 void set_end() noexcept
211 assert(m_object !=
nullptr);
213 switch (m_object->m_type)
242 assert(m_object !=
nullptr);
244 switch (m_object->m_type)
259 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
268 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
279 assert(m_object !=
nullptr);
281 switch (m_object->m_type)
302 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
324 assert(m_object !=
nullptr);
326 switch (m_object->m_type)
367 assert(m_object !=
nullptr);
369 switch (m_object->m_type)
400 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
402 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
405 assert(m_object !=
nullptr);
407 switch (m_object->m_type)
436 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
438 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
441 assert(m_object !=
nullptr);
443 switch (m_object->m_type)
446 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators"));
462 return not other.operator < (*this);
489 assert(m_object !=
nullptr);
491 switch (m_object->m_type)
494 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
560 assert(m_object !=
nullptr);
562 switch (m_object->m_type)
565 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
581 assert(m_object !=
nullptr);
583 switch (m_object->m_type)
586 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators"));
592 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
601 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
610 const typename object_t::key_type&
key()
const
612 assert(m_object !=
nullptr);
614 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
619 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:558
pointer operator->() const
dereference the iterator
Definition: iter_impl.hpp:277
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition: iter_impl.hpp:150
iter_impl & operator--()
pre-decrement (–it)
Definition: iter_impl.hpp:365
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition: iter_impl.hpp:138
iter_impl const operator--(int)
post-decrement (it–)
Definition: iter_impl.hpp:354
bool operator==(const iter_impl &other) const
comparison: equal
Definition: iter_impl.hpp:397
@ object
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:9
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:547
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:61
bool operator!=(const iter_impl &other) const
comparison: not equal
Definition: iter_impl.hpp:424
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 This class implements a both iterato...
Definition: iter_impl.hpp:41
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:75
iter_impl & operator++()
pre-increment (++it)
Definition: iter_impl.hpp:322
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition: iter_impl.hpp:478
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition: iter_impl.hpp:128
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition: iter_impl.hpp:460
iter_impl const operator++(int)
post-increment (it++)
Definition: iter_impl.hpp:311
reference operator*() const
return a reference to the value pointed to by the iterator
Definition: iter_impl.hpp:240
bool operator<(const iter_impl &other) const
comparison: smaller
Definition: iter_impl.hpp:433
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: internal_iterator.hpp:22
@ array
array (ordered collection of values)
Definition: primitive_iterator.hpp:20
iter_impl(pointer object) noexcept
constructor for a given JSON instance
Definition: iter_impl.hpp:86
iter_impl()=default
default constructor
Definition: iter_impl.hpp:43
bool operator>(const iter_impl &other) const
comparison: greater than
Definition: iter_impl.hpp:469
Definition: type_traits.hpp:39
Definition: iteration_proxy.hpp:21
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition: iter_impl.hpp:536
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition: iter_impl.hpp:160
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition: iter_impl.hpp:516
an iterator value
Definition: internal_iterator.hpp:16
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition: iter_impl.hpp:64
iter_impl operator+(difference_type i) const
add to iterator
Definition: iter_impl.hpp:525
reference operator[](difference_type n) const
access to successor
Definition: iter_impl.hpp:579
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition: iter_impl.hpp:66
proxy class for the items() function
Definition: iteration_proxy.hpp:109
const object_t::key_type & key() const
return the key of an object iterator
Definition: iter_impl.hpp:610
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:70
reference value() const
return the value of an iterator
Definition: iter_impl.hpp:626
iter_impl & operator+=(difference_type i)
add to iterator
Definition: iter_impl.hpp:487