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
48392cfa
Commit
48392cfa
authored
Feb 09, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some bug fixing
parent
fe64ed5f
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
482 additions
and
809 deletions
+482
-809
src/json.hpp
src/json.hpp
+384
-720
src/json.hpp.re2c
src/json.hpp.re2c
+78
-69
test/unit.cpp
test/unit.cpp
+20
-20
No files found.
src/json.hpp
View file @
48392cfa
This diff is collapsed.
Click to expand it.
src/json.hpp.re2c
View file @
48392cfa
...
@@ -1604,11 +1604,65 @@ class basic_json
...
@@ -1604,11 +1604,65 @@ class basic_json
json_value m_value = {};
json_value m_value = {};
p
ublic
:
p
rivate
:
///////////////
///////////////
// iterators //
// iterators //
///////////////
///////////////
/// values of a generic iterator type of non-container JSON values
enum class generic_iterator_value
{
/// the iterator was not initialized
uninitialized,
/// the iterator points to the only value
begin,
/// the iterator points past the only value
end,
/// the iterator points to an invalid value
invalid
};
/// an iterator value
union internal_iterator
{
/// iterator for JSON objects
typename object_t::iterator object_iterator;
/// iterator for JSON arrays
typename array_t::iterator array_iterator;
/// generic iteraotr for all other value types
generic_iterator_value generic_iterator;
/// default constructor
internal_iterator() : generic_iterator(generic_iterator_value::uninitialized) {}
/// constructor for object iterators
internal_iterator(typename object_t::iterator v) : object_iterator(v) {}
/// constructor for array iterators
internal_iterator(typename array_t::iterator v) : array_iterator(v) {}
/// constructor for generic iterators
internal_iterator(generic_iterator_value v) : generic_iterator(v) {}
};
/// a const iterator value
union internal_const_iterator
{
/// iterator for JSON objects
typename object_t::const_iterator object_iterator;
/// iterator for JSON arrays
typename array_t::const_iterator array_iterator;
/// generic iteraotr for all other value types
generic_iterator_value generic_iterator;
/// default constructor
internal_const_iterator() : generic_iterator(generic_iterator_value::uninitialized) {}
/// constructor for object iterators
internal_const_iterator(typename object_t::iterator v) : object_iterator(v) {}
/// constructor for array iterators
internal_const_iterator(typename array_t::iterator v) : array_iterator(v) {}
/// constructor for generic iterators
internal_const_iterator(generic_iterator_value v) : generic_iterator(v) {}
};
public:
/// a bidirectional iterator for the basic_json class
/// a bidirectional iterator for the basic_json class
class iterator : public std::iterator<std::bidirectional_iterator_tag, basic_json>
class iterator : public std::iterator<std::bidirectional_iterator_tag, basic_json>
{
{
...
@@ -1624,39 +1678,6 @@ class basic_json
...
@@ -1624,39 +1678,6 @@ class basic_json
/// the category of the iterator
/// the category of the iterator
using iterator_category = std::bidirectional_iterator_tag;
using iterator_category = std::bidirectional_iterator_tag;
/// values of a generic iterator type of non-container JSON values
enum class generic_iterator_value
{
/// the iterator was not initialized
uninitialized,
/// the iterator points to the only value
begin,
/// the iterator points past the only value
end,
/// the iterator points to an invalid value
invalid
};
/// an iterator value
union internal_iterator
{
/// iterator for JSON objects
typename object_t::iterator object_iterator;
/// iterator for JSON arrays
typename array_t::iterator array_iterator;
/// generic iteraotr for all other value types
generic_iterator_value generic_iterator;
/// default constructor
internal_iterator() : generic_iterator(generic_iterator_value::uninitialized) {}
/// constructor for object iterators
internal_iterator(typename object_t::iterator v) : object_iterator(v) {}
/// constructor for array iterators
internal_iterator(typename array_t::iterator v) : array_iterator(v) {}
/// constructor for generic iterators
internal_iterator(generic_iterator_value v) : generic_iterator(v) {}
};
/// constructor for a given JSON instance
/// constructor for a given JSON instance
inline iterator(pointer object) : m_object(object)
inline iterator(pointer object) : m_object(object)
{
{
...
@@ -2015,39 +2036,6 @@ class basic_json
...
@@ -2015,39 +2036,6 @@ class basic_json
/// the category of the iterator
/// the category of the iterator
using iterator_category = std::bidirectional_iterator_tag;
using iterator_category = std::bidirectional_iterator_tag;
/// values of a generic iterator type of non-container JSON values
enum class generic_iterator_value
{
/// the iterator was not initialized
uninitialized,
/// the iterator points to the only value
begin,
/// the iterator points past the only value
end,
/// the iterator points to an invalid value
invalid
};
/// an iterator value
union internal_const_iterator
{
/// iterator for JSON objects
typename object_t::const_iterator object_iterator;
/// iterator for JSON arrays
typename array_t::const_iterator array_iterator;
/// generic iteraotr for all other value types
generic_iterator_value generic_iterator;
/// default constructor
internal_const_iterator() : generic_iterator(generic_iterator_value::uninitialized) {}
/// constructor for object iterators
internal_const_iterator(typename object_t::iterator v) : object_iterator(v) {}
/// constructor for array iterators
internal_const_iterator(typename array_t::iterator v) : array_iterator(v) {}
/// constructor for generic iterators
internal_const_iterator(generic_iterator_value v) : generic_iterator(v) {}
};
/// constructor for a given JSON instance
/// constructor for a given JSON instance
inline const_iterator(pointer object) : m_object(object)
inline const_iterator(pointer object) : m_object(object)
{
{
...
@@ -2072,8 +2060,29 @@ class basic_json
...
@@ -2072,8 +2060,29 @@ class basic_json
}
}
/// copy constructor given a nonconst iterator
/// copy constructor given a nonconst iterator
inline const_iterator(const iterator& other) : m_object(other.m_object), m_it(other.m_it)
inline const_iterator(const iterator& other) : m_object(other.m_object)
{}
{
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):
{
m_it.array_iterator = other.m_it.array_iterator;
break;
}
default:
{
m_it.generic_iterator = other.m_it.generic_iterator;
break;
}
}
}
/// copy assignment
/// copy assignment
inline const_iterator operator=(const const_iterator& other) noexcept
inline const_iterator operator=(const const_iterator& other) noexcept
...
...
test/unit.cpp
View file @
48392cfa
...
@@ -2285,7 +2285,7 @@ TEST_CASE("iterators")
...
@@ -2285,7 +2285,7 @@ TEST_CASE("iterators")
SECTION
(
"json + begin/end"
)
SECTION
(
"json + begin/end"
)
{
{
auto
it
=
j
.
begin
();
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
!=
j
.
end
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
CHECK
(
*
it
==
j
);
...
@@ -2310,7 +2310,7 @@ TEST_CASE("iterators")
...
@@ -2310,7 +2310,7 @@ TEST_CASE("iterators")
SECTION
(
"const json + begin/end"
)
SECTION
(
"const json + begin/end"
)
{
{
auto
it
=
j_const
.
begin
();
json
::
const_iterator
it
=
j_const
.
begin
();
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
CHECK
(
*
it
==
j_const
);
...
@@ -2335,7 +2335,7 @@ TEST_CASE("iterators")
...
@@ -2335,7 +2335,7 @@ TEST_CASE("iterators")
SECTION
(
"json + cbegin/cend"
)
SECTION
(
"json + cbegin/cend"
)
{
{
auto
it
=
j
.
cbegin
();
json
::
const_iterator
it
=
j
.
cbegin
();
CHECK
(
it
!=
j
.
cend
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
CHECK
(
*
it
==
j
);
...
@@ -2360,7 +2360,7 @@ TEST_CASE("iterators")
...
@@ -2360,7 +2360,7 @@ TEST_CASE("iterators")
SECTION
(
"const json + cbegin/cend"
)
SECTION
(
"const json + cbegin/cend"
)
{
{
auto
it
=
j_const
.
cbegin
();
json
::
const_iterator
it
=
j_const
.
cbegin
();
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
CHECK
(
*
it
==
j_const
);
...
@@ -2391,7 +2391,7 @@ TEST_CASE("iterators")
...
@@ -2391,7 +2391,7 @@ TEST_CASE("iterators")
SECTION
(
"json + begin/end"
)
SECTION
(
"json + begin/end"
)
{
{
auto
it
=
j
.
begin
();
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
!=
j
.
end
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
CHECK
(
*
it
==
j
);
...
@@ -2416,7 +2416,7 @@ TEST_CASE("iterators")
...
@@ -2416,7 +2416,7 @@ TEST_CASE("iterators")
SECTION
(
"const json + begin/end"
)
SECTION
(
"const json + begin/end"
)
{
{
auto
it
=
j_const
.
begin
();
json
::
const_iterator
it
=
j_const
.
begin
();
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
CHECK
(
*
it
==
j_const
);
...
@@ -2441,7 +2441,7 @@ TEST_CASE("iterators")
...
@@ -2441,7 +2441,7 @@ TEST_CASE("iterators")
SECTION
(
"json + cbegin/cend"
)
SECTION
(
"json + cbegin/cend"
)
{
{
auto
it
=
j
.
cbegin
();
json
::
const_iterator
it
=
j
.
cbegin
();
CHECK
(
it
!=
j
.
cend
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
CHECK
(
*
it
==
j
);
...
@@ -2466,7 +2466,7 @@ TEST_CASE("iterators")
...
@@ -2466,7 +2466,7 @@ TEST_CASE("iterators")
SECTION
(
"const json + cbegin/cend"
)
SECTION
(
"const json + cbegin/cend"
)
{
{
auto
it
=
j_const
.
cbegin
();
json
::
const_iterator
it
=
j_const
.
cbegin
();
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
CHECK
(
*
it
==
j_const
);
...
@@ -2509,7 +2509,7 @@ TEST_CASE("iterators")
...
@@ -2509,7 +2509,7 @@ TEST_CASE("iterators")
SECTION
(
"json + begin/end"
)
SECTION
(
"json + begin/end"
)
{
{
auto
it
=
j
.
begin
();
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
!=
j
.
end
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
CHECK
(
*
it
==
j
);
...
@@ -2534,7 +2534,7 @@ TEST_CASE("iterators")
...
@@ -2534,7 +2534,7 @@ TEST_CASE("iterators")
SECTION
(
"const json + begin/end"
)
SECTION
(
"const json + begin/end"
)
{
{
auto
it
=
j_const
.
begin
();
json
::
const_iterator
it
=
j_const
.
begin
();
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
CHECK
(
*
it
==
j_const
);
...
@@ -2559,7 +2559,7 @@ TEST_CASE("iterators")
...
@@ -2559,7 +2559,7 @@ TEST_CASE("iterators")
SECTION
(
"json + cbegin/cend"
)
SECTION
(
"json + cbegin/cend"
)
{
{
auto
it
=
j
.
cbegin
();
json
::
const_iterator
it
=
j
.
cbegin
();
CHECK
(
it
!=
j
.
cend
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
CHECK
(
*
it
==
j
);
...
@@ -2584,7 +2584,7 @@ TEST_CASE("iterators")
...
@@ -2584,7 +2584,7 @@ TEST_CASE("iterators")
SECTION
(
"const json + cbegin/cend"
)
SECTION
(
"const json + cbegin/cend"
)
{
{
auto
it
=
j_const
.
cbegin
();
json
::
const_iterator
it
=
j_const
.
cbegin
();
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
CHECK
(
*
it
==
j_const
);
...
@@ -2615,7 +2615,7 @@ TEST_CASE("iterators")
...
@@ -2615,7 +2615,7 @@ TEST_CASE("iterators")
SECTION
(
"json + begin/end"
)
SECTION
(
"json + begin/end"
)
{
{
auto
it
=
j
.
begin
();
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
!=
j
.
end
());
CHECK
(
it
!=
j
.
end
());
CHECK
(
*
it
==
j
);
CHECK
(
*
it
==
j
);
...
@@ -2640,7 +2640,7 @@ TEST_CASE("iterators")
...
@@ -2640,7 +2640,7 @@ TEST_CASE("iterators")
SECTION
(
"const json + begin/end"
)
SECTION
(
"const json + begin/end"
)
{
{
auto
it
=
j_const
.
begin
();
json
::
const_iterator
it
=
j_const
.
begin
();
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
it
!=
j_const
.
end
());
CHECK
(
*
it
==
j_const
);
CHECK
(
*
it
==
j_const
);
...
@@ -2665,7 +2665,7 @@ TEST_CASE("iterators")
...
@@ -2665,7 +2665,7 @@ TEST_CASE("iterators")
SECTION
(
"json + cbegin/cend"
)
SECTION
(
"json + cbegin/cend"
)
{
{
auto
it
=
j
.
cbegin
();
json
::
const_iterator
it
=
j
.
cbegin
();
CHECK
(
it
!=
j
.
cend
());
CHECK
(
it
!=
j
.
cend
());
CHECK
(
*
it
==
j
);
CHECK
(
*
it
==
j
);
...
@@ -2690,7 +2690,7 @@ TEST_CASE("iterators")
...
@@ -2690,7 +2690,7 @@ TEST_CASE("iterators")
SECTION
(
"const json + cbegin/cend"
)
SECTION
(
"const json + cbegin/cend"
)
{
{
auto
it
=
j_const
.
cbegin
();
json
::
const_iterator
it
=
j_const
.
cbegin
();
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
it
!=
j_const
.
cend
());
CHECK
(
*
it
==
j_const
);
CHECK
(
*
it
==
j_const
);
...
@@ -2721,25 +2721,25 @@ TEST_CASE("iterators")
...
@@ -2721,25 +2721,25 @@ TEST_CASE("iterators")
SECTION
(
"json + begin/end"
)
SECTION
(
"json + begin/end"
)
{
{
auto
it
=
j
.
begin
();
json
::
iterator
it
=
j
.
begin
();
CHECK
(
it
==
j
.
end
());
CHECK
(
it
==
j
.
end
());
}
}
SECTION
(
"const json + begin/end"
)
SECTION
(
"const json + begin/end"
)
{
{
auto
it
=
j_const
.
begin
();
json
::
const_iterator
it
=
j_const
.
begin
();
CHECK
(
it
==
j_const
.
end
());
CHECK
(
it
==
j_const
.
end
());
}
}
SECTION
(
"json + cbegin/cend"
)
SECTION
(
"json + cbegin/cend"
)
{
{
auto
it
=
j
.
cbegin
();
json
::
const_iterator
it
=
j
.
cbegin
();
CHECK
(
it
==
j
.
cend
());
CHECK
(
it
==
j
.
cend
());
}
}
SECTION
(
"const json + cbegin/cend"
)
SECTION
(
"const json + cbegin/cend"
)
{
{
auto
it
=
j_const
.
cbegin
();
json
::
const_iterator
it
=
j_const
.
cbegin
();
CHECK
(
it
==
j_const
.
cend
());
CHECK
(
it
==
j_const
.
cend
());
}
}
}
}
...
...
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