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
f8037660
Unverified
Commit
f8037660
authored
Jan 14, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
add iterator set_parent function
parent
0d1fb383
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
78 deletions
+36
-78
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+18
-39
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+18
-39
No files found.
include/nlohmann/json.hpp
View file @
f8037660
...
@@ -1287,6 +1287,19 @@ class basic_json
...
@@ -1287,6 +1287,19 @@ class basic_json
#endif
#endif
}
}
iterator
set_parents
(
iterator
it
,
typename
iterator
::
difference_type
count
)
{
#if JSON_DIAGNOSTICS
for
(
typename
iterator
::
difference_type
i
=
0
;
i
<
count
;
++
i
)
{
(
it
+
i
)
->
m_parent
=
this
;
}
#else
static_cast
<
void
>
(
count
);
#endif
return
it
;
}
reference
set_parent
(
reference
j
)
reference
set_parent
(
reference
j
)
{
{
#if JSON_DIAGNOSTICS
#if JSON_DIAGNOSTICS
...
@@ -3601,7 +3614,7 @@ class basic_json
...
@@ -3601,7 +3614,7 @@ class basic_json
// set parent for values added above
// set parent for values added above
for
(
auto
i
=
previous_size
;
i
<=
idx
;
++
i
)
for
(
auto
i
=
previous_size
;
i
<=
idx
;
++
i
)
{
{
m_value
.
array
->
operator
[](
i
).
m_parent
=
this
;
set_parent
(
m_value
.
array
->
operator
[](
i
))
;
}
}
#endif
#endif
}
}
...
@@ -5636,13 +5649,7 @@ class basic_json
...
@@ -5636,13 +5649,7 @@ class basic_json
}
}
// insert to array and return iterator
// insert to array and return iterator
#if JSON_DIAGNOSTICS
return
set_parents
(
insert_iterator
(
pos
,
val
),
static_cast
<
typename
iterator
::
difference_type
>
(
1
));
iterator
result
=
insert_iterator
(
pos
,
val
);
result
->
m_parent
=
this
;
return
result
;
#else
return
insert_iterator
(
pos
,
val
);
#endif
}
}
JSON_THROW
(
type_error
::
create
(
309
,
"cannot use insert() with "
+
std
::
string
(
type_name
()),
diagnostics_t
(
*
this
)));
JSON_THROW
(
type_error
::
create
(
309
,
"cannot use insert() with "
+
std
::
string
(
type_name
()),
diagnostics_t
(
*
this
)));
...
@@ -5693,16 +5700,7 @@ class basic_json
...
@@ -5693,16 +5700,7 @@ class basic_json
}
}
// insert to array and return iterator
// insert to array and return iterator
#if JSON_DIAGNOSTICS
return
set_parents
(
insert_iterator
(
pos
,
cnt
,
val
),
static_cast
<
typename
iterator
::
difference_type
>
(
cnt
));
iterator
result
=
insert_iterator
(
pos
,
cnt
,
val
);
for
(
size_type
i
=
0
;
i
<
cnt
;
++
i
)
{
(
result
+
static_cast
<
typename
iterator
::
difference_type
>
(
i
))
->
m_parent
=
this
;
}
return
result
;
#else
return
insert_iterator
(
pos
,
cnt
,
val
);
#endif
}
}
JSON_THROW
(
type_error
::
create
(
309
,
"cannot use insert() with "
+
std
::
string
(
type_name
()),
diagnostics_t
(
*
this
)));
JSON_THROW
(
type_error
::
create
(
309
,
"cannot use insert() with "
+
std
::
string
(
type_name
()),
diagnostics_t
(
*
this
)));
...
@@ -5764,16 +5762,7 @@ class basic_json
...
@@ -5764,16 +5762,7 @@ class basic_json
}
}
// insert to array and return iterator
// insert to array and return iterator
#if JSON_DIAGNOSTICS
return
set_parents
(
insert_iterator
(
pos
,
first
.
m_it
.
array_iterator
,
last
.
m_it
.
array_iterator
),
std
::
distance
(
first
,
last
));
iterator
result
=
insert_iterator
(
pos
,
first
.
m_it
.
array_iterator
,
last
.
m_it
.
array_iterator
);
for
(
typename
iterator
::
difference_type
i
=
0
;
i
<
std
::
distance
(
first
,
last
);
++
i
)
{
(
result
+
i
)
->
m_parent
=
this
;
}
return
result
;
#else
return
insert_iterator
(
pos
,
first
.
m_it
.
array_iterator
,
last
.
m_it
.
array_iterator
);
#endif
}
}
/*!
/*!
...
@@ -5815,17 +5804,7 @@ class basic_json
...
@@ -5815,17 +5804,7 @@ class basic_json
}
}
// insert to array and return iterator
// insert to array and return iterator
#if JSON_DIAGNOSTICS
return
set_parents
(
insert_iterator
(
pos
,
ilist
.
begin
(),
ilist
.
end
()),
static_cast
<
typename
iterator
::
difference_type
>
(
ilist
.
size
()));
const
auto
size
=
ilist
.
size
();
iterator
result
=
insert_iterator
(
pos
,
ilist
.
begin
(),
ilist
.
end
());
for
(
std
::
size_t
i
=
0
;
i
<
size
;
++
i
)
{
(
result
+
static_cast
<
typename
iterator
::
difference_type
>
(
i
))
->
m_parent
=
this
;
}
return
result
;
#else
return
insert_iterator
(
pos
,
ilist
.
begin
(),
ilist
.
end
());
#endif
}
}
/*!
/*!
...
...
single_include/nlohmann/json.hpp
View file @
f8037660
...
@@ -18042,6 +18042,19 @@ class basic_json
...
@@ -18042,6 +18042,19 @@ class basic_json
#endif
#endif
}
}
iterator
set_parents
(
iterator
it
,
typename
iterator
::
difference_type
count
)
{
#if JSON_DIAGNOSTICS
for
(
typename
iterator
::
difference_type
i
=
0
;
i
<
count
;
++
i
)
{
(
it
+
i
)
->
m_parent
=
this
;
}
#else
static_cast
<
void
>
(
count
);
#endif
return
it
;
}
reference
set_parent
(
reference
j
)
reference
set_parent
(
reference
j
)
{
{
#if JSON_DIAGNOSTICS
#if JSON_DIAGNOSTICS
...
@@ -20356,7 +20369,7 @@ class basic_json
...
@@ -20356,7 +20369,7 @@ class basic_json
// set parent for values added above
// set parent for values added above
for
(
auto
i
=
previous_size
;
i
<=
idx
;
++
i
)
for
(
auto
i
=
previous_size
;
i
<=
idx
;
++
i
)
{
{
m_value
.
array
->
operator
[](
i
).
m_parent
=
this
;
set_parent
(
m_value
.
array
->
operator
[](
i
))
;
}
}
#endif
#endif
}
}
...
@@ -22391,13 +22404,7 @@ class basic_json
...
@@ -22391,13 +22404,7 @@ class basic_json
}
}
// insert to array and return iterator
// insert to array and return iterator
#if JSON_DIAGNOSTICS
return
set_parents
(
insert_iterator
(
pos
,
val
),
static_cast
<
typename
iterator
::
difference_type
>
(
1
));
iterator
result
=
insert_iterator
(
pos
,
val
);
result
->
m_parent
=
this
;
return
result
;
#else
return
insert_iterator
(
pos
,
val
);
#endif
}
}
JSON_THROW
(
type_error
::
create
(
309
,
"cannot use insert() with "
+
std
::
string
(
type_name
()),
diagnostics_t
(
*
this
)));
JSON_THROW
(
type_error
::
create
(
309
,
"cannot use insert() with "
+
std
::
string
(
type_name
()),
diagnostics_t
(
*
this
)));
...
@@ -22448,16 +22455,7 @@ class basic_json
...
@@ -22448,16 +22455,7 @@ class basic_json
}
}
// insert to array and return iterator
// insert to array and return iterator
#if JSON_DIAGNOSTICS
return
set_parents
(
insert_iterator
(
pos
,
cnt
,
val
),
static_cast
<
typename
iterator
::
difference_type
>
(
cnt
));
iterator
result
=
insert_iterator
(
pos
,
cnt
,
val
);
for
(
size_type
i
=
0
;
i
<
cnt
;
++
i
)
{
(
result
+
static_cast
<
typename
iterator
::
difference_type
>
(
i
))
->
m_parent
=
this
;
}
return
result
;
#else
return
insert_iterator
(
pos
,
cnt
,
val
);
#endif
}
}
JSON_THROW
(
type_error
::
create
(
309
,
"cannot use insert() with "
+
std
::
string
(
type_name
()),
diagnostics_t
(
*
this
)));
JSON_THROW
(
type_error
::
create
(
309
,
"cannot use insert() with "
+
std
::
string
(
type_name
()),
diagnostics_t
(
*
this
)));
...
@@ -22519,16 +22517,7 @@ class basic_json
...
@@ -22519,16 +22517,7 @@ class basic_json
}
}
// insert to array and return iterator
// insert to array and return iterator
#if JSON_DIAGNOSTICS
return
set_parents
(
insert_iterator
(
pos
,
first
.
m_it
.
array_iterator
,
last
.
m_it
.
array_iterator
),
std
::
distance
(
first
,
last
));
iterator
result
=
insert_iterator
(
pos
,
first
.
m_it
.
array_iterator
,
last
.
m_it
.
array_iterator
);
for
(
typename
iterator
::
difference_type
i
=
0
;
i
<
std
::
distance
(
first
,
last
);
++
i
)
{
(
result
+
i
)
->
m_parent
=
this
;
}
return
result
;
#else
return
insert_iterator
(
pos
,
first
.
m_it
.
array_iterator
,
last
.
m_it
.
array_iterator
);
#endif
}
}
/*!
/*!
...
@@ -22570,17 +22559,7 @@ class basic_json
...
@@ -22570,17 +22559,7 @@ class basic_json
}
}
// insert to array and return iterator
// insert to array and return iterator
#if JSON_DIAGNOSTICS
return
set_parents
(
insert_iterator
(
pos
,
ilist
.
begin
(),
ilist
.
end
()),
static_cast
<
typename
iterator
::
difference_type
>
(
ilist
.
size
()));
const
auto
size
=
ilist
.
size
();
iterator
result
=
insert_iterator
(
pos
,
ilist
.
begin
(),
ilist
.
end
());
for
(
std
::
size_t
i
=
0
;
i
<
size
;
++
i
)
{
(
result
+
static_cast
<
typename
iterator
::
difference_type
>
(
i
))
->
m_parent
=
this
;
}
return
result
;
#else
return
insert_iterator
(
pos
,
ilist
.
begin
(),
ilist
.
end
());
#endif
}
}
/*!
/*!
...
...
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