Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
0ee8d53a
Commit
0ee8d53a
authored
Jul 05, 2013
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- a find() function
parent
ac5ff658
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
5 deletions
+56
-5
JSON.cc
src/JSON.cc
+42
-0
JSON.h
src/JSON.h
+14
-5
No files found.
src/JSON.cc
View file @
0ee8d53a
...
@@ -484,6 +484,48 @@ JSON::json_t JSON::type() const {
...
@@ -484,6 +484,48 @@ JSON::json_t JSON::type() const {
return
_type
;
return
_type
;
}
}
JSON
::
iterator
JSON
::
find
(
const
std
::
string
&
key
)
{
return
find
(
key
.
c_str
());
}
JSON
::
const_iterator
JSON
::
find
(
const
std
::
string
&
key
)
const
{
return
find
(
key
.
c_str
());
}
JSON
::
iterator
JSON
::
find
(
const
char
*
key
)
{
if
(
_type
!=
object
)
{
return
end
();
}
else
{
std
::
map
<
std
::
string
,
JSON
>*
o
=
static_cast
<
std
::
map
<
std
::
string
,
JSON
>*>
(
_payload
);
const
std
::
map
<
std
::
string
,
JSON
>::
iterator
i
=
o
->
find
(
key
);
if
(
i
!=
o
->
end
())
{
JSON
::
iterator
result
;
result
.
_object
=
this
;
result
.
_oi
=
new
std
::
map
<
std
::
string
,
JSON
>::
iterator
(
i
);
return
result
;
}
else
{
return
end
();
}
}
}
JSON
::
const_iterator
JSON
::
find
(
const
char
*
key
)
const
{
if
(
_type
!=
object
)
{
return
end
();
}
else
{
std
::
map
<
std
::
string
,
JSON
>*
o
=
static_cast
<
std
::
map
<
std
::
string
,
JSON
>*>
(
_payload
);
const
std
::
map
<
std
::
string
,
JSON
>::
const_iterator
i
=
o
->
find
(
key
);
if
(
i
!=
o
->
end
())
{
JSON
::
const_iterator
result
;
result
.
_object
=
this
;
result
.
_oi
=
new
std
::
map
<
std
::
string
,
JSON
>::
const_iterator
(
i
);
return
result
;
}
else
{
return
end
();
}
}
}
/// direct access to the underlying payload
/// direct access to the underlying payload
void
*
JSON
::
data
()
{
void
*
JSON
::
data
()
{
return
_payload
;
return
_payload
;
...
...
src/JSON.h
View file @
0ee8d53a
...
@@ -22,6 +22,11 @@
...
@@ -22,6 +22,11 @@
#endif
#endif
class
JSON
{
class
JSON
{
// forward declaration to friend this class
public
:
class
iterator
;
class
const_iterator
;
private
:
private
:
#ifdef __cplusplus11
#ifdef __cplusplus11
/// mutex to guard payload
/// mutex to guard payload
...
@@ -158,6 +163,12 @@ class JSON {
...
@@ -158,6 +163,12 @@ class JSON {
/// return the type of the object
/// return the type of the object
json_t
type
()
const
;
json_t
type
()
const
;
/// find an element in an object (returns end() iterator otherwise)
iterator
find
(
const
std
::
string
&
);
const_iterator
find
(
const
std
::
string
&
)
const
;
iterator
find
(
const
char
*
);
const_iterator
find
(
const
char
*
)
const
;
/// direct access to the underlying payload
/// direct access to the underlying payload
void
*
data
();
void
*
data
();
/// direct access to the underlying payload
/// direct access to the underlying payload
...
@@ -170,14 +181,11 @@ class JSON {
...
@@ -170,14 +181,11 @@ class JSON {
/// return the type as string
/// return the type as string
std
::
string
_typename
()
const
;
std
::
string
_typename
()
const
;
// forward declaration to friend this class
public
:
class
const_iterator
;
public
:
public
:
/// an iterator
/// an iterator
class
iterator
{
class
iterator
{
friend
class
JSON
::
const_iterator
;
friend
class
JSON
;
friend
class
JSON
::
const_iterator
;
public
:
public
:
iterator
();
iterator
();
iterator
(
JSON
*
);
iterator
(
JSON
*
);
...
@@ -207,6 +215,7 @@ class JSON {
...
@@ -207,6 +215,7 @@ class JSON {
/// a const iterator
/// a const iterator
class
const_iterator
{
class
const_iterator
{
friend
class
JSON
;
public
:
public
:
const_iterator
();
const_iterator
();
const_iterator
(
const
JSON
*
);
const_iterator
(
const
JSON
*
);
...
...
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