All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
nlohmann::detail::iter_impl< BasicJsonType > Class Template Reference

a template for a bidirectional iterator for the basic_json class This class implements a both iterators (iterator and const_iterator) for the basic_json class. More...

#include <json.hpp>

Public Types

using iterator_category = std::bidirectional_iterator_tag
 
using value_type = typename BasicJsonType::value_type
 the type of the values when the iterator is dereferenced More...
 
using difference_type = typename BasicJsonType::difference_type
 a type to represent differences between iterators More...
 
using pointer = typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer >::type
 defines a pointer to the type iterated over (value_type) More...
 
using reference = typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference >::type
 defines a reference to the type iterated over (value_type) More...
 

Public Member Functions

 iter_impl ()=default
 default constructor More...
 
 iter_impl (pointer object) noexcept
 constructor for a given JSON instance More...
 
 iter_impl (const iter_impl< const BasicJsonType > &other) noexcept
 const copy constructor More...
 
iter_imploperator= (const iter_impl< const BasicJsonType > &other) noexcept
 converting assignment More...
 
 iter_impl (const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
 converting constructor More...
 
iter_imploperator= (const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
 converting assignment More...
 
reference operator* () const
 return a reference to the value pointed to by the iterator More...
 
pointer operator-> () const
 dereference the iterator More...
 
iter_impl const operator++ (int)
 post-increment (it++) More...
 
iter_imploperator++ ()
 pre-increment (++it) More...
 
iter_impl const operator-- (int)
 post-decrement (it–) More...
 
iter_imploperator-- ()
 pre-decrement (–it) More...
 
bool operator== (const iter_impl &other) const
 comparison: equal More...
 
bool operator!= (const iter_impl &other) const
 comparison: not equal More...
 
bool operator< (const iter_impl &other) const
 comparison: smaller More...
 
bool operator<= (const iter_impl &other) const
 comparison: less than or equal More...
 
bool operator> (const iter_impl &other) const
 comparison: greater than More...
 
bool operator>= (const iter_impl &other) const
 comparison: greater than or equal More...
 
iter_imploperator+= (difference_type i)
 add to iterator More...
 
iter_imploperator-= (difference_type i)
 subtract from iterator More...
 
iter_impl operator+ (difference_type i) const
 add to iterator More...
 
iter_impl operator- (difference_type i) const
 subtract from iterator More...
 
difference_type operator- (const iter_impl &other) const
 return difference More...
 
reference operator[] (difference_type n) const
 access to successor More...
 
const object_t::key_type & key () const
 return the key of an object iterator More...
 
reference value () const
 return the value of an iterator More...
 

Private Types

using object_t = typename BasicJsonType::object_t
 
using array_t = typename BasicJsonType::array_t
 

Private Member Functions

void set_begin () noexcept
 set the iterator to the first value More...
 
void set_end () noexcept
 set the iterator past the last value More...
 

Private Attributes

friend BasicJsonType
 
friend iteration_proxy< iter_impl >
 
friend iteration_proxy_value< iter_impl >
 
pointer m_object = nullptr
 associated JSON instance More...
 
internal_iterator< typename
std::remove_const
< BasicJsonType >::type
m_it {}
 the actual iterator of the associated instance More...
 

Friends

iter_impl operator+ (difference_type i, const iter_impl &it)
 addition of distance and iterator More...
 

Detailed Description

template<typename BasicJsonType>
class nlohmann::detail::iter_impl< BasicJsonType >

a template for a bidirectional iterator for the basic_json class This class implements a both iterators (iterator and const_iterator) for the basic_json class.

Note
An iterator is called initialized when a pointer to a JSON value has been set (e.g., by a constructor or a copy assignment). If the iterator is default-constructed, it is uninitialized and most methods are undefined. The library uses assertions to detect calls on uninitialized iterators.** The class satisfies the following concept requirements:
  • BidirectionalIterator: The iterator that can be moved can be moved in both directions (i.e. incremented and decremented).
Since
version 1.0.0, simplified in version 2.0.9, change to bidirectional iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593)

Definition at line 9346 of file json.hpp.

Member Typedef Documentation

template<typename BasicJsonType>
using nlohmann::detail::iter_impl< BasicJsonType >::array_t = typename BasicJsonType::array_t
private

Definition at line 9355 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::iter_impl< BasicJsonType >::difference_type = typename BasicJsonType::difference_type

a type to represent differences between iterators

Definition at line 9372 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::iter_impl< BasicJsonType >::iterator_category = std::bidirectional_iterator_tag

The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. The C++ Standard has never required user-defined iterators to derive from std::iterator. A user-defined iterator should provide publicly accessible typedefs named iterator_category, value_type, difference_type, pointer, and reference. Note that value_type is required to be non-const, even for constant iterators.

Definition at line 9367 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::iter_impl< BasicJsonType >::object_t = typename BasicJsonType::object_t
private

Definition at line 9354 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::iter_impl< BasicJsonType >::pointer = typename std::conditional<std::is_const<BasicJsonType>::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer>::type

defines a pointer to the type iterated over (value_type)

Definition at line 9376 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::iter_impl< BasicJsonType >::reference = typename std::conditional<std::is_const<BasicJsonType>::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference>::type

defines a reference to the type iterated over (value_type)

Definition at line 9381 of file json.hpp.

template<typename BasicJsonType>
using nlohmann::detail::iter_impl< BasicJsonType >::value_type = typename BasicJsonType::value_type

the type of the values when the iterator is dereferenced

Definition at line 9370 of file json.hpp.

Constructor & Destructor Documentation

template<typename BasicJsonType>
iter_impl< typename std::conditional< std::is_const< BasicJsonType >::value, typename std::remove_const< BasicJsonType >::type, const BasicJsonType >::type > ( )
default

default constructor

allow basic_json to access private members

Definition at line 9349 of file json.hpp.

template<typename BasicJsonType>
nlohmann::detail::iter_impl< BasicJsonType >::iter_impl ( pointer  object)
inlineexplicitnoexcept

constructor for a given JSON instance

Parameters
[in]objectpointer to a JSON object for this iterator
Precondition
object != nullptr
Postcondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9392 of file json.hpp.

9392  : m_object(object)
9393  {
9394  assert(m_object != nullptr);
9395 
9396  switch (m_object->m_type)
9397  {
9398  case value_t::object:
9399  {
9400  m_it.object_iterator = typename object_t::iterator();
9401  break;
9402  }
9403 
9404  case value_t::array:
9405  {
9406  m_it.array_iterator = typename array_t::iterator();
9407  break;
9408  }
9409 
9410  default:
9411  {
9412  m_it.primitive_iterator = primitive_iterator_t();
9413  break;
9414  }
9415  }
9416  }
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:9290
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
template<typename BasicJsonType>
nlohmann::detail::iter_impl< BasicJsonType >::iter_impl ( const iter_impl< const BasicJsonType > &  other)
inlinenoexcept

const copy constructor

Note
The conventional copy constructor and copy assignment are implicitly defined. Combined with the following converting constructor and assignment, they support: (1) copy from iterator to iterator, (2) copy from const iterator to const iterator, and (3) conversion from iterator to const iterator. However conversion from const iterator to iterator is not defined.
Parameters
[in]otherconst iterator to copy from
Note
This copy constructor had to be defined explicitly to circumvent a bug occurring on msvc v19.0 compiler (VS 2015) debug build. For more information refer to: https://github.com/nlohmann/json/issues/1608

Definition at line 9434 of file json.hpp.

9435  : m_object(other.m_object), m_it(other.m_it)
9436  {}
pointer m_object
associated JSON instance
Definition: json.hpp:9939
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
template<typename BasicJsonType>
nlohmann::detail::iter_impl< BasicJsonType >::iter_impl ( const iter_impl< typename std::remove_const< BasicJsonType >::type > &  other)
inlinenoexcept

converting constructor

Parameters
[in]othernon-const iterator to copy from
Note
It is not checked whether other is initialized.

Definition at line 9456 of file json.hpp.

9457  : m_object(other.m_object), m_it(other.m_it)
9458  {}
pointer m_object
associated JSON instance
Definition: json.hpp:9939
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941

Member Function Documentation

template<typename BasicJsonType>
const object_t::key_type& nlohmann::detail::iter_impl< BasicJsonType >::key ( ) const
inline

return the key of an object iterator

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9916 of file json.hpp.

9917  {
9918  assert(m_object != nullptr);
9919 
9920  if (JSON_HEDLEY_LIKELY(m_object->is_object()))
9921  {
9922  return m_it.object_iterator->first;
9923  }
9924 
9925  JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators"));
9926  }
pointer m_object
associated JSON instance
Definition: json.hpp:9939
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:9290
#define JSON_THROW(exception)
Definition: json.hpp:1754
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
static invalid_iterator create(int id_, const std::string &what_arg)
Definition: json.hpp:2024
#define JSON_HEDLEY_LIKELY(expr)
Definition: json.hpp:1123
template<typename BasicJsonType>
bool nlohmann::detail::iter_impl< BasicJsonType >::operator!= ( const iter_impl< BasicJsonType > &  other) const
inline

comparison: not equal

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9730 of file json.hpp.

9731  {
9732  return not operator==(other);
9733  }
bool operator==(const iter_impl &other) const
comparison: equal
Definition: json.hpp:9703
template<typename BasicJsonType>
reference nlohmann::detail::iter_impl< BasicJsonType >::operator* ( ) const
inline

return a reference to the value pointed to by the iterator

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9546 of file json.hpp.

9547  {
9548  assert(m_object != nullptr);
9549 
9550  switch (m_object->m_type)
9551  {
9552  case value_t::object:
9553  {
9554  assert(m_it.object_iterator != m_object->m_value.object->end());
9555  return m_it.object_iterator->second;
9556  }
9557 
9558  case value_t::array:
9559  {
9560  assert(m_it.array_iterator != m_object->m_value.array->end());
9561  return *m_it.array_iterator;
9562  }
9563 
9564  case value_t::null:
9565  JSON_THROW(invalid_iterator::create(214, "cannot get value"));
9566 
9567  default:
9568  {
9570  {
9571  return *m_object;
9572  }
9573 
9574  JSON_THROW(invalid_iterator::create(214, "cannot get value"));
9575  }
9576  }
9577  }
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:9290
#define JSON_THROW(exception)
Definition: json.hpp:1754
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition: json.hpp:9202
static invalid_iterator create(int id_, const std::string &what_arg)
Definition: json.hpp:2024
#define JSON_HEDLEY_LIKELY(expr)
Definition: json.hpp:1123
template<typename BasicJsonType>
iter_impl nlohmann::detail::iter_impl< BasicJsonType >::operator+ ( difference_type  i) const
inline

add to iterator

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9831 of file json.hpp.

9832  {
9833  auto result = *this;
9834  result += i;
9835  return result;
9836  }
template<typename BasicJsonType>
iter_impl const nlohmann::detail::iter_impl< BasicJsonType >::operator++ ( int  )
inline

post-increment (it++)

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9617 of file json.hpp.

9618  {
9619  auto result = *this;
9620  ++(*this);
9621  return result;
9622  }
template<typename BasicJsonType>
iter_impl& nlohmann::detail::iter_impl< BasicJsonType >::operator++ ( )
inline

pre-increment (++it)

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9628 of file json.hpp.

9629  {
9630  assert(m_object != nullptr);
9631 
9632  switch (m_object->m_type)
9633  {
9634  case value_t::object:
9635  {
9636  std::advance(m_it.object_iterator, 1);
9637  break;
9638  }
9639 
9640  case value_t::array:
9641  {
9642  std::advance(m_it.array_iterator, 1);
9643  break;
9644  }
9645 
9646  default:
9647  {
9649  break;
9650  }
9651  }
9652 
9653  return *this;
9654  }
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:9290
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
template<typename BasicJsonType>
iter_impl& nlohmann::detail::iter_impl< BasicJsonType >::operator+= ( difference_type  i)
inline

add to iterator

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9793 of file json.hpp.

9794  {
9795  assert(m_object != nullptr);
9796 
9797  switch (m_object->m_type)
9798  {
9799  case value_t::object:
9800  JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators"));
9801 
9802  case value_t::array:
9803  {
9804  std::advance(m_it.array_iterator, i);
9805  break;
9806  }
9807 
9808  default:
9809  {
9810  m_it.primitive_iterator += i;
9811  break;
9812  }
9813  }
9814 
9815  return *this;
9816  }
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
#define JSON_THROW(exception)
Definition: json.hpp:1754
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
static invalid_iterator create(int id_, const std::string &what_arg)
Definition: json.hpp:2024
template<typename BasicJsonType>
iter_impl nlohmann::detail::iter_impl< BasicJsonType >::operator- ( difference_type  i) const
inline

subtract from iterator

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9853 of file json.hpp.

9854  {
9855  auto result = *this;
9856  result -= i;
9857  return result;
9858  }
template<typename BasicJsonType>
difference_type nlohmann::detail::iter_impl< BasicJsonType >::operator- ( const iter_impl< BasicJsonType > &  other) const
inline

return difference

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9864 of file json.hpp.

9865  {
9866  assert(m_object != nullptr);
9867 
9868  switch (m_object->m_type)
9869  {
9870  case value_t::object:
9871  JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators"));
9872 
9873  case value_t::array:
9874  return m_it.array_iterator - other.m_it.array_iterator;
9875 
9876  default:
9877  return m_it.primitive_iterator - other.m_it.primitive_iterator;
9878  }
9879  }
difference_type m_it
iterator as signed integer type
Definition: json.hpp:9181
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
#define JSON_THROW(exception)
Definition: json.hpp:1754
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
static invalid_iterator create(int id_, const std::string &what_arg)
Definition: json.hpp:2024
template<typename BasicJsonType>
iter_impl const nlohmann::detail::iter_impl< BasicJsonType >::operator-- ( int  )
inline

post-decrement (it–)

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9660 of file json.hpp.

9661  {
9662  auto result = *this;
9663  --(*this);
9664  return result;
9665  }
template<typename BasicJsonType>
iter_impl& nlohmann::detail::iter_impl< BasicJsonType >::operator-- ( )
inline

pre-decrement (–it)

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9671 of file json.hpp.

9672  {
9673  assert(m_object != nullptr);
9674 
9675  switch (m_object->m_type)
9676  {
9677  case value_t::object:
9678  {
9679  std::advance(m_it.object_iterator, -1);
9680  break;
9681  }
9682 
9683  case value_t::array:
9684  {
9685  std::advance(m_it.array_iterator, -1);
9686  break;
9687  }
9688 
9689  default:
9690  {
9692  break;
9693  }
9694  }
9695 
9696  return *this;
9697  }
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:9290
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
template<typename BasicJsonType>
iter_impl& nlohmann::detail::iter_impl< BasicJsonType >::operator-= ( difference_type  i)
inline

subtract from iterator

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9822 of file json.hpp.

9823  {
9824  return operator+=(-i);
9825  }
iter_impl & operator+=(difference_type i)
add to iterator
Definition: json.hpp:9793
template<typename BasicJsonType>
pointer nlohmann::detail::iter_impl< BasicJsonType >::operator-> ( ) const
inline

dereference the iterator

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9583 of file json.hpp.

9584  {
9585  assert(m_object != nullptr);
9586 
9587  switch (m_object->m_type)
9588  {
9589  case value_t::object:
9590  {
9591  assert(m_it.object_iterator != m_object->m_value.object->end());
9592  return &(m_it.object_iterator->second);
9593  }
9594 
9595  case value_t::array:
9596  {
9597  assert(m_it.array_iterator != m_object->m_value.array->end());
9598  return &*m_it.array_iterator;
9599  }
9600 
9601  default:
9602  {
9604  {
9605  return m_object;
9606  }
9607 
9608  JSON_THROW(invalid_iterator::create(214, "cannot get value"));
9609  }
9610  }
9611  }
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:9290
#define JSON_THROW(exception)
Definition: json.hpp:1754
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition: json.hpp:9202
static invalid_iterator create(int id_, const std::string &what_arg)
Definition: json.hpp:2024
#define JSON_HEDLEY_LIKELY(expr)
Definition: json.hpp:1123
template<typename BasicJsonType>
bool nlohmann::detail::iter_impl< BasicJsonType >::operator< ( const iter_impl< BasicJsonType > &  other) const
inline

comparison: smaller

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9739 of file json.hpp.

9740  {
9741  // if objects are not the same, the comparison is undefined
9742  if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
9743  {
9744  JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers"));
9745  }
9746 
9747  assert(m_object != nullptr);
9748 
9749  switch (m_object->m_type)
9750  {
9751  case value_t::object:
9752  JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators"));
9753 
9754  case value_t::array:
9755  return (m_it.array_iterator < other.m_it.array_iterator);
9756 
9757  default:
9758  return (m_it.primitive_iterator < other.m_it.primitive_iterator);
9759  }
9760  }
difference_type m_it
iterator as signed integer type
Definition: json.hpp:9181
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
#define JSON_THROW(exception)
Definition: json.hpp:1754
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
static invalid_iterator create(int id_, const std::string &what_arg)
Definition: json.hpp:2024
#define JSON_HEDLEY_UNLIKELY(expr)
Definition: json.hpp:1124
template<typename BasicJsonType>
bool nlohmann::detail::iter_impl< BasicJsonType >::operator<= ( const iter_impl< BasicJsonType > &  other) const
inline

comparison: less than or equal

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9766 of file json.hpp.

9767  {
9768  return not other.operator < (*this);
9769  }
template<typename BasicJsonType>
iter_impl& nlohmann::detail::iter_impl< BasicJsonType >::operator= ( const iter_impl< const BasicJsonType > &  other)
inlinenoexcept

converting assignment

Parameters
[in]otherconst iterator to copy from
Returns
const/non-const iterator
Note
It is not checked whether other is initialized.

Definition at line 9444 of file json.hpp.

9445  {
9446  m_object = other.m_object;
9447  m_it = other.m_it;
9448  return *this;
9449  }
pointer m_object
associated JSON instance
Definition: json.hpp:9939
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
template<typename BasicJsonType>
iter_impl& nlohmann::detail::iter_impl< BasicJsonType >::operator= ( const iter_impl< typename std::remove_const< BasicJsonType >::type > &  other)
inlinenoexcept

converting assignment

Parameters
[in]othernon-const iterator to copy from
Returns
const/non-const iterator
Note
It is not checked whether other is initialized.

Definition at line 9466 of file json.hpp.

9467  {
9468  m_object = other.m_object;
9469  m_it = other.m_it;
9470  return *this;
9471  }
pointer m_object
associated JSON instance
Definition: json.hpp:9939
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
template<typename BasicJsonType>
bool nlohmann::detail::iter_impl< BasicJsonType >::operator== ( const iter_impl< BasicJsonType > &  other) const
inline

comparison: equal

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9703 of file json.hpp.

9704  {
9705  // if objects are not the same, the comparison is undefined
9706  if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
9707  {
9708  JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers"));
9709  }
9710 
9711  assert(m_object != nullptr);
9712 
9713  switch (m_object->m_type)
9714  {
9715  case value_t::object:
9716  return (m_it.object_iterator == other.m_it.object_iterator);
9717 
9718  case value_t::array:
9719  return (m_it.array_iterator == other.m_it.array_iterator);
9720 
9721  default:
9722  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
9723  }
9724  }
difference_type m_it
iterator as signed integer type
Definition: json.hpp:9181
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:9290
#define JSON_THROW(exception)
Definition: json.hpp:1754
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
static invalid_iterator create(int id_, const std::string &what_arg)
Definition: json.hpp:2024
#define JSON_HEDLEY_UNLIKELY(expr)
Definition: json.hpp:1124
template<typename BasicJsonType>
bool nlohmann::detail::iter_impl< BasicJsonType >::operator> ( const iter_impl< BasicJsonType > &  other) const
inline

comparison: greater than

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9775 of file json.hpp.

9776  {
9777  return not operator<=(other);
9778  }
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition: json.hpp:9766
template<typename BasicJsonType>
bool nlohmann::detail::iter_impl< BasicJsonType >::operator>= ( const iter_impl< BasicJsonType > &  other) const
inline

comparison: greater than or equal

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9784 of file json.hpp.

9785  {
9786  return not operator<(other);
9787  }
bool operator<(const iter_impl &other) const
comparison: smaller
Definition: json.hpp:9739
template<typename BasicJsonType>
reference nlohmann::detail::iter_impl< BasicJsonType >::operator[] ( difference_type  n) const
inline

access to successor

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9885 of file json.hpp.

9886  {
9887  assert(m_object != nullptr);
9888 
9889  switch (m_object->m_type)
9890  {
9891  case value_t::object:
9892  JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators"));
9893 
9894  case value_t::array:
9895  return *std::next(m_it.array_iterator, n);
9896 
9897  case value_t::null:
9898  JSON_THROW(invalid_iterator::create(214, "cannot get value"));
9899 
9900  default:
9901  {
9903  {
9904  return *m_object;
9905  }
9906 
9907  JSON_THROW(invalid_iterator::create(214, "cannot get value"));
9908  }
9909  }
9910  }
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
#define JSON_THROW(exception)
Definition: json.hpp:1754
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
constexpr difference_type get_value() const noexcept
Definition: json.hpp:9184
object (unordered set of name/value pairs)
static invalid_iterator create(int id_, const std::string &what_arg)
Definition: json.hpp:2024
#define JSON_HEDLEY_LIKELY(expr)
Definition: json.hpp:1123
template<typename BasicJsonType>
void nlohmann::detail::iter_impl< BasicJsonType >::set_begin ( )
inlineprivatenoexcept

set the iterator to the first value

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9478 of file json.hpp.

9479  {
9480  assert(m_object != nullptr);
9481 
9482  switch (m_object->m_type)
9483  {
9484  case value_t::object:
9485  {
9486  m_it.object_iterator = m_object->m_value.object->begin();
9487  break;
9488  }
9489 
9490  case value_t::array:
9491  {
9492  m_it.array_iterator = m_object->m_value.array->begin();
9493  break;
9494  }
9495 
9496  case value_t::null:
9497  {
9498  // set to end so begin()==end() is true: null is empty
9500  break;
9501  }
9502 
9503  default:
9504  {
9506  break;
9507  }
9508  }
9509  }
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
void set_end() noexcept
set iterator to a defined past the end
Definition: json.hpp:9196
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:9290
void set_begin() noexcept
set iterator to a defined beginning
Definition: json.hpp:9190
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
template<typename BasicJsonType>
void nlohmann::detail::iter_impl< BasicJsonType >::set_end ( )
inlineprivatenoexcept

set the iterator past the last value

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9515 of file json.hpp.

9516  {
9517  assert(m_object != nullptr);
9518 
9519  switch (m_object->m_type)
9520  {
9521  case value_t::object:
9522  {
9523  m_it.object_iterator = m_object->m_value.object->end();
9524  break;
9525  }
9526 
9527  case value_t::array:
9528  {
9529  m_it.array_iterator = m_object->m_value.array->end();
9530  break;
9531  }
9532 
9533  default:
9534  {
9536  break;
9537  }
9538  }
9539  }
array (ordered collection of values)
pointer m_object
associated JSON instance
Definition: json.hpp:9939
void set_end() noexcept
set iterator to a defined past the end
Definition: json.hpp:9196
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition: json.hpp:9290
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition: json.hpp:9294
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition: json.hpp:9292
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition: json.hpp:9941
object (unordered set of name/value pairs)
template<typename BasicJsonType>
reference nlohmann::detail::iter_impl< BasicJsonType >::value ( ) const
inline

return the value of an iterator

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9932 of file json.hpp.

9933  {
9934  return operator*();
9935  }
reference operator*() const
return a reference to the value pointed to by the iterator
Definition: json.hpp:9546

Friends And Related Function Documentation

template<typename BasicJsonType>
iter_impl operator+ ( difference_type  i,
const iter_impl< BasicJsonType > &  it 
)
friend

addition of distance and iterator

Precondition
The iterator is initialized; i.e. m_object != nullptr.

Definition at line 9842 of file json.hpp.

9843  {
9844  auto result = it;
9845  result += i;
9846  return result;
9847  }

Member Data Documentation

template<typename BasicJsonType>
friend nlohmann::detail::iter_impl< BasicJsonType >::BasicJsonType
private

Definition at line 9350 of file json.hpp.

template<typename BasicJsonType>
friend nlohmann::detail::iter_impl< BasicJsonType >::iteration_proxy< iter_impl >
private

Definition at line 9351 of file json.hpp.

template<typename BasicJsonType>
friend nlohmann::detail::iter_impl< BasicJsonType >::iteration_proxy_value< iter_impl >
private

Definition at line 9352 of file json.hpp.

template<typename BasicJsonType>
internal_iterator<typename std::remove_const<BasicJsonType>::type> nlohmann::detail::iter_impl< BasicJsonType >::m_it {}
private

the actual iterator of the associated instance

Definition at line 9941 of file json.hpp.

template<typename BasicJsonType>
pointer nlohmann::detail::iter_impl< BasicJsonType >::m_object = nullptr
private

associated JSON instance

Definition at line 9939 of file json.hpp.


The documentation for this class was generated from the following file: