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
bbc45eb4
Commit
bbc45eb4
authored
Jan 21, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
overworked iterators
parent
76be1ae1
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
356 additions
and
512 deletions
+356
-512
header_only/json.h
header_only/json.h
+149
-227
src/json.cc
src/json.cc
+138
-221
src/json.h
src/json.h
+11
-6
test/json_unit.cc
test/json_unit.cc
+58
-58
No files found.
header_only/json.h
View file @
bbc45eb4
This diff is collapsed.
Click to expand it.
src/json.cc
View file @
bbc45eb4
This diff is collapsed.
Click to expand it.
src/json.h
View file @
bbc45eb4
...
...
@@ -42,11 +42,12 @@ due to alignment.
*/
class
json
{
p
ublic
:
p
rivate
:
// forward declaration to friend this class
class
iterator
;
class
const_iterator
;
public:
// container types
using
value_type
=
json
;
using
reference
=
json
&
;
...
...
@@ -371,15 +372,15 @@ class json
/// the payload
value
value_
{};
p
ublic
:
p
rivate
:
/// an iterator
class
iterator
:
p
ublic
std
::
iterator
<
std
::
forward_iterator_tag
,
json
>
class
iterator
:
p
rivate
std
::
iterator
<
std
::
forward_iterator_tag
,
json
>
{
friend
class
json
;
friend
class
json
::
const_iterator
;
public:
iterator
()
=
default
;
iterator
(
json
*
);
iterator
(
json
*
,
bool
);
iterator
(
const
iterator
&
);
~
iterator
();
...
...
@@ -402,16 +403,18 @@ class json
array_t
::
iterator
*
vi_
=
nullptr
;
/// an iterator for JSON objects
object_t
::
iterator
*
oi_
=
nullptr
;
/// whether iterator points to a valid object
bool
invalid
=
true
;
};
/// a const iterator
class
const_iterator
:
p
ublic
std
::
iterator
<
std
::
forward_iterator_tag
,
const
json
>
class
const_iterator
:
p
rivate
std
::
iterator
<
std
::
forward_iterator_tag
,
const
json
>
{
friend
class
json
;
public:
const_iterator
()
=
default
;
const_iterator
(
const
json
*
);
const_iterator
(
const
json
*
,
bool
);
const_iterator
(
const
const_iterator
&
);
const_iterator
(
const
json
::
iterator
&
);
~
const_iterator
();
...
...
@@ -435,6 +438,8 @@ class json
array_t
::
const_iterator
*
vi_
=
nullptr
;
/// an iterator for JSON objects
object_t
::
const_iterator
*
oi_
=
nullptr
;
/// whether iterator reached past the end
bool
invalid
=
true
;
};
private:
...
...
test/json_unit.cc
View file @
bbc45eb4
...
...
@@ -1371,35 +1371,35 @@ TEST_CASE("Iterators")
CHECK
(
*
j7
.
begin
()
==
json
(
"hello"
));
CHECK
(
*
j7_const
.
begin
()
==
json
(
"hello"
));
CHECK_THROWS_AS
(
*
j1
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j1
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j2
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j2
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j3
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j3
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j4
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j4
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j5
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j5
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j6
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j6
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j7
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j7
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j1_const
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j1_const
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j2_const
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j2_const
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j3_const
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j3_const
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j4_const
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j4_const
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j5_const
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j5_const
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j6_const
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j6_const
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j7_const
.
end
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j7_const
.
cend
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
*
j1
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j1
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j2
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j2
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j3
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j3
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j4
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j4
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j5
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j5
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j6
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j6
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j7
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j7
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j1_const
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j1_const
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j2_const
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j2_const
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j3_const
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j3_const
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j4_const
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j4_const
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j5_const
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j5_const
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j6_const
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j6_const
.
cend
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j7_const
.
end
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
*
j7_const
.
cend
(),
std
::
out_of_range
);
// operator ->
CHECK
(
j1
.
begin
()
->
type
()
==
json
::
value_t
::
number
);
...
...
@@ -1432,35 +1432,35 @@ TEST_CASE("Iterators")
CHECK
(
j7_const
.
begin
()
->
type
()
==
json
::
value_t
::
string
);
CHECK
(
j7_const
.
cbegin
()
->
type
()
==
json
::
value_t
::
string
);
CHECK_THROWS_AS
(
j1
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j1
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j2
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j2
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j3
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j3
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j4
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j4
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j5
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j5
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j6
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j6
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j7
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j7
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j1_const
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j1_const
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j2_const
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j2_const
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j3_const
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j3_const
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j4_const
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j4_const
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j5_const
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j5_const
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j6_const
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j6_const
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j7_const
.
end
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j7_const
.
cend
()
->
type
(),
std
::
runtime_error
);
CHECK_THROWS_AS
(
j1
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j1
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j2
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j2
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j3
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j3
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j4
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j4
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j5
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j5
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j6
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j6
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j7
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j7
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j1_const
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j1_const
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j2_const
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j2_const
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j3_const
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j3_const
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j4_const
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j4_const
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j5_const
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j5_const
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j6_const
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j6_const
.
cend
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j7_const
.
end
()
->
type
(),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j7_const
.
cend
()
->
type
(),
std
::
out_of_range
);
// value
CHECK
(
j1
.
begin
().
value
().
type
()
==
json
::
value_t
::
number
);
...
...
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