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
4e6a400a
Commit
4e6a400a
authored
Jul 10, 2013
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- reorganized payload
parent
ec6e628d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
11 deletions
+37
-11
JSON.cc
src/JSON.cc
+0
-0
JSON.h
src/JSON.h
+35
-9
JSON_test.cc
test/JSON_test.cc
+2
-2
No files found.
src/JSON.cc
View file @
4e6a400a
This diff is collapsed.
Click to expand it.
src/JSON.h
View file @
4e6a400a
...
@@ -39,18 +39,44 @@ class JSON {
...
@@ -39,18 +39,44 @@ class JSON {
array
,
object
,
null
,
string
,
boolean
,
number
,
number_float
array
,
object
,
null
,
string
,
boolean
,
number
,
number_float
}
json_t
;
}
json_t
;
private
:
/// the type of this object
json_t
_type
;
/// the payload
void
*
_payload
;
public
:
public
:
/// a type for an object
/// a type for an object
typedef
std
::
map
<
std
::
string
,
JSON
>
object_t
;
typedef
std
::
map
<
std
::
string
,
JSON
>
object_t
;
/// a type for an array
/// a type for an array
typedef
std
::
vector
<
JSON
>
array_t
;
typedef
std
::
vector
<
JSON
>
array_t
;
/// a type for a string
typedef
std
::
string
string_t
;
/// a type for a Boolean
typedef
bool
boolean_t
;
/// a type for an integer number
typedef
int
number_t
;
/// a type for a floating point number
typedef
double
number_float_t
;
/// a JSON value
union
value
{
array_t
*
array
;
object_t
*
object
;
string_t
*
string
;
boolean_t
*
boolean
;
number_t
*
number
;
number_float_t
*
number_float
;
value
()
{}
value
(
array_t
*
array
)
:
array
(
array
)
{}
value
(
object_t
*
object
)
:
object
(
object
)
{}
value
(
string_t
*
string
)
:
string
(
string
)
{}
value
(
boolean_t
*
boolean
)
:
boolean
(
boolean
)
{}
value
(
number_t
*
number
)
:
number
(
number
)
{}
value
(
number_float_t
*
number_float
)
:
number_float
(
number_float
)
{}
};
private
:
/// the type of this object
json_t
_type
;
/// the payload
value
_value
;
#ifdef __cplusplus11
#ifdef __cplusplus11
/// a type for array initialization
/// a type for array initialization
...
@@ -190,9 +216,9 @@ class JSON {
...
@@ -190,9 +216,9 @@ class JSON {
const_iterator
find
(
const
char
*
)
const
;
const_iterator
find
(
const
char
*
)
const
;
/// direct access to the underlying payload
/// direct access to the underlying payload
v
oid
*
data
();
v
alue
data
();
/// direct access to the underlying payload
/// direct access to the underlying payload
const
v
oid
*
data
()
const
;
const
v
alue
data
()
const
;
/// lexicographically compares the values
/// lexicographically compares the values
bool
operator
==
(
const
JSON
&
)
const
;
bool
operator
==
(
const
JSON
&
)
const
;
...
...
test/JSON_test.cc
View file @
4e6a400a
...
@@ -145,7 +145,7 @@ void test_string() {
...
@@ -145,7 +145,7 @@ void test_string() {
{
{
// get payload
// get payload
std
::
string
*
s1
=
static_cast
<
std
::
string
*>
(
a
.
data
())
;
std
::
string
*
s1
=
a
.
data
().
string
;
std
::
string
s2
=
a
;
std
::
string
s2
=
a
;
assert
(
*
s1
==
s2
);
assert
(
*
s1
==
s2
);
}
}
...
@@ -271,7 +271,7 @@ void test_array() {
...
@@ -271,7 +271,7 @@ void test_array() {
{
{
// get payload
// get payload
std
::
vector
<
JSON
>*
array
=
static_cast
<
std
::
vector
<
JSON
>*>
(
a
.
data
())
;
std
::
vector
<
JSON
>*
array
=
a
.
data
().
array
;
assert
(
array
->
size
()
==
a
.
size
());
assert
(
array
->
size
()
==
a
.
size
());
assert
(
array
->
empty
()
==
a
.
empty
());
assert
(
array
->
empty
()
==
a
.
empty
());
}
}
...
...
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