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
5fc9ef2b
Unverified
Commit
5fc9ef2b
authored
Aug 14, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add detail/iterators/iteration_proxy.hpp
parent
bf06cf6c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
87 deletions
+102
-87
Makefile
Makefile
+2
-1
src/detail/iterators/iteration_proxy.hpp
src/detail/iterators/iteration_proxy.hpp
+99
-0
src/json.hpp
src/json.hpp
+1
-86
No files found.
Makefile
View file @
5fc9ef2b
...
@@ -15,7 +15,8 @@ SRCS = ${SRCDIR}/json.hpp \
...
@@ -15,7 +15,8 @@ SRCS = ${SRCDIR}/json.hpp \
${SRCDIR}
/detail/parsing/parser.hpp
\
${SRCDIR}
/detail/parsing/parser.hpp
\
${SRCDIR}
/detail/iterators/primitive_iterator.hpp
\
${SRCDIR}
/detail/iterators/primitive_iterator.hpp
\
${SRCDIR}
/detail/iterators/internal_iterator.hpp
\
${SRCDIR}
/detail/iterators/internal_iterator.hpp
\
${SRCDIR}
/detail/iterators/iter_impl.hpp
${SRCDIR}
/detail/iterators/iter_impl.hpp
\
${SRCDIR}
/detail/iterators/iteration_proxy.hpp
...
...
src/detail/iterators/iteration_proxy.hpp
0 → 100644
View file @
5fc9ef2b
#ifndef NLOHMANN_JSON_DETAIL_ITERATORS_ITERATION_PROXY_HPP
#define NLOHMANN_JSON_DETAIL_ITERATORS_ITERATION_PROXY_HPP
#include <cstddef>
#include <string>
namespace
nlohmann
{
namespace
detail
{
/// proxy class for the iterator_wrapper functions
template
<
typename
IteratorType
>
class
iteration_proxy
{
private:
/// helper class for iteration
class
iteration_proxy_internal
{
private:
/// the iterator
IteratorType
anchor
;
/// an index for arrays (used to create key names)
std
::
size_t
array_index
=
0
;
public:
explicit
iteration_proxy_internal
(
IteratorType
it
)
noexcept
:
anchor
(
it
)
{}
/// dereference operator (needed for range-based for)
iteration_proxy_internal
&
operator
*
()
{
return
*
this
;
}
/// increment operator (needed for range-based for)
iteration_proxy_internal
&
operator
++
()
{
++
anchor
;
++
array_index
;
return
*
this
;
}
/// inequality operator (needed for range-based for)
bool
operator
!=
(
const
iteration_proxy_internal
&
o
)
const
noexcept
{
return
anchor
!=
o
.
anchor
;
}
/// return key of the iterator
std
::
string
key
()
const
{
assert
(
anchor
.
m_object
!=
nullptr
);
switch
(
anchor
.
m_object
->
type
())
{
// use integer array index as key
case
value_t
:
:
array
:
return
std
::
to_string
(
array_index
);
// use key from the object
case
value_t
:
:
object
:
return
anchor
.
key
();
// use an empty key for all primitive types
default:
return
""
;
}
}
/// return value of the iterator
typename
IteratorType
::
reference
value
()
const
{
return
anchor
.
value
();
}
};
/// the container to iterate
typename
IteratorType
::
reference
container
;
public:
/// construct iteration proxy from a container
explicit
iteration_proxy
(
typename
IteratorType
::
reference
cont
)
:
container
(
cont
)
{}
/// return iterator begin (needed for range-based for)
iteration_proxy_internal
begin
()
noexcept
{
return
iteration_proxy_internal
(
container
.
begin
());
}
/// return iterator end (needed for range-based for)
iteration_proxy_internal
end
()
noexcept
{
return
iteration_proxy_internal
(
container
.
end
());
}
};
}
}
#endif
src/json.hpp
View file @
5fc9ef2b
...
@@ -63,6 +63,7 @@ SOFTWARE.
...
@@ -63,6 +63,7 @@ SOFTWARE.
#include "detail/iterators/primitive_iterator.hpp"
#include "detail/iterators/primitive_iterator.hpp"
#include "detail/iterators/internal_iterator.hpp"
#include "detail/iterators/internal_iterator.hpp"
#include "detail/iterators/iter_impl.hpp"
#include "detail/iterators/iter_impl.hpp"
#include "detail/iterators/iteration_proxy.hpp"
/*!
/*!
@brief namespace for Niels Lohmann
@brief namespace for Niels Lohmann
...
@@ -77,92 +78,6 @@ namespace detail
...
@@ -77,92 +78,6 @@ namespace detail
// iterators //
// iterators //
///////////////
///////////////
/// proxy class for the iterator_wrapper functions
template
<
typename
IteratorType
>
class
iteration_proxy
{
private:
/// helper class for iteration
class
iteration_proxy_internal
{
private:
/// the iterator
IteratorType
anchor
;
/// an index for arrays (used to create key names)
std
::
size_t
array_index
=
0
;
public:
explicit
iteration_proxy_internal
(
IteratorType
it
)
noexcept
:
anchor
(
it
)
{}
/// dereference operator (needed for range-based for)
iteration_proxy_internal
&
operator
*
()
{
return
*
this
;
}
/// increment operator (needed for range-based for)
iteration_proxy_internal
&
operator
++
()
{
++
anchor
;
++
array_index
;
return
*
this
;
}
/// inequality operator (needed for range-based for)
bool
operator
!=
(
const
iteration_proxy_internal
&
o
)
const
noexcept
{
return
anchor
!=
o
.
anchor
;
}
/// return key of the iterator
std
::
string
key
()
const
{
assert
(
anchor
.
m_object
!=
nullptr
);
switch
(
anchor
.
m_object
->
type
())
{
// use integer array index as key
case
value_t
:
:
array
:
return
std
::
to_string
(
array_index
);
// use key from the object
case
value_t
:
:
object
:
return
anchor
.
key
();
// use an empty key for all primitive types
default:
return
""
;
}
}
/// return value of the iterator
typename
IteratorType
::
reference
value
()
const
{
return
anchor
.
value
();
}
};
/// the container to iterate
typename
IteratorType
::
reference
container
;
public:
/// construct iteration proxy from a container
explicit
iteration_proxy
(
typename
IteratorType
::
reference
cont
)
:
container
(
cont
)
{}
/// return iterator begin (needed for range-based for)
iteration_proxy_internal
begin
()
noexcept
{
return
iteration_proxy_internal
(
container
.
begin
());
}
/// return iterator end (needed for range-based for)
iteration_proxy_internal
end
()
noexcept
{
return
iteration_proxy_internal
(
container
.
end
());
}
};
/*!
/*!
@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