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
4e6a400a
Commit
4e6a400a
authored
Jul 10, 2013
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- reorganized payload
parent
ec6e628d
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
145 additions
and
138 deletions
+145
-138
src/JSON.cc
src/JSON.cc
+108
-127
src/JSON.h
src/JSON.h
+35
-9
test/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 {
array
,
object
,
null
,
string
,
boolean
,
number
,
number_float
}
json_t
;
private:
/// the type of this object
json_t
_type
;
/// the payload
void
*
_payload
;
public:
/// a type for an object
typedef
std
::
map
<
std
::
string
,
JSON
>
object_t
;
/// a type for an array
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
/// a type for array initialization
...
...
@@ -190,9 +216,9 @@ class JSON {
const_iterator
find
(
const
char
*
)
const
;
/// direct access to the underlying payload
v
oid
*
data
();
v
alue
data
();
/// direct access to the underlying payload
const
v
oid
*
data
()
const
;
const
v
alue
data
()
const
;
/// lexicographically compares the values
bool
operator
==
(
const
JSON
&
)
const
;
...
...
test/JSON_test.cc
View file @
4e6a400a
...
...
@@ -145,7 +145,7 @@ void test_string() {
{
// get payload
std
::
string
*
s1
=
static_cast
<
std
::
string
*>
(
a
.
data
())
;
std
::
string
*
s1
=
a
.
data
().
string
;
std
::
string
s2
=
a
;
assert
(
*
s1
==
s2
);
}
...
...
@@ -271,7 +271,7 @@ void test_array() {
{
// 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
->
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