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
b80ca376
Commit
b80ca376
authored
Feb 15, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some missing features from 2.0 version
parent
2d8b3628
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
src/json.hpp
src/json.hpp
+31
-0
src/json.hpp.re2c
src/json.hpp.re2c
+31
-0
No files found.
src/json.hpp
View file @
b80ca376
...
@@ -725,6 +725,18 @@ class basic_json
...
@@ -725,6 +725,18 @@ class basic_json
return
m_value
.
object
->
operator
[](
key
);
return
m_value
.
object
->
operator
[](
key
);
}
}
/// access specified element
inline
const_reference
operator
[](
const
typename
object_t
::
key_type
&
key
)
const
{
// at only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime_error
(
"cannot use [] with "
+
type_name
());
}
return
m_value
.
object
->
operator
[](
key
);
}
/// access specified element (needed for clang)
/// access specified element (needed for clang)
template
<
typename
T
,
size_t
n
>
template
<
typename
T
,
size_t
n
>
inline
reference
operator
[](
const
T
(
&
key
)[
n
])
inline
reference
operator
[](
const
T
(
&
key
)[
n
])
...
@@ -738,6 +750,19 @@ class basic_json
...
@@ -738,6 +750,19 @@ class basic_json
return
m_value
.
object
->
operator
[](
key
);
return
m_value
.
object
->
operator
[](
key
);
}
}
/// access specified element (needed for clang)
template
<
typename
T
,
size_t
n
>
inline
const_reference
operator
[](
const
T
(
&
key
)[
n
])
const
{
// at only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime_error
(
"cannot use [] with "
+
type_name
());
}
return
m_value
.
object
->
operator
[](
key
);
}
/// find an element in an object
/// find an element in an object
inline
iterator
find
(
typename
object_t
::
key_type
key
)
inline
iterator
find
(
typename
object_t
::
key_type
key
)
...
@@ -1686,6 +1711,9 @@ class basic_json
...
@@ -1686,6 +1711,9 @@ 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
;
/// default constructor
inline
iterator
()
=
default
;
/// 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
)
{
{
...
@@ -2044,6 +2072,9 @@ class basic_json
...
@@ -2044,6 +2072,9 @@ 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
;
/// default constructor
inline
const_iterator
()
=
default
;
/// 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
)
{
{
...
...
src/json.hpp.re2c
View file @
b80ca376
...
@@ -725,6 +725,18 @@ class basic_json
...
@@ -725,6 +725,18 @@ class basic_json
return m_value.object->operator[](key);
return m_value.object->operator[](key);
}
}
/// access specified element
inline const_reference operator[](const typename object_t::key_type& key) const
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](key);
}
/// access specified element (needed for clang)
/// access specified element (needed for clang)
template<typename T, size_t n>
template<typename T, size_t n>
inline reference operator[](const T (&key)[n])
inline reference operator[](const T (&key)[n])
...
@@ -738,6 +750,19 @@ class basic_json
...
@@ -738,6 +750,19 @@ class basic_json
return m_value.object->operator[](key);
return m_value.object->operator[](key);
}
}
/// access specified element (needed for clang)
template<typename T, size_t n>
inline const_reference operator[](const T (&key)[n]) const
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](key);
}
/// find an element in an object
/// find an element in an object
inline iterator find(typename object_t::key_type key)
inline iterator find(typename object_t::key_type key)
...
@@ -1686,6 +1711,9 @@ class basic_json
...
@@ -1686,6 +1711,9 @@ 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;
/// default constructor
inline iterator() = default;
/// 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)
{
{
...
@@ -2044,6 +2072,9 @@ class basic_json
...
@@ -2044,6 +2072,9 @@ 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;
/// default constructor
inline const_iterator() = default;
/// 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)
{
{
...
...
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