1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-09 11:01:47 +03:00

key/value function for iterators (#46)

Currently only support iterator and const_iterator. reverse_iterator
and const_reverse_iterator to be implemented soon.
This commit is contained in:
Niels
2015-03-24 19:08:03 +01:00
parent 8fc4061187
commit 47ea1c10d4
3 changed files with 162 additions and 0 deletions

View File

@ -2137,6 +2137,7 @@ class basic_json
return *this;
}
private:
/// set the iterator to the first value
inline void set_begin() noexcept
{
@ -2194,6 +2195,7 @@ class basic_json
}
}
public:
/// return a reference to the value pointed to by the iterator
inline reference operator*()
{
@ -2559,6 +2561,27 @@ class basic_json
}
}
inline typename object_t::key_type key() const
{
switch (m_object->m_type)
{
case (basic_json::value_t::object):
{
return m_it.object_iterator->first;
}
default:
{
throw std::domain_error("cannot use key() for non-object iterators");
}
}
}
inline reference value()
{
return operator*();
}
private:
/// associated JSON instance
pointer m_object = nullptr;
@ -2654,6 +2677,7 @@ class basic_json
return *this;
}
private:
/// set the iterator to the first value
inline void set_begin() noexcept
{
@ -2711,6 +2735,7 @@ class basic_json
}
}
public:
/// return a reference to the value pointed to by the iterator
inline reference operator*() const
{
@ -3071,6 +3096,27 @@ class basic_json
}
}
inline typename object_t::key_type key() const
{
switch (m_object->m_type)
{
case (basic_json::value_t::object):
{
return m_it.object_iterator->first;
}
default:
{
throw std::domain_error("cannot use key() for non-object iterators");
}
}
}
inline reference value() const
{
return operator*();
}
private:
/// associated JSON instance
pointer m_object = nullptr;