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
7f359017
Commit
7f359017
authored
Jan 21, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename template argument Json -> BasicJsonType
parent
708eb961
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1183 additions
and
705 deletions
+1183
-705
src/json.hpp
src/json.hpp
+1007
-529
src/json.hpp.re2c
src/json.hpp.re2c
+147
-147
test/src/unit-udt.cpp
test/src/unit-udt.cpp
+29
-29
No files found.
src/json.hpp
View file @
7f359017
This diff is collapsed.
Click to expand it.
src/json.hpp.re2c
View file @
7f359017
This diff is collapsed.
Click to expand it.
test/src/unit-udt.cpp
View file @
7f359017
...
@@ -84,20 +84,20 @@ struct contact_book
...
@@ -84,20 +84,20 @@ struct contact_book
namespace
udt
namespace
udt
{
{
// templates because of the custom_json tests (see below)
// templates because of the custom_json tests (see below)
template
<
typename
Json
>
template
<
typename
BasicJsonType
>
void
to_json
(
Json
&
j
,
age
a
)
void
to_json
(
BasicJsonType
&
j
,
age
a
)
{
{
j
=
a
.
m_val
;
j
=
a
.
m_val
;
}
}
template
<
typename
Json
>
template
<
typename
BasicJsonType
>
void
to_json
(
Json
&
j
,
const
name
&
n
)
void
to_json
(
BasicJsonType
&
j
,
const
name
&
n
)
{
{
j
=
n
.
m_val
;
j
=
n
.
m_val
;
}
}
template
<
typename
Json
>
template
<
typename
BasicJsonType
>
void
to_json
(
Json
&
j
,
country
c
)
void
to_json
(
BasicJsonType
&
j
,
country
c
)
{
{
switch
(
c
)
switch
(
c
)
{
{
...
@@ -113,10 +113,10 @@ void to_json(Json& j, country c)
...
@@ -113,10 +113,10 @@ void to_json(Json& j, country c)
}
}
}
}
template
<
typename
Json
>
template
<
typename
BasicJsonType
>
void
to_json
(
Json
&
j
,
const
person
&
p
)
void
to_json
(
BasicJsonType
&
j
,
const
person
&
p
)
{
{
j
=
Json
{{
"age"
,
p
.
m_age
},
{
"name"
,
p
.
m_name
},
{
"country"
,
p
.
m_country
}};
j
=
BasicJsonType
{{
"age"
,
p
.
m_age
},
{
"name"
,
p
.
m_name
},
{
"country"
,
p
.
m_country
}};
}
}
void
to_json
(
nlohmann
::
json
&
j
,
const
address
&
a
)
void
to_json
(
nlohmann
::
json
&
j
,
const
address
&
a
)
...
@@ -171,20 +171,20 @@ bool operator==(const contact_book& lhs, const contact_book& rhs)
...
@@ -171,20 +171,20 @@ bool operator==(const contact_book& lhs, const contact_book& rhs)
// from_json methods
// from_json methods
namespace
udt
namespace
udt
{
{
template
<
typename
Json
>
template
<
typename
BasicJsonType
>
void
from_json
(
const
Json
&
j
,
age
&
a
)
void
from_json
(
const
BasicJsonType
&
j
,
age
&
a
)
{
{
a
.
m_val
=
j
.
template
get
<
int
>();
a
.
m_val
=
j
.
template
get
<
int
>();
}
}
template
<
typename
Json
>
template
<
typename
BasicJsonType
>
void
from_json
(
const
Json
&
j
,
name
&
n
)
void
from_json
(
const
BasicJsonType
&
j
,
name
&
n
)
{
{
n
.
m_val
=
j
.
template
get
<
std
::
string
>();
n
.
m_val
=
j
.
template
get
<
std
::
string
>();
}
}
template
<
typename
Json
>
template
<
typename
BasicJsonType
>
void
from_json
(
const
Json
&
j
,
country
&
c
)
void
from_json
(
const
BasicJsonType
&
j
,
country
&
c
)
{
{
const
auto
str
=
j
.
template
get
<
std
::
string
>();
const
auto
str
=
j
.
template
get
<
std
::
string
>();
static
const
std
::
map
<
std
::
string
,
country
>
m
=
static
const
std
::
map
<
std
::
string
,
country
>
m
=
...
@@ -199,8 +199,8 @@ void from_json(const Json& j, country& c)
...
@@ -199,8 +199,8 @@ void from_json(const Json& j, country& c)
c
=
it
->
second
;
c
=
it
->
second
;
}
}
template
<
typename
Json
>
template
<
typename
BasicJsonType
>
void
from_json
(
const
Json
&
j
,
person
&
p
)
void
from_json
(
const
BasicJsonType
&
j
,
person
&
p
)
{
{
p
.
m_age
=
j
[
"age"
].
template
get
<
age
>();
p
.
m_age
=
j
[
"age"
].
template
get
<
age
>();
p
.
m_name
=
j
[
"name"
].
template
get
<
name
>();
p
.
m_name
=
j
[
"name"
].
template
get
<
name
>();
...
@@ -493,20 +493,20 @@ struct pod_serializer
...
@@ -493,20 +493,20 @@ struct pod_serializer
{
{
// use adl for non-pods, or scalar types
// use adl for non-pods, or scalar types
template
<
template
<
typename
Json
,
typename
U
=
T
,
typename
BasicJsonType
,
typename
U
=
T
,
typename
std
::
enable_if
<
typename
std
::
enable_if
<
not
(
std
::
is_pod
<
U
>
::
value
and
std
::
is_class
<
U
>::
value
),
int
>::
type
=
0
>
not
(
std
::
is_pod
<
U
>
::
value
and
std
::
is_class
<
U
>::
value
),
int
>::
type
=
0
>
static
void
from_json
(
const
Json
&
j
,
U
&
t
)
static
void
from_json
(
const
BasicJsonType
&
j
,
U
&
t
)
{
{
using
nlohmann
::
from_json
;
using
nlohmann
::
from_json
;
from_json
(
j
,
t
);
from_json
(
j
,
t
);
}
}
// special behaviour for pods
// special behaviour for pods
template
<
typename
Json
,
typename
U
=
T
,
template
<
typename
BasicJsonType
,
typename
U
=
T
,
typename
std
::
enable_if
<
typename
std
::
enable_if
<
std
::
is_pod
<
U
>
::
value
and
std
::
is_class
<
U
>::
value
,
int
>::
type
=
0
>
std
::
is_pod
<
U
>
::
value
and
std
::
is_class
<
U
>::
value
,
int
>::
type
=
0
>
static
void
from_json
(
const
Json
&
j
,
U
&
t
)
static
void
from_json
(
const
BasicJsonType
&
j
,
U
&
t
)
{
{
std
::
uint64_t
value
;
std
::
uint64_t
value
;
// TODO The following block is no longer relevant in this serializer, make another one that shows the issue
// TODO The following block is no longer relevant in this serializer, make another one that shows the issue
...
@@ -529,19 +529,19 @@ struct pod_serializer
...
@@ -529,19 +529,19 @@ struct pod_serializer
}
}
template
<
template
<
typename
Json
,
typename
U
=
T
,
typename
BasicJsonType
,
typename
U
=
T
,
typename
std
::
enable_if
<
typename
std
::
enable_if
<
not
(
std
::
is_pod
<
U
>
::
value
and
std
::
is_class
<
U
>::
value
),
int
>::
type
=
0
>
not
(
std
::
is_pod
<
U
>
::
value
and
std
::
is_class
<
U
>::
value
),
int
>::
type
=
0
>
static
void
to_json
(
Json
&
j
,
const
T
&
t
)
static
void
to_json
(
BasicJsonType
&
j
,
const
T
&
t
)
{
{
using
nlohmann
::
to_json
;
using
nlohmann
::
to_json
;
to_json
(
j
,
t
);
to_json
(
j
,
t
);
}
}
template
<
typename
Json
,
typename
U
=
T
,
template
<
typename
BasicJsonType
,
typename
U
=
T
,
typename
std
::
enable_if
<
typename
std
::
enable_if
<
std
::
is_pod
<
U
>
::
value
and
std
::
is_class
<
U
>::
value
,
int
>::
type
=
0
>
std
::
is_pod
<
U
>
::
value
and
std
::
is_class
<
U
>::
value
,
int
>::
type
=
0
>
static
void
to_json
(
Json
&
j
,
const
T
&
t
)
noexcept
static
void
to_json
(
BasicJsonType
&
j
,
const
T
&
t
)
noexcept
{
{
auto
bytes
=
static_cast
<
const
unsigned
char
*>
(
static_cast
<
const
void
*>
(
&
t
));
auto
bytes
=
static_cast
<
const
unsigned
char
*>
(
static_cast
<
const
void
*>
(
&
t
));
std
::
uint64_t
value
=
bytes
[
0
];
std
::
uint64_t
value
=
bytes
[
0
];
...
@@ -565,14 +565,14 @@ struct non_pod
...
@@ -565,14 +565,14 @@ struct non_pod
std
::
string
s
;
std
::
string
s
;
};
};
template
<
typename
Json
>
template
<
typename
BasicJsonType
>
void
to_json
(
Json
&
j
,
const
non_pod
&
np
)
void
to_json
(
BasicJsonType
&
j
,
const
non_pod
&
np
)
{
{
j
=
np
.
s
;
j
=
np
.
s
;
}
}
template
<
typename
Json
>
template
<
typename
BasicJsonType
>
void
from_json
(
const
Json
&
j
,
non_pod
&
np
)
void
from_json
(
const
BasicJsonType
&
j
,
non_pod
&
np
)
{
{
np
.
s
=
j
.
template
get
<
std
::
string
>();
np
.
s
=
j
.
template
get
<
std
::
string
>();
}
}
...
...
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