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
db03d093
Unverified
Commit
db03d093
authored
May 27, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/key_ref' into develop (fixes #1098)
parents
cf9299d2
481ace65
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
8 deletions
+34
-8
include/nlohmann/detail/iterators/iter_impl.hpp
include/nlohmann/detail/iterators/iter_impl.hpp
+1
-1
include/nlohmann/detail/iterators/iteration_proxy.hpp
include/nlohmann/detail/iterators/iteration_proxy.hpp
+16
-3
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+17
-4
No files found.
include/nlohmann/detail/iterators/iter_impl.hpp
View file @
db03d093
...
@@ -583,7 +583,7 @@ class iter_impl
...
@@ -583,7 +583,7 @@ class iter_impl
@brief return the key of an object iterator
@brief return the key of an object iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
typename
object_t
::
key_type
key
()
const
const
typename
object_t
::
key_type
&
key
()
const
{
{
assert
(
m_object
!=
nullptr
);
assert
(
m_object
!=
nullptr
);
...
...
include/nlohmann/detail/iterators/iteration_proxy.hpp
View file @
db03d093
...
@@ -21,6 +21,12 @@ template<typename IteratorType> class iteration_proxy
...
@@ -21,6 +21,12 @@ template<typename IteratorType> class iteration_proxy
IteratorType
anchor
;
IteratorType
anchor
;
/// an index for arrays (used to create key names)
/// an index for arrays (used to create key names)
std
::
size_t
array_index
=
0
;
std
::
size_t
array_index
=
0
;
/// last stringified array index
mutable
std
::
size_t
array_index_last
=
0
;
/// a string representation of the array index
mutable
std
::
string
array_index_str
=
"0"
;
/// an empty string (to return a reference for primitive values)
const
std
::
string
empty_str
=
""
;
public:
public:
explicit
iteration_proxy_internal
(
IteratorType
it
)
noexcept
:
anchor
(
it
)
{}
explicit
iteration_proxy_internal
(
IteratorType
it
)
noexcept
:
anchor
(
it
)
{}
...
@@ -47,7 +53,7 @@ template<typename IteratorType> class iteration_proxy
...
@@ -47,7 +53,7 @@ template<typename IteratorType> class iteration_proxy
}
}
/// return key of the iterator
/// return key of the iterator
std
::
string
key
()
const
const
std
::
string
&
key
()
const
{
{
assert
(
anchor
.
m_object
!=
nullptr
);
assert
(
anchor
.
m_object
!=
nullptr
);
...
@@ -55,7 +61,14 @@ template<typename IteratorType> class iteration_proxy
...
@@ -55,7 +61,14 @@ template<typename IteratorType> class iteration_proxy
{
{
// use integer array index as key
// use integer array index as key
case
value_t
:
:
array
:
case
value_t
:
:
array
:
return
std
::
to_string
(
array_index
);
{
if
(
array_index
!=
array_index_last
)
{
array_index_str
=
std
::
to_string
(
array_index
);
array_index_last
=
array_index
;
}
return
array_index_str
;
}
// use key from the object
// use key from the object
case
value_t
:
:
object
:
case
value_t
:
:
object
:
...
@@ -63,7 +76,7 @@ template<typename IteratorType> class iteration_proxy
...
@@ -63,7 +76,7 @@ template<typename IteratorType> class iteration_proxy
// use an empty key for all primitive types
// use an empty key for all primitive types
default:
default:
return
""
;
return
empty_str
;
}
}
}
}
...
...
single_include/nlohmann/json.hpp
View file @
db03d093
...
@@ -5210,7 +5210,7 @@ class iter_impl
...
@@ -5210,7 +5210,7 @@ class iter_impl
@brief return the key of an object iterator
@brief return the key of an object iterator
@pre The iterator is initialized; i.e. `m_object != nullptr`.
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
*/
typename
object_t
::
key_type
key
()
const
const
typename
object_t
::
key_type
&
key
()
const
{
{
assert
(
m_object
!=
nullptr
);
assert
(
m_object
!=
nullptr
);
...
@@ -5265,6 +5265,12 @@ template<typename IteratorType> class iteration_proxy
...
@@ -5265,6 +5265,12 @@ template<typename IteratorType> class iteration_proxy
IteratorType
anchor
;
IteratorType
anchor
;
/// an index for arrays (used to create key names)
/// an index for arrays (used to create key names)
std
::
size_t
array_index
=
0
;
std
::
size_t
array_index
=
0
;
/// last stringified array index
mutable
std
::
size_t
array_index_last
=
0
;
/// a string representation of the array index
mutable
std
::
string
array_index_str
=
"0"
;
/// an empty string (to return a reference for primitive values)
const
std
::
string
empty_str
=
""
;
public:
public:
explicit
iteration_proxy_internal
(
IteratorType
it
)
noexcept
:
anchor
(
it
)
{}
explicit
iteration_proxy_internal
(
IteratorType
it
)
noexcept
:
anchor
(
it
)
{}
...
@@ -5291,7 +5297,7 @@ template<typename IteratorType> class iteration_proxy
...
@@ -5291,7 +5297,7 @@ template<typename IteratorType> class iteration_proxy
}
}
/// return key of the iterator
/// return key of the iterator
std
::
string
key
()
const
const
std
::
string
&
key
()
const
{
{
assert
(
anchor
.
m_object
!=
nullptr
);
assert
(
anchor
.
m_object
!=
nullptr
);
...
@@ -5299,7 +5305,14 @@ template<typename IteratorType> class iteration_proxy
...
@@ -5299,7 +5305,14 @@ template<typename IteratorType> class iteration_proxy
{
{
// use integer array index as key
// use integer array index as key
case
value_t
:
:
array
:
case
value_t
:
:
array
:
return
std
::
to_string
(
array_index
);
{
if
(
array_index
!=
array_index_last
)
{
array_index_str
=
std
::
to_string
(
array_index
);
array_index_last
=
array_index
;
}
return
array_index_str
;
}
// use key from the object
// use key from the object
case
value_t
:
:
object
:
case
value_t
:
:
object
:
...
@@ -5307,7 +5320,7 @@ template<typename IteratorType> class iteration_proxy
...
@@ -5307,7 +5320,7 @@ template<typename IteratorType> class iteration_proxy
// use an empty key for all primitive types
// use an empty key for all primitive types
default:
default:
return
""
;
return
empty_str
;
}
}
}
}
...
...
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