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>
47 using object_t =
typename BasicJsonType::object_t;
48 using array_t =
typename BasicJsonType::array_t;
51 "iter_impl only accepts (const) basic_json");
67 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
68 typename BasicJsonType::const_pointer,
69 typename BasicJsonType::pointer>::type;
72 typename std::conditional<std::is_const<BasicJsonType>::value,
73 typename BasicJsonType::const_reference,
74 typename BasicJsonType::reference>::type;
87 JSON_ASSERT(m_object !=
nullptr);
89 switch (m_object->m_type)
128 : m_object(other.m_object), m_it(other.m_it)
139 m_object = other.m_object;
150 : m_object(other.m_object), m_it(other.m_it)
161 m_object = other.m_object;
171 void set_begin() noexcept
173 JSON_ASSERT(m_object !=
nullptr);
175 switch (m_object->m_type)
208 void set_end() noexcept
210 JSON_ASSERT(m_object !=
nullptr);
212 switch (m_object->m_type)
241 JSON_ASSERT(m_object !=
nullptr);
243 switch (m_object->m_type)
253 JSON_ASSERT(m_it.
array_iterator != m_object->m_value.array->end());
258 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
267 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
278 JSON_ASSERT(m_object !=
nullptr);
280 switch (m_object->m_type)
290 JSON_ASSERT(m_it.
array_iterator != m_object->m_value.array->end());
301 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
323 JSON_ASSERT(m_object !=
nullptr);
325 switch (m_object->m_type)
366 JSON_ASSERT(m_object !=
nullptr);
368 switch (m_object->m_type)
399 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
401 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
404 JSON_ASSERT(m_object !=
nullptr);
406 switch (m_object->m_type)
435 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
437 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers"));
440 JSON_ASSERT(m_object !=
nullptr);
442 switch (m_object->m_type)
445 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators"));
461 return !other.operator < (*this);
488 JSON_ASSERT(m_object !=
nullptr);
490 switch (m_object->m_type)
493 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
559 JSON_ASSERT(m_object !=
nullptr);
561 switch (m_object->m_type)
564 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators"));
580 JSON_ASSERT(m_object !=
nullptr);
582 switch (m_object->m_type)
585 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators"));
591 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
600 JSON_THROW(invalid_iterator::create(214,
"cannot get value"));
609 const typename object_t::key_type&
key()
const
611 JSON_ASSERT(m_object !=
nullptr);
613 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
618 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators"));
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:432
iter_impl operator-(difference_type i) const
subtract from iterator
Definition: iter_impl.hpp:546
const object_t::key_type & key() const
return the key of an object iterator
Definition: iter_impl.hpp:609
iter_impl()=default
default constructor
Definition: iter_impl.hpp:42
iter_impl const operator--(int)
post-decrement (it–)
Definition: iter_impl.hpp:353
bool operator==(const iter_impl &other) const
comparison: equal
Definition: iter_impl.hpp:396
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition: iter_impl.hpp:65
iter_impl & operator+=(difference_type i)
add to iterator
Definition: iter_impl.hpp:486
difference_type operator-(const iter_impl &other) const
return difference
Definition: iter_impl.hpp:557
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:74
reference operator*() const
return a reference to the value pointed to by the iterator
Definition: iter_impl.hpp:239
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition: iter_impl.hpp:477
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:69
pointer operator->() const
dereference the iterator
Definition: iter_impl.hpp:276
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition: iter_impl.hpp:159
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition: iter_impl.hpp:127
iter_impl const operator++(int)
post-increment (it++)
Definition: iter_impl.hpp:310
iter_impl & operator--()
pre-decrement (–it)
Definition: iter_impl.hpp:364
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition: iter_impl.hpp:149
iter_impl(pointer object) noexcept
constructor for a given JSON instance
Definition: iter_impl.hpp:85
iter_impl operator+(difference_type i) const
add to iterator
Definition: iter_impl.hpp:524
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition: iter_impl.hpp:535
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition: iter_impl.hpp:137
bool operator>(const iter_impl &other) const
comparison: greater than
Definition: iter_impl.hpp:468
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition: iter_impl.hpp:63
reference value() const
return the value of an iterator
Definition: iter_impl.hpp:625
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition: iter_impl.hpp:515
iter_impl & operator++()
pre-increment (++it)
Definition: iter_impl.hpp:321
reference operator[](difference_type n) const
access to successor
Definition: iter_impl.hpp:578
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition: iter_impl.hpp:459
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:60
bool operator!=(const iter_impl &other) const
comparison: not equal
Definition: iter_impl.hpp:423
Definition: iteration_proxy.hpp:23
proxy class for the items() function
Definition: iteration_proxy.hpp:111
Definition: primitive_iterator.hpp:20
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition: primitive_iterator.hpp:48
void set_begin() noexcept
set iterator to a defined beginning
Definition: primitive_iterator.hpp:36
void set_end() noexcept
set iterator to a defined past the end
Definition: primitive_iterator.hpp:42
@ object
object (unordered set of name/value pairs)
@ array
array (ordered collection of values)
namespace for Niels Lohmann
Definition: adl_serializer.hpp:9
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:38