Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
92e28c31
Commit
92e28c31
authored
Dec 13, 2016
by
Bosswestfalen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added missing changes in json.hpp.re2c
parent
dd3f4f9b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
188 deletions
+51
-188
src/json.hpp.re2c
src/json.hpp.re2c
+51
-188
No files found.
src/json.hpp.re2c
View file @
92e28c31
...
@@ -8204,10 +8204,10 @@ class basic_json
...
@@ -8204,10 +8204,10 @@ class basic_json
public:
public:
/*!
/*!
@brief a
const
random access iterator for the @ref basic_json class
@brief a
template for a
random access iterator for the @ref basic_json class
This class implements a
const iterator for the @ref basic_json class. From
This class implements a
both iterators (iterator and const_iterator)
this class, the @ref iterator class is derived
.
for the @ref basic_json class
.
@note An iterator is called *initialized* when a pointer to a JSON value
@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
has been set (e.g., by a constructor or a copy assignment). If the
...
@@ -8222,25 +8222,35 @@ class basic_json
...
@@ -8222,25 +8222,35 @@ class basic_json
@since version 1.0.0
@since version 1.0.0
*/
*/
class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
template <typename U>
class iter_impl : public std::iterator<std::random_access_iterator_tag, U>
{
{
/// allow basic_json to access private members
/// allow basic_json to access private members
friend class basic_json;
friend class basic_json;
// make sure U is basic_json or const basic_json
static_assert(std::is_same<U, basic_json>::value
or std::is_same<U, const basic_json>::value,
"iter_impl only accepts (const) basic_json");
public:
public:
/// the type of the values when the iterator is dereferenced
/// the type of the values when the iterator is dereferenced
using value_type = typename basic_json::value_type;
using value_type = typename basic_json::value_type;
/// a type to represent differences between iterators
/// a type to represent differences between iterators
using difference_type = typename basic_json::difference_type;
using difference_type = typename basic_json::difference_type;
/// defines a pointer to the type iterated over (value_type)
/// defines a pointer to the type iterated over (value_type)
using pointer = typename basic_json::const_pointer;
using pointer = typename std::conditional<std::is_const<U>::value,
typename basic_json::const_pointer,
typename basic_json::pointer>::type;
/// defines a reference to the type iterated over (value_type)
/// defines a reference to the type iterated over (value_type)
using reference = typename basic_json::const_reference;
using reference = typename std::conditional<std::is_const<U>::value,
typename basic_json::const_reference,
typename basic_json::reference>::type;
/// the category of the iterator
/// the category of the iterator
using iterator_category = std::bidirectional_iterator_tag;
using iterator_category = std::bidirectional_iterator_tag;
/// default constructor
/// default constructor
const_iterator
() = default;
iter_impl
() = default;
/*!
/*!
@brief constructor for a given JSON instance
@brief constructor for a given JSON instance
...
@@ -8248,7 +8258,7 @@ class basic_json
...
@@ -8248,7 +8258,7 @@ class basic_json
@pre object != nullptr
@pre object != nullptr
@post The iterator is initialized; i.e. `m_object != nullptr`.
@post The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
explicit
const_iterator
(pointer object) noexcept
explicit
iter_impl
(pointer object) noexcept
: m_object(object)
: m_object(object)
{
{
assert(m_object != nullptr);
assert(m_object != nullptr);
...
@@ -8275,37 +8285,25 @@ class basic_json
...
@@ -8275,37 +8285,25 @@ class basic_json
}
}
}
}
/*!
/*
@brief copy constructor given a non-const iterator
Use operator const_iterator instead of
@param[in] other iterator to copy from
const_iterator(const iterator& other) noexcept
@note It is not checked whether @a other is initialized.
to avoid two class definitions for iterator and const_iterator.
*/
explicit const_iterator(const iterator& other) noexcept
: m_object(other.m_object)
{
if (m_object != nullptr)
{
switch (m_object->m_type)
{
case basic_json::value_t::object:
{
m_it.object_iterator = other.m_it.object_iterator;
break;
}
case basic_json::value_t::array:
This function is only called if this class is an iterator.
{
If this class is a const_iterator this function is not called.
m_it.array_iterator = other.m_it.array_iterator;
*/
break;
operator const_iterator() const
}
{
const_iterator ret;
default:
if (m_object)
{
{
m_it.primitive_iterator = other.m_it.primitive_iterator;
ret.m_object = m_object;
break;
ret.m_it = m_it;
}
}
}
}
return ret;
}
}
/*!
/*!
...
@@ -8313,7 +8311,7 @@ class basic_json
...
@@ -8313,7 +8311,7 @@ class basic_json
@param[in] other iterator to copy from
@param[in] other iterator to copy from
@note It is not checked whether @a other is initialized.
@note It is not checked whether @a other is initialized.
*/
*/
const_iterator(const const_iterator
& other) noexcept
iter_impl(const iter_impl
& other) noexcept
: m_object(other.m_object), m_it(other.m_it)
: m_object(other.m_object), m_it(other.m_it)
{}
{}
...
@@ -8322,7 +8320,7 @@ class basic_json
...
@@ -8322,7 +8320,7 @@ class basic_json
@param[in,out] other iterator to copy from
@param[in,out] other iterator to copy from
@note It is not checked whether @a other is initialized.
@note It is not checked whether @a other is initialized.
*/
*/
const_iterator& operator=(const_iterator
other) noexcept(
iter_impl& operator=(iter_impl
other) noexcept(
std::is_nothrow_move_constructible<pointer>::value and
std::is_nothrow_move_constructible<pointer>::value and
std::is_nothrow_move_assignable<pointer>::value and
std::is_nothrow_move_assignable<pointer>::value and
std::is_nothrow_move_constructible<internal_iterator>::value and
std::is_nothrow_move_constructible<internal_iterator>::value and
...
@@ -8484,7 +8482,7 @@ class basic_json
...
@@ -8484,7 +8482,7 @@ class basic_json
@brief post-increment (it++)
@brief post-increment (it++)
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
const_iterator
operator++(int)
iter_impl
operator++(int)
{
{
auto result = *this;
auto result = *this;
++(*this);
++(*this);
...
@@ -8495,7 +8493,7 @@ class basic_json
...
@@ -8495,7 +8493,7 @@ class basic_json
@brief pre-increment (++it)
@brief pre-increment (++it)
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
const_iterator
& operator++()
iter_impl
& operator++()
{
{
assert(m_object != nullptr);
assert(m_object != nullptr);
...
@@ -8527,7 +8525,7 @@ class basic_json
...
@@ -8527,7 +8525,7 @@ class basic_json
@brief post-decrement (it--)
@brief post-decrement (it--)
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
const_iterator
operator--(int)
iter_impl
operator--(int)
{
{
auto result = *this;
auto result = *this;
--(*this);
--(*this);
...
@@ -8538,7 +8536,7 @@ class basic_json
...
@@ -8538,7 +8536,7 @@ class basic_json
@brief pre-decrement (--it)
@brief pre-decrement (--it)
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
const_iterator
& operator--()
iter_impl
& operator--()
{
{
assert(m_object != nullptr);
assert(m_object != nullptr);
...
@@ -8570,7 +8568,7 @@ class basic_json
...
@@ -8570,7 +8568,7 @@ class basic_json
@brief comparison: equal
@brief comparison: equal
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
bool operator==(const
const_iterator
& other) const
bool operator==(const
iter_impl
& other) const
{
{
// if objects are not the same, the comparison is undefined
// if objects are not the same, the comparison is undefined
if (m_object != other.m_object)
if (m_object != other.m_object)
...
@@ -8603,7 +8601,7 @@ class basic_json
...
@@ -8603,7 +8601,7 @@ class basic_json
@brief comparison: not equal
@brief comparison: not equal
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
bool operator!=(const
const_iterator
& other) const
bool operator!=(const
iter_impl
& other) const
{
{
return not operator==(other);
return not operator==(other);
}
}
...
@@ -8612,7 +8610,7 @@ class basic_json
...
@@ -8612,7 +8610,7 @@ class basic_json
@brief comparison: smaller
@brief comparison: smaller
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
bool operator<(const
const_iterator
& other) const
bool operator<(const
iter_impl
& other) const
{
{
// if objects are not the same, the comparison is undefined
// if objects are not the same, the comparison is undefined
if (m_object != other.m_object)
if (m_object != other.m_object)
...
@@ -8645,7 +8643,7 @@ class basic_json
...
@@ -8645,7 +8643,7 @@ class basic_json
@brief comparison: less than or equal
@brief comparison: less than or equal
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
bool operator<=(const
const_iterator
& other) const
bool operator<=(const
iter_impl
& other) const
{
{
return not other.operator < (*this);
return not other.operator < (*this);
}
}
...
@@ -8654,7 +8652,7 @@ class basic_json
...
@@ -8654,7 +8652,7 @@ class basic_json
@brief comparison: greater than
@brief comparison: greater than
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
bool operator>(const
const_iterator
& other) const
bool operator>(const
iter_impl
& other) const
{
{
return not operator<=(other);
return not operator<=(other);
}
}
...
@@ -8663,7 +8661,7 @@ class basic_json
...
@@ -8663,7 +8661,7 @@ class basic_json
@brief comparison: greater than or equal
@brief comparison: greater than or equal
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
bool operator>=(const
const_iterator
& other) const
bool operator>=(const
iter_impl
& other) const
{
{
return not operator<(other);
return not operator<(other);
}
}
...
@@ -8672,7 +8670,7 @@ class basic_json
...
@@ -8672,7 +8670,7 @@ class basic_json
@brief add to iterator
@brief add to iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
const_iterator
& operator+=(difference_type i)
iter_impl
& operator+=(difference_type i)
{
{
assert(m_object != nullptr);
assert(m_object != nullptr);
...
@@ -8703,7 +8701,7 @@ class basic_json
...
@@ -8703,7 +8701,7 @@ class basic_json
@brief subtract from iterator
@brief subtract from iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
const_iterator
& operator-=(difference_type i)
iter_impl
& operator-=(difference_type i)
{
{
return operator+=(-i);
return operator+=(-i);
}
}
...
@@ -8712,7 +8710,7 @@ class basic_json
...
@@ -8712,7 +8710,7 @@ class basic_json
@brief add to iterator
@brief add to iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
const_iterator
operator+(difference_type i)
iter_impl
operator+(difference_type i)
{
{
auto result = *this;
auto result = *this;
result += i;
result += i;
...
@@ -8723,7 +8721,7 @@ class basic_json
...
@@ -8723,7 +8721,7 @@ class basic_json
@brief subtract from iterator
@brief subtract from iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
const_iterator
operator-(difference_type i)
iter_impl
operator-(difference_type i)
{
{
auto result = *this;
auto result = *this;
result -= i;
result -= i;
...
@@ -8734,7 +8732,7 @@ class basic_json
...
@@ -8734,7 +8732,7 @@ class basic_json
@brief return difference
@brief return difference
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
difference_type operator-(const
const_iterator
& other) const
difference_type operator-(const
iter_impl
& other) const
{
{
assert(m_object != nullptr);
assert(m_object != nullptr);
...
@@ -8830,141 +8828,6 @@ class basic_json
...
@@ -8830,141 +8828,6 @@ class basic_json
internal_iterator m_it = internal_iterator();
internal_iterator m_it = internal_iterator();
};
};
/*!
@brief a mutable random access iterator for the @ref basic_json class
@requirement The class satisfies the following concept requirements:
- [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator):
The iterator that can be moved to point (forward and backward) to any
element in constant time.
- [OutputIterator](http://en.cppreference.com/w/cpp/concept/OutputIterator):
It is possible to write to the pointed-to element.
@since version 1.0.0
*/
class iterator : public const_iterator
{
public:
using base_iterator = const_iterator;
using pointer = typename basic_json::pointer;
using reference = typename basic_json::reference;
/// default constructor
iterator() = default;
/// constructor for a given JSON instance
explicit iterator(pointer object) noexcept
: base_iterator(object)
{}
/// copy constructor
iterator(const iterator& other) noexcept
: base_iterator(other)
{}
/// copy assignment
iterator& operator=(iterator other) noexcept(
std::is_nothrow_move_constructible<pointer>::value and
std::is_nothrow_move_assignable<pointer>::value and
std::is_nothrow_move_constructible<internal_iterator>::value and
std::is_nothrow_move_assignable<internal_iterator>::value
)
{
base_iterator::operator=(other);
return *this;
}
/// return a reference to the value pointed to by the iterator
reference operator*() const
{
return const_cast<reference>(base_iterator::operator*());
}
/// dereference the iterator
pointer operator->() const
{
return const_cast<pointer>(base_iterator::operator->());
}
/// post-increment (it++)
iterator operator++(int)
{
iterator result = *this;
base_iterator::operator++();
return result;
}
/// pre-increment (++it)
iterator& operator++()
{
base_iterator::operator++();
return *this;
}
/// post-decrement (it--)
iterator operator--(int)
{
iterator result = *this;
base_iterator::operator--();
return result;
}
/// pre-decrement (--it)
iterator& operator--()
{
base_iterator::operator--();
return *this;
}
/// add to iterator
iterator& operator+=(difference_type i)
{
base_iterator::operator+=(i);
return *this;
}
/// subtract from iterator
iterator& operator-=(difference_type i)
{
base_iterator::operator-=(i);
return *this;
}
/// add to iterator
iterator operator+(difference_type i)
{
auto result = *this;
result += i;
return result;
}
/// subtract from iterator
iterator operator-(difference_type i)
{
auto result = *this;
result -= i;
return result;
}
/// return difference
difference_type operator-(const iterator& other) const
{
return base_iterator::operator-(other);
}
/// access to successor
reference operator[](difference_type n) const
{
return const_cast<reference>(base_iterator::operator[](n));
}
/// return the value of an iterator
reference value() const
{
return const_cast<reference>(base_iterator::value());
}
};
/*!
/*!
@brief a template for a reverse iterator class
@brief a template for a reverse iterator class
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment