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
3e15b551
Commit
3e15b551
authored
Jan 17, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
run make pretty
parent
fbac056c
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
983 additions
and
425 deletions
+983
-425
json.hpp
src/json.hpp
+802
-284
json.hpp.re2c
src/json.hpp.re2c
+137
-97
unit-conversions.cpp
test/src/unit-conversions.cpp
+0
-0
unit-noexcept.cpp
test/src/unit-noexcept.cpp
+2
-2
unit-regression.cpp
test/src/unit-regression.cpp
+1
-1
unit-udt.cpp
test/src/unit-udt.cpp
+41
-41
No files found.
src/json.hpp
View file @
3e15b551
...
...
@@ -168,7 +168,7 @@ using is_unscoped_enum =
namespace
detail
{
template
<
typename
Json
>
std
::
string
type_name
(
const
Json
&
j
)
template
<
typename
Json
>
std
::
string
type_name
(
const
Json
&
j
)
{
switch
(
j
.
m_type
)
{
...
...
@@ -190,7 +190,7 @@ template <typename Json> std::string type_name(const Json &j)
}
// dispatch utility (taken from ranges-v3)
template
<
unsigned
N
>
struct
priority_tag
:
priority_tag
<
N
-
1
>
{};
template
<
unsigned
N
>
struct
priority_tag
:
priority_tag
<
N
-
1
>
{};
template
<>
struct
priority_tag
<
0
>
{};
...
...
@@ -202,7 +202,7 @@ template <>
struct
external_constructor
<
value_t
::
boolean
>
{
template
<
typename
Json
>
static
void
construct
(
Json
&
j
,
typename
Json
::
boolean_t
b
)
noexcept
static
void
construct
(
Json
&
j
,
typename
Json
::
boolean_t
b
)
noexcept
{
j
.
m_type
=
value_t
::
boolean
;
j
.
m_value
=
b
;
...
...
@@ -214,7 +214,7 @@ template <>
struct
external_constructor
<
value_t
::
string
>
{
template
<
typename
Json
>
static
void
construct
(
Json
&
j
,
const
typename
Json
::
string_t
&
s
)
static
void
construct
(
Json
&
j
,
const
typename
Json
::
string_t
&
s
)
{
j
.
m_type
=
value_t
::
string
;
j
.
m_value
=
s
;
...
...
@@ -226,7 +226,7 @@ template <>
struct
external_constructor
<
value_t
::
number_float
>
{
template
<
typename
Json
>
static
void
construct
(
Json
&
j
,
typename
Json
::
number_float_t
val
)
noexcept
static
void
construct
(
Json
&
j
,
typename
Json
::
number_float_t
val
)
noexcept
{
// replace infinity and NAN by null
if
(
not
std
::
isfinite
(
val
))
...
...
@@ -244,7 +244,7 @@ template <>
struct
external_constructor
<
value_t
::
number_unsigned
>
{
template
<
typename
Json
>
static
void
construct
(
Json
&
j
,
typename
Json
::
number_unsigned_t
val
)
noexcept
static
void
construct
(
Json
&
j
,
typename
Json
::
number_unsigned_t
val
)
noexcept
{
j
.
m_type
=
value_t
::
number_unsigned
;
j
.
m_value
=
val
;
...
...
@@ -256,7 +256,7 @@ template <>
struct
external_constructor
<
value_t
::
number_integer
>
{
template
<
typename
Json
>
static
void
construct
(
Json
&
j
,
typename
Json
::
number_integer_t
val
)
noexcept
static
void
construct
(
Json
&
j
,
typename
Json
::
number_integer_t
val
)
noexcept
{
j
.
m_type
=
value_t
::
number_integer
;
j
.
m_value
=
val
;
...
...
@@ -268,7 +268,7 @@ template <>
struct
external_constructor
<
value_t
::
array
>
{
template
<
typename
Json
>
static
void
construct
(
Json
&
j
,
const
typename
Json
::
array_t
&
arr
)
static
void
construct
(
Json
&
j
,
const
typename
Json
::
array_t
&
arr
)
{
j
.
m_type
=
value_t
::
array
;
j
.
m_value
=
arr
;
...
...
@@ -279,7 +279,7 @@ struct external_constructor<value_t::array>
enable_if_t
<
not
std
::
is_same
<
CompatibleArrayType
,
typename
Json
::
array_t
>::
value
,
int
>
=
0
>
static
void
construct
(
Json
&
j
,
const
CompatibleArrayType
&
arr
)
static
void
construct
(
Json
&
j
,
const
CompatibleArrayType
&
arr
)
{
using
std
::
begin
;
using
std
::
end
;
...
...
@@ -294,7 +294,7 @@ template <>
struct
external_constructor
<
value_t
::
object
>
{
template
<
typename
Json
>
static
void
construct
(
Json
&
j
,
const
typename
Json
::
object_t
&
obj
)
static
void
construct
(
Json
&
j
,
const
typename
Json
::
object_t
&
obj
)
{
j
.
m_type
=
value_t
::
object
;
j
.
m_value
=
obj
;
...
...
@@ -305,7 +305,7 @@ struct external_constructor<value_t::object>
enable_if_t
<
not
std
::
is_same
<
CompatibleObjectType
,
typename
Json
::
object_t
>::
value
,
int
>
=
0
>
static
void
construct
(
Json
&
j
,
const
CompatibleObjectType
&
obj
)
static
void
construct
(
Json
&
j
,
const
CompatibleObjectType
&
obj
)
{
using
std
::
begin
;
using
std
::
end
;
...
...
@@ -380,11 +380,11 @@ struct is_compatible_object_type_impl<true, RealType, CompatibleObjectType>
template
<
class
BasicJson
,
class
CompatibleObjectType
>
struct
is_compatible_object_type
{
static
auto
constexpr
value
=
is_compatible_object_type_impl
<
static
auto
constexpr
value
=
is_compatible_object_type_impl
<
conjunction
<
negation
<
std
::
is_same
<
void
,
CompatibleObjectType
>>
,
has_mapped_type
<
CompatibleObjectType
>
,
has_key_type
<
CompatibleObjectType
>>::
value
,
typename
BasicJson
::
object_t
,
CompatibleObjectType
>::
value
;
typename
BasicJson
::
object_t
,
CompatibleObjectType
>::
value
;
};
template
<
typename
BasicJson
,
typename
T
>
...
...
@@ -461,15 +461,15 @@ struct has_from_json
template
<
typename
Json
,
typename
T
>
struct
has_non_default_from_json
{
private
:
private
:
template
<
typename
U
,
typename
=
enable_if_t
<
std
::
is_same
<
T
,
decltype
(
uncvref_t
<
U
>::
from_json
(
std
::
declval
<
Json
>
()))
>::
value
>>
static
int
detect
(
U
&&
);
T
,
decltype
(
uncvref_t
<
U
>::
from_json
(
std
::
declval
<
Json
>
()))
>::
value
>>
static
int
detect
(
U
&&
);
static
void
detect
(...);
public
:
public
:
static
constexpr
bool
value
=
std
::
is_integral
<
decltype
(
detect
(
std
::
declval
<
typename
Json
::
template
json_serializer
<
T
,
void
>>
()))
>::
value
;
};
...
...
@@ -478,13 +478,13 @@ public:
template
<
typename
Json
,
typename
T
>
struct
has_to_json
{
private
:
private
:
template
<
typename
U
,
typename
=
decltype
(
uncvref_t
<
U
>::
to_json
(
std
::
declval
<
Json
&>
(),
std
::
declval
<
T
>
()))
>
static
int
detect
(
U
&&
);
std
::
declval
<
Json
&>
(),
std
::
declval
<
T
>
()))
>
static
int
detect
(
U
&&
);
static
void
detect
(...);
public
:
public
:
static
constexpr
bool
value
=
std
::
is_integral
<
decltype
(
detect
(
std
::
declval
<
typename
Json
::
template
json_serializer
<
T
,
void
>>
()))
>::
value
;
};
...
...
@@ -496,21 +496,29 @@ template <typename Json, typename ArithmeticType,
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
boolean_t
>::
value
,
int
>
=
0
>
void
get_arithmetic_value
(
const
Json
&
j
,
ArithmeticType
&
val
)
void
get_arithmetic_value
(
const
Json
&
j
,
ArithmeticType
&
val
)
{
// unsigned must be checked first, since is_number_integer() == true for unsigned
if
(
j
.
is_number_unsigned
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_unsigned_t
*>
());
}
else
if
(
j
.
is_number_integer
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_integer_t
*>
());
}
else
if
(
j
.
is_number_float
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_float_t
*>
());
}
else
{
throw
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
));
}
}
template
<
typename
Json
>
void
to_json
(
Json
&
j
,
typename
Json
::
boolean_t
b
)
noexcept
void
to_json
(
Json
&
j
,
typename
Json
::
boolean_t
b
)
noexcept
{
external_constructor
<
value_t
::
boolean
>::
construct
(
j
,
b
);
}
...
...
@@ -519,14 +527,14 @@ template <typename Json, typename CompatibleString,
enable_if_t
<
std
::
is_constructible
<
typename
Json
::
string_t
,
CompatibleString
>::
value
,
int
>
=
0
>
void
to_json
(
Json
&
j
,
const
CompatibleString
&
s
)
void
to_json
(
Json
&
j
,
const
CompatibleString
&
s
)
{
external_constructor
<
value_t
::
string
>::
construct
(
j
,
s
);
}
template
<
typename
Json
,
typename
FloatType
,
enable_if_t
<
std
::
is_floating_point
<
FloatType
>::
value
,
int
>
=
0
>
void
to_json
(
Json
&
j
,
FloatType
val
)
noexcept
void
to_json
(
Json
&
j
,
FloatType
val
)
noexcept
{
external_constructor
<
value_t
::
number_float
>::
construct
(
j
,
static_cast
<
typename
Json
::
number_float_t
>
(
val
));
}
...
...
@@ -536,8 +544,8 @@ template <
typename
Json
,
typename
CompatibleNumberUnsignedType
,
enable_if_t
<
is_compatible_integer_type
<
typename
Json
::
number_unsigned_t
,
CompatibleNumberUnsignedType
>::
value
,
int
>
=
0
>
void
to_json
(
Json
&
j
,
CompatibleNumberUnsignedType
val
)
noexcept
int
>
=
0
>
void
to_json
(
Json
&
j
,
CompatibleNumberUnsignedType
val
)
noexcept
{
external_constructor
<
value_t
::
number_unsigned
>::
construct
(
j
,
static_cast
<
typename
Json
::
number_unsigned_t
>
(
val
));
}
...
...
@@ -546,26 +554,26 @@ template <
typename
Json
,
typename
CompatibleNumberIntegerType
,
enable_if_t
<
is_compatible_integer_type
<
typename
Json
::
number_integer_t
,
CompatibleNumberIntegerType
>::
value
,
int
>
=
0
>
void
to_json
(
Json
&
j
,
CompatibleNumberIntegerType
val
)
noexcept
int
>
=
0
>
void
to_json
(
Json
&
j
,
CompatibleNumberIntegerType
val
)
noexcept
{
external_constructor
<
value_t
::
number_integer
>::
construct
(
j
,
static_cast
<
typename
Json
::
number_integer_t
>
(
val
));
}
template
<
typename
Json
,
typename
UnscopedEnumType
,
enable_if_t
<
is_unscoped_enum
<
UnscopedEnumType
>::
value
,
int
>
=
0
>
void
to_json
(
Json
&
j
,
UnscopedEnumType
e
)
noexcept
void
to_json
(
Json
&
j
,
UnscopedEnumType
e
)
noexcept
{
external_constructor
<
value_t
::
number_integer
>::
construct
(
j
,
e
);
}
template
<
typename
Json
,
typename
CompatibleArrayType
,
enable_if_t
<
enable_if_t
<
is_compatible_array_type
<
Json
,
CompatibleArrayType
>::
value
or
std
::
is_same
<
typename
Json
::
array_t
,
CompatibleArrayType
>::
value
,
int
>
=
0
>
void
to_json
(
Json
&
j
,
const
CompatibleArrayType
&
arr
)
int
>
=
0
>
void
to_json
(
Json
&
j
,
const
CompatibleArrayType
&
arr
)
{
external_constructor
<
value_t
::
array
>::
construct
(
j
,
arr
);
}
...
...
@@ -573,49 +581,53 @@ void to_json(Json &j, const CompatibleArrayType &arr)
template
<
typename
Json
,
typename
CompatibleObjectType
,
enable_if_t
<
is_compatible_object_type
<
Json
,
CompatibleObjectType
>::
value
,
int
>
=
0
>
void
to_json
(
Json
&
j
,
const
CompatibleObjectType
&
arr
)
int
>
=
0
>
void
to_json
(
Json
&
j
,
const
CompatibleObjectType
&
arr
)
{
external_constructor
<
value_t
::
object
>::
construct
(
j
,
arr
);
}
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
typename
Json
::
boolean_t
&
b
)
void
from_json
(
const
Json
&
j
,
typename
Json
::
boolean_t
&
b
)
{
if
(
!
j
.
is_boolean
())
{
throw
std
::
domain_error
(
"type must be boolean, but is "
+
type_name
(
j
));
}
b
=
*
j
.
template
get_ptr
<
const
typename
Json
::
boolean_t
*>
();
}
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
typename
Json
::
string_t
&
s
)
void
from_json
(
const
Json
&
j
,
typename
Json
::
string_t
&
s
)
{
if
(
!
j
.
is_string
())
{
throw
std
::
domain_error
(
"type must be string, but is "
+
type_name
(
j
));
}
s
=
*
j
.
template
get_ptr
<
const
typename
Json
::
string_t
*>
();
}
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
typename
Json
::
number_float_t
&
val
)
void
from_json
(
const
Json
&
j
,
typename
Json
::
number_float_t
&
val
)
{
get_arithmetic_value
(
j
,
val
);
}
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
typename
Json
::
number_unsigned_t
&
val
)
void
from_json
(
const
Json
&
j
,
typename
Json
::
number_unsigned_t
&
val
)
{
get_arithmetic_value
(
j
,
val
);
}
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
typename
Json
::
number_integer_t
&
val
)
void
from_json
(
const
Json
&
j
,
typename
Json
::
number_integer_t
&
val
)
{
get_arithmetic_value
(
j
,
val
);
}
template
<
typename
Json
,
typename
UnscopedEnumType
,
enable_if_t
<
is_unscoped_enum
<
UnscopedEnumType
>::
value
,
int
>
=
0
>
void
from_json
(
const
Json
&
j
,
UnscopedEnumType
&
e
)
void
from_json
(
const
Json
&
j
,
UnscopedEnumType
&
e
)
{
typename
std
::
underlying_type
<
UnscopedEnumType
>::
type
val
=
e
;
get_arithmetic_value
(
j
,
val
);
...
...
@@ -623,38 +635,46 @@ void from_json(const Json &j, UnscopedEnumType& e)
}
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
typename
Json
::
array_t
&
arr
)
void
from_json
(
const
Json
&
j
,
typename
Json
::
array_t
&
arr
)
{
if
(
!
j
.
is_array
())
{
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
(
j
));
}
arr
=
*
j
.
template
get_ptr
<
const
typename
Json
::
array_t
*>
();
}
// forward_list doesn't have an insert method, TODO find a way to avoid including forward_list
template
<
typename
Json
,
typename
T
,
typename
Allocator
>
void
from_json
(
const
Json
&
j
,
std
::
forward_list
<
T
,
Allocator
>&
l
)
void
from_json
(
const
Json
&
j
,
std
::
forward_list
<
T
,
Allocator
>&
l
)
{
// do not perform the check when user wants to retrieve jsons
// (except when it's null.. ?)
if
(
j
.
is_null
())
{
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
(
j
));
}
if
(
not
std
::
is_same
<
T
,
Json
>::
value
)
{
if
(
!
j
.
is_array
())
{
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
(
j
));
}
}
for
(
auto
it
=
j
.
rbegin
(),
end
=
j
.
rend
();
it
!=
end
;
++
it
)
{
l
.
push_front
(
it
->
template
get
<
T
>
());
}
}
template
<
typename
Json
,
typename
CompatibleArrayType
>
void
from_json_array_impl
(
const
Json
&
j
,
CompatibleArrayType
&
arr
,
priority_tag
<
0
>
)
void
from_json_array_impl
(
const
Json
&
j
,
CompatibleArrayType
&
arr
,
priority_tag
<
0
>
)
{
using
std
::
begin
;
using
std
::
end
;
std
::
transform
(
j
.
begin
(),
j
.
end
(),
std
::
inserter
(
arr
,
end
(
arr
)),
[](
const
Json
&
i
)
j
.
begin
(),
j
.
end
(),
std
::
inserter
(
arr
,
end
(
arr
)),
[](
const
Json
&
i
)
{
// get<Json>() returns *this, this won't call a from_json method when
// value_type is Json
...
...
@@ -663,8 +683,8 @@ void from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag
}
template
<
typename
Json
,
typename
CompatibleArrayType
>
auto
from_json_array_impl
(
const
Json
&
j
,
CompatibleArrayType
&
arr
,
priority_tag
<
1
>
)
->
decltype
(
auto
from_json_array_impl
(
const
Json
&
j
,
CompatibleArrayType
&
arr
,
priority_tag
<
1
>
)
->
decltype
(
arr
.
reserve
(
std
::
declval
<
typename
CompatibleArrayType
::
size_type
>
()),
void
())
{
...
...
@@ -673,7 +693,7 @@ auto from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag
arr
.
reserve
(
j
.
size
());
std
::
transform
(
j
.
begin
(),
j
.
end
(),
std
::
inserter
(
arr
,
end
(
arr
)),
[](
const
Json
&
i
)
j
.
begin
(),
j
.
end
(),
std
::
inserter
(
arr
,
end
(
arr
)),
[](
const
Json
&
i
)
{
// get<Json>() returns *this, this won't call a from_json method when
// value_type is Json
...
...
@@ -686,29 +706,35 @@ template <
enable_if_t
<
is_compatible_array_type
<
Json
,
CompatibleArrayType
>::
value
and
not
std
::
is_same
<
typename
Json
::
array_t
,
CompatibleArrayType
>::
value
,
int
>
=
0
>
void
from_json
(
const
Json
&
j
,
CompatibleArrayType
&
arr
)
int
>
=
0
>
void
from_json
(
const
Json
&
j
,
CompatibleArrayType
&
arr
)
{
if
(
j
.
is_null
())
{
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
(
j
));
}
// when T == Json, do not check if value_t is correct
if
(
not
std
::
is_same
<
typename
CompatibleArrayType
::
value_type
,
Json
>::
value
)
{
if
(
!
j
.
is_array
())
{
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
(
j
));
}
from_json_array_impl
(
j
,
arr
,
priority_tag
<
1
>
{});
}
from_json_array_impl
(
j
,
arr
,
priority_tag
<
1
>
{});
}
template
<
typename
Json
,
typename
CompatibleObjectType
,
enable_if_t
<
is_compatible_object_type
<
Json
,
CompatibleObjectType
>::
value
,
int
>
=
0
>
void
from_json
(
const
Json
&
j
,
CompatibleObjectType
&
obj
)
int
>
=
0
>
void
from_json
(
const
Json
&
j
,
CompatibleObjectType
&
obj
)
{
if
(
!
j
.
is_object
())
{
throw
std
::
domain_error
(
"type must be object, but is "
+
type_name
(
j
));
}
auto
inner_object
=
j
.
template
get_ptr
<
const
typename
Json
::
object_t
*>
();
using
std
::
begin
;
...
...
@@ -724,25 +750,35 @@ void from_json(const Json &j, CompatibleObjectType &obj)
// in case of a custom BooleanType which is not an arithmetic type?
template
<
typename
Json
,
typename
ArithmeticType
,
enable_if_t
<
enable_if_t
<
std
::
is_arithmetic
<
ArithmeticType
>::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
number_unsigned_t
>::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
number_integer_t
>::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
number_float_t
>::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
boolean_t
>::
value
,
int
>
=
0
>
void
from_json
(
const
Json
&
j
,
ArithmeticType
&
val
)
int
>
=
0
>
void
from_json
(
const
Json
&
j
,
ArithmeticType
&
val
)
{
if
(
j
.
is_number_unsigned
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_unsigned_t
*>
());
}
else
if
(
j
.
is_number_integer
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_integer_t
*>
());
}
else
if
(
j
.
is_number_float
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_float_t
*>
());
}
else
if
(
j
.
is_boolean
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
boolean_t
*>
());
}
else
{
throw
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
));
}
}
struct
to_json_fn
...
...
@@ -762,20 +798,20 @@ struct to_json_fn
static_assert
(
sizeof
(
Json
)
==
0
,
"to_json method in T's namespace can not be called"
);
}
public
:
public
:
template
<
typename
Json
,
typename
T
>
void
operator
()(
Json
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
to_json_fn
>
().
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{})))
void
operator
()(
Json
&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
to_json_fn
>
().
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{})))
{
return
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{});
return
call
(
j
,
std
::
forward
<
T
>
(
val
),
priority_tag
<
1
>
{});
}
};
struct
from_json_fn
{
private
:
private
:
template
<
typename
Json
,
typename
T
>
auto
call
(
const
Json
&
j
,
T
&
val
,
priority_tag
<
1
>
)
const
auto
call
(
const
Json
&
j
,
T
&
val
,
priority_tag
<
1
>
)
const
noexcept
(
noexcept
(
from_json
(
j
,
val
)))
->
decltype
(
from_json
(
j
,
val
),
void
())
{
...
...
@@ -783,17 +819,17 @@ private:
}
template
<
typename
Json
,
typename
T
>
void
call
(
const
Json
&
,
T
&
,
priority_tag
<
0
>
)
const
noexcept
void
call
(
const
Json
&
,
T
&
,
priority_tag
<
0
>
)
const
noexcept
{
static_assert
(
sizeof
(
Json
)
==
0
,
"from_json method in T's namespace can not be called"
);
}
public
:
public
:
template
<
typename
Json
,
typename
T
>
void
operator
()(
const
Json
&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
from_json_fn
>
().
call
(
j
,
val
,
priority_tag
<
1
>
{})))
void
operator
()(
const
Json
&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
std
::
declval
<
from_json_fn
>
().
call
(
j
,
val
,
priority_tag
<
1
>
{})))
{
return
call
(
j
,
val
,
priority_tag
<
1
>
{});
return
call
(
j
,
val
,
priority_tag
<
1
>
{});
}
};
...
...
@@ -830,8 +866,8 @@ struct DecimalSeparator : std::numpunct<char>
inline
namespace
{
constexpr
const
auto
&
to_json
=
detail
::
static_const
<
detail
::
to_json_fn
>::
value
;
constexpr
const
auto
&
from_json
=
detail
::
static_const
<
detail
::
from_json_fn
>::
value
;
constexpr
const
auto
&
to_json
=
detail
::
static_const
<
detail
::
to_json_fn
>::
value
;
constexpr
const
auto
&
from_json
=
detail
::
static_const
<
detail
::
from_json_fn
>::
value
;
}
// default JSONSerializer template argument, doesn't care about template argument
...
...
@@ -846,7 +882,7 @@ struct adl_serializer
}
template
<
typename
Json
,
typename
T
>
static
void
to_json
(
Json
&
j
,
T
&&
val
)
noexcept
(
static
void
to_json
(
Json
&
j
,
T
&&
val
)
noexcept
(
noexcept
(
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
T
>
(
val
))))
{
::
nlohmann
::
to_json
(
j
,
std
::
forward
<
T
>
(
val
));
...
...
@@ -947,7 +983,7 @@ class basic_json
{
private
:
template
<::
nlohmann
::
value_t
>
friend
struct
detail
::
external_constructor
;
template
<
typename
Json
>
friend
std
::
string
detail
::
type_name
(
const
Json
&
);
template
<
typename
Json
>
friend
std
::
string
detail
::
type_name
(
const
Json
&
);
/// workaround type for MSVC
using
basic_json_t
=
basic_json
<
ObjectType
,
ArrayType
,
StringType
,
BooleanType
,
NumberIntegerType
,
NumberUnsignedType
,
NumberFloatType
,
...
...
@@ -1854,8 +1890,8 @@ class basic_json
basic_json_t
,
U
>::
value
and
detail
::
has_to_json
<
basic_json
,
U
>::
value
,
int
>
=
0
>
basic_json
(
T
&&
val
)
noexcept
(
noexcept
(
JSONSerializer
<
U
>::
to_json
(
std
::
declval
<
basic_json_t
&>
(),
std
::
forward
<
T
>
(
val
))))
basic_json
(
T
&&
val
)
noexcept
(
noexcept
(
JSONSerializer
<
U
>::
to_json
(
std
::
declval
<
basic_json_t
&>
(),
std
::
forward
<
T
>
(
val
))))
{
JSONSerializer
<
U
>::
to_json
(
*
this
,
std
::
forward
<
T
>
(
val
));
}
...
...
@@ -3041,17 +3077,17 @@ class basic_json
template
<
typename
T
,
typename
U
=
uncvref_t
<
T
>
,
enable_if_t
<
enable_if_t
<
not
std
::
is_same
<
basic_json_t
,
U
>::
value
and
detail
::
has_from_json
<
basic_json_t
,
U
>::
value
and
not
detail
::
has_non_default_from_json
<
basic_json_t
,
U
>::
value
,
int
>
=
0
>
int
>
=
0
>
// do we really want the uncvref ? if a user call get<int &>, shouldn't we
// static assert ?
// i know there is a special behaviour for boolean_t* and such
auto
get
()
const
noexcept
(
noexcept
(
JSONSerializer
<
U
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
std
::
declval
<
U
&>
())))
std
::
declval
<
const
basic_json_t
&>
(),
std
::
declval
<
U
&>
())))
->
U
{
static_assert
(
std
::
is_default_constructible
<
U
>::
value
and
...
...
@@ -3083,8 +3119,8 @@ class basic_json
enable_if_t
<
not
std
::
is_same
<
basic_json_t
,
uncvref_t
<
T
>>::
value
and
detail
::
has_non_default_from_json
<
basic_json_t
,
uncvref_t
<
T
>>::
value
,
int
>
=
0
>
uncvref_t
<
T
>
get
()
const
noexcept
(
noexcept
(
JSONSerializer
<
T
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
())))
int
>
=
0
>
uncvref_t
<
T
>
get
()
const
noexcept
(
noexcept
(
JSONSerializer
<
T
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
())))
{
return
JSONSerializer
<
T
>::
from_json
(
*
this
);
}
...
...
@@ -7871,7 +7907,10 @@ class basic_json
@since version 1.0.0
*/
std
::
string
type_name
()
const
{
return
detail
::
type_name
(
*
this
);
}
std
::
string
type_name
()
const
{
return
detail
::
type_name
(
*
this
);
}
private
:
/*!
...
...
@@ -9427,7 +9466,8 @@ class basic_json
{
lexer_char_t
yych
;
unsigned
int
yyaccept
=
0
;
static
const
unsigned
char
yybm
[]
=
{
static
const
unsigned
char
yybm
[]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
32
,
32
,
0
,
0
,
32
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
...
...
@@ -9461,396 +9501,873 @@ class basic_json
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
};
if
((
m_limit
-
m_cursor
)
<
5
)
fill_line_buffer
(
5
);
// LCOV_EXCL_LINE
if
((
m_limit
-
m_cursor
)
<
5
)
{
fill_line_buffer
(
5
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yybm
[
0
+
yych
]
&
32
)
{
if
(
yybm
[
0
+
yych
]
&
32
)
{
goto
basic_json_parser_6
;
}
if
(
yych
<=
'['
)
{
if
(
yych
<=
'-'
)
{
if
(
yych
<=
'"'
)
{
if
(
yych
<=
0x00
)
goto
basic_json_parser_2
;
if
(
yych
<=
'!'
)
goto
basic_json_parser_4
;
if
(
yych
<=
'['
)
{
if
(
yych
<=
'-'
)
{
if
(
yych
<=
'"'
)
{
if
(
yych
<=
0x00
)
{
goto
basic_json_parser_2
;
}
if
(
yych
<=
'!'
)
{
goto
basic_json_parser_4
;
}
goto
basic_json_parser_9
;
}
else
{
if
(
yych
<=
'+'
)
goto
basic_json_parser_4
;
if
(
yych
<=
','
)
goto
basic_json_parser_10
;
}
else
{
if
(
yych
<=
'+'
)
{
goto
basic_json_parser_4
;
}
if
(
yych
<=
','
)
{
goto
basic_json_parser_10
;
}
goto
basic_json_parser_12
;
}
}
else
{
if
(
yych
<=
'9'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_4
;
if
(
yych
<=
'0'
)
goto
basic_json_parser_13
;
}
else
{
if
(
yych
<=
'9'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_4
;
}
if
(
yych
<=
'0'
)
{
goto
basic_json_parser_13
;
}
goto
basic_json_parser_15
;
}
else
{
if
(
yych
<=
':'
)
goto
basic_json_parser_17
;
if
(
yych
<=
'Z'
)
goto
basic_json_parser_4
;
}
else
{
if
(
yych
<=
':'
)
{
goto
basic_json_parser_17
;
}
if
(
yych
<=
'Z'
)
{
goto
basic_json_parser_4
;
}
goto
basic_json_parser_19
;
}
}
}
else
{
if
(
yych
<=
'n'
)
{
if
(
yych
<=
'e'
)
{
if
(
yych
==
']'
)
goto
basic_json_parser_21
;
}
else
{
if
(
yych
<=
'n'
)
{
if
(
yych
<=
'e'
)
{
if
(
yych
==
']'
)
{
goto
basic_json_parser_21
;
}
goto
basic_json_parser_4
;
}
else
{
if
(
yych
<=
'f'
)
{
goto
basic_json_parser_23
;
}
if
(
yych
<=
'm'
)
{
goto
basic_json_parser_4
;
}
else
{
if
(
yych
<=
'f'
)
goto
basic_json_parser_23
;
if
(
yych
<=
'm'
)
goto
basic_json_parser_4
;
}
goto
basic_json_parser_24
;
}
}
else
{
if
(
yych
<=
'z'
)
{
if
(
yych
==
't'
)
goto
basic_json_parser_25
;
}
else
{
if
(
yych
<=
'z'
)
{
if
(
yych
==
't'
)
{
goto
basic_json_parser_25
;
}
goto
basic_json_parser_4
;
}
else
{
if
(
yych
<=
'{'
)
goto
basic_json_parser_26
;
if
(
yych
==
'}'
)
goto
basic_json_parser_28
;
}
else
{
if
(
yych
<=
'{'
)
{
goto
basic_json_parser_26
;
}
if
(
yych
==
'}'
)
{
goto
basic_json_parser_28
;
}
goto
basic_json_parser_4
;
}
}
}
basic_json_parser_2
:
++
m_cursor
;
{
last_token_type
=
token_type
::
end_of_input
;
break
;
}
{
last_token_type
=
token_type
::
end_of_input
;
break
;
}
basic_json_parser_4
:
++
m_cursor
;
basic_json_parser_5
:
{
last_token_type
=
token_type
::
parse_error
;
break
;
}
{
last_token_type
=
token_type
::
parse_error
;
break
;
}
basic_json_parser_6
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yybm
[
0
+
yych
]
&
32
)
{
if
(
yybm
[
0
+
yych
]
&
32
)
{
goto
basic_json_parser_6
;
}
{
continue
;
}
{
continue
;
}
basic_json_parser_9
:
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
<=
0x1F
)
goto
basic_json_parser_5
;
if
(
yych
<=
0x7F
)
goto
basic_json_parser_31
;
if
(
yych
<=
0xC1
)
goto
basic_json_parser_5
;
if
(
yych
<=
0xF4
)
goto
basic_json_parser_31
;
if
(
yych
<=
0x1F
)
{
goto
basic_json_parser_5
;
}
if
(
yych
<=
0x7F
)
{
goto
basic_json_parser_31
;
}
if
(
yych
<=
0xC1
)
{
goto
basic_json_parser_5
;
}
if
(
yych
<=
0xF4
)
{
goto
basic_json_parser_31
;
}
goto
basic_json_parser_5
;
basic_json_parser_10
:
++
m_cursor
;
{
last_token_type
=
token_type
::
value_separator
;
break
;
}
{
last_token_type
=
token_type
::
value_separator
;
break
;
}
basic_json_parser_12
:
yych
=
*++
m_cursor
;
if
(
yych
<=
'/'
)
goto
basic_json_parser_5
;
if
(
yych
<=
'0'
)
goto
basic_json_parser_13
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_15
;
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_5
;
}
if
(
yych
<=
'0'
)
{
goto
basic_json_parser_13
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_15
;
}
goto
basic_json_parser_5
;
basic_json_parser_13
:
yyaccept
=
1
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
<=
'D'
)
{
if
(
yych
==
'.'
)
goto
basic_json_parser_43
;
}
else
{
if
(
yych
<=
'E'
)
goto
basic_json_parser_44
;
if
(
yych
==
'e'
)
goto
basic_json_parser_44
;
if
(
yych
<=
'D'
)
{
if
(
yych
==
'.'
)
{
goto
basic_json_parser_43
;
}
}
else
{
if
(
yych
<=
'E'
)
{
goto
basic_json_parser_44
;
}
if
(
yych
==
'e'
)
{
goto
basic_json_parser_44
;
}
}
basic_json_parser_14
:
{
last_token_type
=
token_type
::
value_number
;
break
;
}
{
last_token_type
=
token_type
::
value_number
;
break
;
}
basic_json_parser_15
:
yyaccept
=
1
;
m_marker
=
++
m_cursor
;
if
((
m_limit
-
m_cursor
)
<
3
)
fill_line_buffer
(
3
);
// LCOV_EXCL_LINE
if
((
m_limit
-
m_cursor
)
<
3
)
{
fill_line_buffer
(
3
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yybm
[
0
+
yych
]
&
64
)
{
if
(
yybm
[
0
+
yych
]
&
64
)
{
goto
basic_json_parser_15
;
}
if
(
yych
<=
'D'
)
{
if
(
yych
==
'.'
)
goto
basic_json_parser_43
;
if
(
yych
<=
'D'
)
{
if
(
yych
==
'.'
)
{
goto
basic_json_parser_43
;
}
goto
basic_json_parser_14
;
}
else
{
if
(
yych
<=
'E'
)
goto
basic_json_parser_44
;
if
(
yych
==
'e'
)
goto
basic_json_parser_44
;
}
else
{
if
(
yych
<=
'E'
)
{
goto
basic_json_parser_44
;
}
if
(
yych
==
'e'
)
{
goto
basic_json_parser_44
;
}
goto
basic_json_parser_14
;
}
basic_json_parser_17
:
++
m_cursor
;
{
last_token_type
=
token_type
::
name_separator
;
break
;
}
{
last_token_type
=
token_type
::
name_separator
;
break
;
}
basic_json_parser_19
:
++
m_cursor
;
{
last_token_type
=
token_type
::
begin_array
;
break
;
}
{
last_token_type
=
token_type
::
begin_array
;
break
;
}
basic_json_parser_21
:
++
m_cursor
;
{
last_token_type
=
token_type
::
end_array
;
break
;
}
{
last_token_type
=
token_type
::
end_array
;
break
;
}
basic_json_parser_23
:
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
'a'
)
goto
basic_json_parser_45
;
if
(
yych
==
'a'
)
{
goto
basic_json_parser_45
;
}
goto
basic_json_parser_5
;
basic_json_parser_24
:
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
'u'
)
goto
basic_json_parser_46
;
if
(
yych
==
'u'
)
{
goto
basic_json_parser_46
;
}
goto
basic_json_parser_5
;
basic_json_parser_25
:
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
'r'
)
goto
basic_json_parser_47
;
if
(
yych
==
'r'
)
{
goto
basic_json_parser_47
;
}
goto
basic_json_parser_5
;
basic_json_parser_26
:
++
m_cursor
;
{
last_token_type
=
token_type
::
begin_object
;
break
;
}
{
last_token_type
=
token_type
::
begin_object
;
break
;
}
basic_json_parser_28
:
++
m_cursor
;
{
last_token_type
=
token_type
::
end_object
;
break
;
}
{
last_token_type
=
token_type
::
end_object
;
break
;
}
basic_json_parser_30
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
basic_json_parser_31
:
if
(
yybm
[
0
+
yych
]
&
128
)
{
if
(
yybm
[
0
+
yych
]
&
128
)
{
goto
basic_json_parser_30
;
}
if
(
yych
<=
0xE0
)
{
if
(
yych
<=
'\\'
)
{
if
(
yych
<=
0x1F
)
goto
basic_json_parser_32
;
if
(
yych
<=
'"'
)
goto
basic_json_parser_33
;
if
(
yych
<=
0xE0
)
{
if
(
yych
<=
'\\'
)
{
if
(
yych
<=
0x1F
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
'"'
)
{
goto
basic_json_parser_33
;
}
goto
basic_json_parser_35
;
}
else
{
if
(
yych
<=
0xC1
)
goto
basic_json_parser_32
;
if
(
yych
<=
0xDF
)
goto
basic_json_parser_36
;
}
else
{
if
(
yych
<=
0xC1
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
0xDF
)
{
goto
basic_json_parser_36
;
}
goto
basic_json_parser_37
;
}
}
else
{
if
(
yych
<=
0xEF
)
{
if
(
yych
==
0xED
)
goto
basic_json_parser_39
;
}
else
{
if
(
yych
<=
0xEF
)
{
if
(
yych
==
0xED
)
{
goto
basic_json_parser_39
;
}
goto
basic_json_parser_38
;
}
else
{
if
(
yych
<=
0xF0
)
goto
basic_json_parser_40
;
if
(
yych
<=
0xF3
)
goto
basic_json_parser_41
;
if
(
yych
<=
0xF4
)
goto
basic_json_parser_42
;
}
else
{
if
(
yych
<=
0xF0
)
{
goto
basic_json_parser_40
;
}
if
(
yych
<=
0xF3
)
{
goto
basic_json_parser_41
;
}
if
(
yych
<=
0xF4
)
{
goto
basic_json_parser_42
;
}
}
}
basic_json_parser_32
:
m_cursor
=
m_marker
;
if
(
yyaccept
==
0
)
{
if
(
yyaccept
==
0
)
{
goto
basic_json_parser_5
;
}
else
{
}
else
{
goto
basic_json_parser_14
;
}
basic_json_parser_33
:
++
m_cursor
;
{
last_token_type
=
token_type
::
value_string
;
break
;
}
{
last_token_type
=
token_type
::
value_string
;
break
;
}
basic_json_parser_35
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'e'
)
{
if
(
yych
<=
'/'
)
{
if
(
yych
==
'"'
)
goto
basic_json_parser_30
;
if
(
yych
<=
'.'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'e'
)
{
if
(
yych
<=
'/'
)
{
if
(
yych
==
'"'
)
{
goto
basic_json_parser_30
;
}
if
(
yych
<=
'.'
)
{
goto
basic_json_parser_32
;
}
goto
basic_json_parser_30
;
}
else
{
if
(
yych
<=
'\\'
)
{
if
(
yych
<=
'['
)
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'\\'
)
{
if
(
yych
<=
'['
)
{
goto
basic_json_parser_32
;
}
goto
basic_json_parser_30
;
}
else
{
if
(
yych
==
'b'
)
{
goto
basic_json_parser_30
;
}
else
{
if
(
yych
==
'b'
)
goto
basic_json_parser_30
;
}
goto
basic_json_parser_32
;
}
}
}
else
{
if
(
yych
<=
'q'
)
{
if
(
yych
<=
'f'
)
goto
basic_json_parser_30
;
if
(
yych
==
'n'
)
goto
basic_json_parser_30
;
}
else
{
if
(
yych
<=
'q'
)
{
if
(
yych
<=
'f'
)
{
goto
basic_json_parser_30
;
}
if
(
yych
==
'n'
)
{
goto
basic_json_parser_30
;
}
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
's'
)
{
if
(
yych
<=
'r'
)
goto
basic_json_parser_30
;
}
else
{
if
(
yych
<=
's'
)
{
if
(
yych
<=
'r'
)
{
goto
basic_json_parser_30
;
}
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
't'
)
goto
basic_json_parser_30
;
if
(
yych
<=
'u'
)
goto
basic_json_parser_48
;
}
else
{
if
(
yych
<=
't'
)
{
goto
basic_json_parser_30
;
}
if
(
yych
<=
'u'
)
{
goto
basic_json_parser_48
;
}
goto
basic_json_parser_32
;
}
}
}
basic_json_parser_36
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x7F
)
goto
basic_json_parser_32
;
if
(
yych
<=
0xBF
)
goto
basic_json_parser_30
;
if
(
yych
<=
0x7F
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
0xBF
)
{
goto
basic_json_parser_30
;
}
goto
basic_json_parser_32
;
basic_json_parser_37
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x9F
)
goto
basic_json_parser_32
;
if
(
yych
<=
0xBF
)
goto
basic_json_parser_36
;
if
(
yych
<=
0x9F
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
0xBF
)
{
goto
basic_json_parser_36
;
}
goto
basic_json_parser_32
;
basic_json_parser_38
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x7F
)
goto
basic_json_parser_32
;
if
(
yych
<=
0xBF
)
goto
basic_json_parser_36
;
if
(
yych
<=
0x7F
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
0xBF
)
{
goto
basic_json_parser_36
;
}
goto
basic_json_parser_32
;
basic_json_parser_39
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x7F
)
goto
basic_json_parser_32
;
if
(
yych
<=
0x9F
)
goto
basic_json_parser_36
;
if
(
yych
<=
0x7F
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
0x9F
)
{
goto
basic_json_parser_36
;
}
goto
basic_json_parser_32
;
basic_json_parser_40
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x8F
)
goto
basic_json_parser_32
;
if
(
yych
<=
0xBF
)
goto
basic_json_parser_38
;
if
(
yych
<=
0x8F
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
0xBF
)
{
goto
basic_json_parser_38
;
}
goto
basic_json_parser_32
;
basic_json_parser_41
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x7F
)
goto
basic_json_parser_32
;
if
(
yych
<=
0xBF
)
goto
basic_json_parser_38
;
if
(
yych
<=
0x7F
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
0xBF
)
{
goto
basic_json_parser_38
;
}
goto
basic_json_parser_32
;
basic_json_parser_42
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
0x7F
)
goto
basic_json_parser_32
;
if
(
yych
<=
0x8F
)
goto
basic_json_parser_38
;
if
(
yych
<=
0x7F
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
0x8F
)
{
goto
basic_json_parser_38
;
}
goto
basic_json_parser_32
;
basic_json_parser_43
:
yych
=
*++
m_cursor
;
if
(
yych
<=
'/'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_49
;
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_49
;
}
goto
basic_json_parser_32
;
basic_json_parser_44
:
yych
=
*++
m_cursor
;
if
(
yych
<=
','
)
{
if
(
yych
==
'+'
)
goto
basic_json_parser_51
;
if
(
yych
<=
','
)
{
if
(
yych
==
'+'
)
{
goto
basic_json_parser_51
;
}
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'-'
)
{
goto
basic_json_parser_51
;
}
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'-'
)
goto
basic_json_parser_51
;
if
(
yych
<=
'/'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_52
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_52
;
}
goto
basic_json_parser_32
;
}
basic_json_parser_45
:
yych
=
*++
m_cursor
;
if
(
yych
==
'l'
)
goto
basic_json_parser_54
;
if
(
yych
==
'l'
)
{
goto
basic_json_parser_54
;
}
goto
basic_json_parser_32
;
basic_json_parser_46
:
yych
=
*++
m_cursor
;
if
(
yych
==
'l'
)
goto
basic_json_parser_55
;
if
(
yych
==
'l'
)
{
goto
basic_json_parser_55
;
}
goto
basic_json_parser_32
;
basic_json_parser_47
:
yych
=
*++
m_cursor
;
if
(
yych
==
'u'
)
goto
basic_json_parser_56
;
if
(
yych
==
'u'
)
{
goto
basic_json_parser_56
;
}
goto
basic_json_parser_32
;
basic_json_parser_48
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_57
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'F'
)
goto
basic_json_parser_57
;
if
(
yych
<=
'`'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'f'
)
goto
basic_json_parser_57
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_57
;
}
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'F'
)
{
goto
basic_json_parser_57
;
}
if
(
yych
<=
'`'
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
'f'
)
{
goto
basic_json_parser_57
;
}
goto
basic_json_parser_32
;
}
basic_json_parser_49
:
yyaccept
=
1
;
m_marker
=
++
m_cursor
;
if
((
m_limit
-
m_cursor
)
<
3
)
fill_line_buffer
(
3
);
// LCOV_EXCL_LINE
if
((
m_limit
-
m_cursor
)
<
3
)
{
fill_line_buffer
(
3
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'D'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_14
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_49
;
if
(
yych
<=
'D'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_14
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_49
;
}
goto
basic_json_parser_14
;
}
else
{
if
(
yych
<=
'E'
)
goto
basic_json_parser_44
;
if
(
yych
==
'e'
)
goto
basic_json_parser_44
;
}
else
{
if
(
yych
<=
'E'
)
{
goto
basic_json_parser_44
;
}
if
(
yych
==
'e'
)
{
goto
basic_json_parser_44
;
}
goto
basic_json_parser_14
;
}
basic_json_parser_51
:
yych
=
*++
m_cursor
;
if
(
yych
<=
'/'
)
goto
basic_json_parser_32
;
if
(
yych
>=
':'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_32
;
}
if
(
yych
>=
':'
)
{
goto
basic_json_parser_32
;
}
basic_json_parser_52
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'/'
)
goto
basic_json_parser_14
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_52
;
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_14
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_52
;
}
goto
basic_json_parser_14
;
basic_json_parser_54
:
yych
=
*++
m_cursor
;
if
(
yych
==
's'
)
goto
basic_json_parser_58
;
if
(
yych
==
's'
)
{
goto
basic_json_parser_58
;
}
goto
basic_json_parser_32
;
basic_json_parser_55
:
yych
=
*++
m_cursor
;
if
(
yych
==
'l'
)
goto
basic_json_parser_59
;
if
(
yych
==
'l'
)
{
goto
basic_json_parser_59
;
}
goto
basic_json_parser_32
;
basic_json_parser_56
:
yych
=
*++
m_cursor
;
if
(
yych
==
'e'
)
goto
basic_json_parser_61
;
if
(
yych
==
'e'
)
{
goto
basic_json_parser_61
;
}
goto
basic_json_parser_32
;
basic_json_parser_57
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_63
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'F'
)
goto
basic_json_parser_63
;
if
(
yych
<=
'`'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'f'
)
goto
basic_json_parser_63
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_63
;
}
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'F'
)
{
goto
basic_json_parser_63
;
}
if
(
yych
<=
'`'
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
'f'
)
{
goto
basic_json_parser_63
;
}
goto
basic_json_parser_32
;
}
basic_json_parser_58
:
yych
=
*++
m_cursor
;
if
(
yych
==
'e'
)
goto
basic_json_parser_64
;
if
(
yych
==
'e'
)
{
goto
basic_json_parser_64
;
}
goto
basic_json_parser_32
;
basic_json_parser_59
:
++
m_cursor
;
{
last_token_type
=
token_type
::
literal_null
;
break
;
}
{
last_token_type
=
token_type
::
literal_null
;
break
;
}
basic_json_parser_61
:
++
m_cursor
;
{
last_token_type
=
token_type
::
literal_true
;
break
;
}
{
last_token_type
=
token_type
::
literal_true
;
break
;
}
basic_json_parser_63
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_66
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'F'
)
goto
basic_json_parser_66
;
if
(
yych
<=
'`'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'f'
)
goto
basic_json_parser_66
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_66
;
}
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'F'
)
{
goto
basic_json_parser_66
;
}
if
(
yych
<=
'`'
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
'f'
)
{
goto
basic_json_parser_66
;
}
goto
basic_json_parser_32
;
}
basic_json_parser_64
:
++
m_cursor
;
{
last_token_type
=
token_type
::
literal_false
;
break
;
}
{
last_token_type
=
token_type
::
literal_false
;
break
;
}
basic_json_parser_66
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
if
(
m_limit
<=
m_cursor
)
{
fill_line_buffer
(
1
);
// LCOV_EXCL_LINE
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_30
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_32
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_30
;
}
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'F'
)
{
goto
basic_json_parser_30
;
}
if
(
yych
<=
'`'
)
{
goto
basic_json_parser_32
;
}
else
{
if
(
yych
<=
'F'
)
goto
basic_json_parser_30
;
if
(
yych
<=
'`'
)
goto
basic_json_parser_32
;
if
(
yych
<=
'f'
)
goto
basic_json_parser_30
;
}
if
(
yych
<=
'f'
)
{
goto
basic_json_parser_30
;
}
goto
basic_json_parser_32
;
}
}
...
...
@@ -11210,14 +11727,14 @@ basic_json_parser_66:
}
private
:
friend
bool
operator
==
(
json_pointer
const
&
lhs
,
json_pointer
const
&
rhs
)
noexcept
friend
bool
operator
==
(
json_pointer
const
&
lhs
,
json_pointer
const
&
rhs
)
noexcept
{
return
lhs
.
reference_tokens
==
rhs
.
reference_tokens
;
}
friend
bool
operator
!=
(
json_pointer
const
&
lhs
,
json_pointer
const
&
rhs
)
noexcept
friend
bool
operator
!=
(
json_pointer
const
&
lhs
,
json_pointer
const
&
rhs
)
noexcept
{
return
!
(
lhs
==
rhs
);
}
...
...
@@ -11908,7 +12425,8 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept
2
,
// integer
2
,
// unsigned
2
,
// float
}};
}
};
// discarded values are not comparable
if
(
lhs
==
value_t
::
discarded
or
rhs
==
value_t
::
discarded
)
...
...
@@ -11943,25 +12461,25 @@ using json = basic_json<>;
// specialization of std::swap, and std::hash
namespace
std
{
/*!
@brief exchanges the values of two JSON objects
/*!
@brief exchanges the values of two JSON objects
@since version 1.0.0
*/
template
<>
inline
void
swap
(
nlohmann
::
json
&
j1
,
@since version 1.0.0
*/
template
<>
inline
void
swap
(
nlohmann
::
json
&
j1
,
nlohmann
::
json
&
j2
)
noexcept
(
is_nothrow_move_constructible
<
nlohmann
::
json
>::
value
and
is_nothrow_move_assignable
<
nlohmann
::
json
>::
value
)
{
{
j1
.
swap
(
j2
);
}
}
/// hash value for JSON objects
template
<>
struct
hash
<
nlohmann
::
json
>
{
/// hash value for JSON objects
template
<>
struct
hash
<
nlohmann
::
json
>
{
/*!
@brief return a hash value for a JSON object
...
...
@@ -11973,7 +12491,7 @@ namespace std
const
auto
&
h
=
hash
<
nlohmann
::
json
::
string_t
>
();
return
h
(
j
.
dump
());
}
};
};
}
// namespace std
/*!
...
...
src/json.hpp.re2c
View file @
3e15b551
...
...
@@ -168,7 +168,7 @@ using is_unscoped_enum =
namespace detail
{
template <typename Json> std::string type_name(const Json
&
j)
template <typename Json> std::string type_name(const Json
&
j)
{
switch (j.m_type)
{
...
...
@@ -190,7 +190,7 @@ template <typename Json> std::string type_name(const Json &j)
}
// dispatch utility (taken from ranges-v3)
template <unsigned N> struct priority_tag : priority_tag
<N - 1
> {};
template <unsigned N> struct priority_tag : priority_tag
< N - 1
> {};
template <> struct priority_tag<0> {};
...
...
@@ -202,7 +202,7 @@ template <>
struct external_constructor<value_t::boolean>
{
template <typename Json>
static void construct(Json &
j, typename Json::boolean_t b) noexcept
static void construct(Json&
j, typename Json::boolean_t b) noexcept
{
j.m_type = value_t::boolean;
j.m_value = b;
...
...
@@ -214,7 +214,7 @@ template <>
struct external_constructor<value_t::string>
{
template <typename Json>
static void construct(Json &
j, const typename Json::string_t& s)
static void construct(Json&
j, const typename Json::string_t& s)
{
j.m_type = value_t::string;
j.m_value = s;
...
...
@@ -226,7 +226,7 @@ template <>
struct external_constructor<value_t::number_float>
{
template <typename Json>
static void construct(Json &
j, typename Json::number_float_t val) noexcept
static void construct(Json&
j, typename Json::number_float_t val) noexcept
{
// replace infinity and NAN by null
if (not std::isfinite(val))
...
...
@@ -244,7 +244,7 @@ template <>
struct external_constructor<value_t::number_unsigned>
{
template <typename Json>
static void construct(Json &
j, typename Json::number_unsigned_t val) noexcept
static void construct(Json&
j, typename Json::number_unsigned_t val) noexcept
{
j.m_type = value_t::number_unsigned;
j.m_value = val;
...
...
@@ -256,7 +256,7 @@ template <>
struct external_constructor<value_t::number_integer>
{
template <typename Json>
static void construct(Json &
j, typename Json::number_integer_t val) noexcept
static void construct(Json&
j, typename Json::number_integer_t val) noexcept
{
j.m_type = value_t::number_integer;
j.m_value = val;
...
...
@@ -268,7 +268,7 @@ template <>
struct external_constructor<value_t::array>
{
template <typename Json>
static void construct(Json &
j, const typename Json::array_t& arr)
static void construct(Json&
j, const typename Json::array_t& arr)
{
j.m_type = value_t::array;
j.m_value = arr;
...
...
@@ -279,7 +279,7 @@ struct external_constructor<value_t::array>
enable_if_t<not std::is_same<CompatibleArrayType,
typename Json::array_t>::value,
int> = 0>
static void construct(Json &j, const CompatibleArrayType &
arr)
static void construct(Json& j, const CompatibleArrayType&
arr)
{
using std::begin;
using std::end;
...
...
@@ -294,7 +294,7 @@ template <>
struct external_constructor<value_t::object>
{
template <typename Json>
static void construct(Json &
j, const typename Json::object_t& obj)
static void construct(Json&
j, const typename Json::object_t& obj)
{
j.m_type = value_t::object;
j.m_value = obj;
...
...
@@ -305,7 +305,7 @@ struct external_constructor<value_t::object>
enable_if_t<not std::is_same<CompatibleObjectType,
typename Json::object_t>::value,
int> = 0>
static void construct(Json &j, const CompatibleObjectType &
obj)
static void construct(Json& j, const CompatibleObjectType&
obj)
{
using std::begin;
using std::end;
...
...
@@ -380,11 +380,11 @@ struct is_compatible_object_type_impl<true, RealType, CompatibleObjectType>
template<class BasicJson, class CompatibleObjectType>
struct is_compatible_object_type
{
static auto constexpr value = is_compatible_object_type_impl<
static auto constexpr value = is_compatible_object_type_impl
<
conjunction<negation<std::is_same<void, CompatibleObjectType>>,
has_mapped_type<CompatibleObjectType>,
has_key_type<CompatibleObjectType>>::value,
typename BasicJson::object_t, CompatibleObjectType
>::value;
typename BasicJson::object_t, CompatibleObjectType
>::value;
};
template <typename BasicJson, typename T>
...
...
@@ -461,15 +461,15 @@ struct has_from_json
template <typename Json, typename T>
struct has_non_default_from_json
{
private:
private:
template <
typename U,
typename = enable_if_t<std::is_same<
T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value
>>
static int detect(U
&&);
T, decltype(uncvref_t<U>::from_json(std::declval<Json>()))>::value
>>
static int detect(U
&&);
static void detect(...);
public:
public:
static constexpr bool value = std::is_integral<decltype(detect(
std::declval<typename Json::template json_serializer<T, void>>()))>::value;
};
...
...
@@ -478,13 +478,13 @@ public:
template <typename Json, typename T>
struct has_to_json
{
private:
private:
template <typename U, typename = decltype(uncvref_t<U>::to_json(
std::declval<Json
&>(), std::declval<T>()))>
static int detect(U
&&);
std::declval<Json
&>(), std::declval<T>()))>
static int detect(U
&&);
static void detect(...);
public:
public:
static constexpr bool value = std::is_integral<decltype(detect(
std::declval<typename Json::template json_serializer<T, void>>()))>::value;
};
...
...
@@ -496,21 +496,29 @@ template <typename Json, typename ArithmeticType,
not std::is_same<ArithmeticType,
typename Json::boolean_t>::value,
int> = 0>
void get_arithmetic_value(const Json
&j, ArithmeticType &
val)
void get_arithmetic_value(const Json
& j, ArithmeticType&
val)
{
// unsigned must be checked first, since is_number_integer() == true for unsigned
if (j.is_number_unsigned())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>());
}
else if (j.is_number_integer())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>());
}
else if (j.is_number_float())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>());
}
else
{
throw std::domain_error("type must be number, but is " + type_name(j));
}
}
template <typename Json>
void to_json(Json
&
j, typename Json::boolean_t b) noexcept
void to_json(Json
&
j, typename Json::boolean_t b) noexcept
{
external_constructor<value_t::boolean>::construct(j, b);
}
...
...
@@ -519,14 +527,14 @@ template <typename Json, typename CompatibleString,
enable_if_t<std::is_constructible<typename Json::string_t,
CompatibleString>::value,
int> = 0>
void to_json(Json
&j, const CompatibleString &
s)
void to_json(Json
& j, const CompatibleString&
s)
{
external_constructor<value_t::string>::construct(j, s);
}
template <typename Json, typename FloatType,
enable_if_t<std::is_floating_point<FloatType>::value, int> = 0>
void to_json(Json
&
j, FloatType val) noexcept
void to_json(Json
&
j, FloatType val) noexcept
{
external_constructor<value_t::number_float>::construct(j, static_cast<typename Json::number_float_t>(val));
}
...
...
@@ -536,8 +544,8 @@ template <
typename Json, typename CompatibleNumberUnsignedType,
enable_if_t<is_compatible_integer_type<typename Json::number_unsigned_t,
CompatibleNumberUnsignedType>::value,
int> = 0>
void to_json(Json
&
j, CompatibleNumberUnsignedType val) noexcept
int> = 0
>
void to_json(Json
&
j, CompatibleNumberUnsignedType val) noexcept
{
external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename Json::number_unsigned_t>(val));
}
...
...
@@ -546,26 +554,26 @@ template <
typename Json, typename CompatibleNumberIntegerType,
enable_if_t<is_compatible_integer_type<typename Json::number_integer_t,
CompatibleNumberIntegerType>::value,
int> = 0>
void to_json(Json
&
j, CompatibleNumberIntegerType val) noexcept
int> = 0
>
void to_json(Json
&
j, CompatibleNumberIntegerType val) noexcept
{
external_constructor<value_t::number_integer>::construct(j, static_cast<typename Json::number_integer_t>(val));
}
template <typename Json, typename UnscopedEnumType,
enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0>
void to_json(Json
&
j, UnscopedEnumType e) noexcept
void to_json(Json
&
j, UnscopedEnumType e) noexcept
{
external_constructor<value_t::number_integer>::construct(j, e);
}
template <
typename Json, typename CompatibleArrayType,
enable_if_t<
enable_if_t
<
is_compatible_array_type<Json, CompatibleArrayType>::value or
std::is_same<typename Json::array_t, CompatibleArrayType>::value,
int
> = 0
>
void to_json(Json
&j, const CompatibleArrayType &
arr)
int
> = 0
>
void to_json(Json
& j, const CompatibleArrayType&
arr)
{
external_constructor<value_t::array>::construct(j, arr);
}
...
...
@@ -573,49 +581,53 @@ void to_json(Json &j, const CompatibleArrayType &arr)
template <
typename Json, typename CompatibleObjectType,
enable_if_t<is_compatible_object_type<Json, CompatibleObjectType>::value,
int> = 0>
void to_json(Json
&j, const CompatibleObjectType &
arr)
int> = 0
>
void to_json(Json
& j, const CompatibleObjectType&
arr)
{
external_constructor<value_t::object>::construct(j, arr);
}
template <typename Json>
void from_json(const Json
& j, typename Json::boolean_t& b)
void from_json(const Json& j, typename Json::boolean_t& b)
{
if (!j.is_boolean())
{
throw std::domain_error("type must be boolean, but is " + type_name(j));
}
b = *j.template get_ptr<const typename Json::boolean_t*>();
}
template <typename Json>
void from_json(const Json
& j, typename Json::string_t& s)
void from_json(const Json& j, typename Json::string_t& s)
{
if (!j.is_string())
{
throw std::domain_error("type must be string, but is " + type_name(j));
}
s = *j.template get_ptr<const typename Json::string_t*>();
}
template <typename Json>
void from_json(const Json
& j, typename Json::number_float_t& val)
void from_json(const Json& j, typename Json::number_float_t& val)
{
get_arithmetic_value(j, val);
}
template <typename Json>
void from_json(const Json
& j, typename Json::number_unsigned_t& val)
void from_json(const Json& j, typename Json::number_unsigned_t& val)
{
get_arithmetic_value(j, val);
}
template <typename Json>
void from_json(const Json
& j, typename Json::number_integer_t& val)
void from_json(const Json& j, typename Json::number_integer_t& val)
{
get_arithmetic_value(j, val);
}
template <typename Json, typename UnscopedEnumType,
enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0>
void from_json(const Json
&
j, UnscopedEnumType& e)
void from_json(const Json
&
j, UnscopedEnumType& e)
{
typename std::underlying_type<UnscopedEnumType>::type val = e;
get_arithmetic_value(j, val);
...
...
@@ -623,38 +635,46 @@ void from_json(const Json &j, UnscopedEnumType& e)
}
template <typename Json>
void from_json(const Json
&j, typename Json::array_t &
arr)
void from_json(const Json
& j, typename Json::array_t&
arr)
{
if (!j.is_array())
{
throw std::domain_error("type must be array, but is " + type_name(j));
}
arr = *j.template get_ptr<const typename Json::array_t*>();
}
// forward_list doesn't have an insert method, TODO find a way to avoid including forward_list
template <typename Json, typename T, typename Allocator>
void from_json(const Json
&
j, std::forward_list<T, Allocator>& l)
void from_json(const Json
&
j, std::forward_list<T, Allocator>& l)
{
// do not perform the check when user wants to retrieve jsons
// (except when it's null.. ?)
if (j.is_null())
{
throw std::domain_error("type must be array, but is " + type_name(j));
}
if (not std::is_same<T, Json>::value)
{
if (!j.is_array())
{
throw std::domain_error("type must be array, but is " + type_name(j));
}
}
for (auto it = j.rbegin(), end = j.rend(); it != end; ++it)
{
l.push_front(it->template get<T>());
}
}
template <typename Json, typename CompatibleArrayType>
void from_json_array_impl(const Json
&j, CompatibleArrayType &
arr, priority_tag<0>)
void from_json_array_impl(const Json
& j, CompatibleArrayType&
arr, priority_tag<0>)
{
using std::begin;
using std::end;
std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json &
i)
j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json &
i)
{
// get<Json>() returns *this, this won't call a from_json method when
// value_type is Json
...
...
@@ -663,8 +683,8 @@ void from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag
}
template <typename Json, typename CompatibleArrayType>
auto from_json_array_impl(const Json
&j, CompatibleArrayType &
arr, priority_tag<1>)
-> decltype(
auto from_json_array_impl(const Json
& j, CompatibleArrayType&
arr, priority_tag<1>)
-> decltype(
arr.reserve(std::declval<typename CompatibleArrayType::size_type>()),
void())
{
...
...
@@ -673,7 +693,7 @@ auto from_json_array_impl(const Json &j, CompatibleArrayType &arr, priority_tag
arr.reserve(j.size());
std::transform(
j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json &
i)
j.begin(), j.end(), std::inserter(arr, end(arr)), [](const Json &
i)
{
// get<Json>() returns *this, this won't call a from_json method when
// value_type is Json
...
...
@@ -686,29 +706,35 @@ template <
enable_if_t<is_compatible_array_type<Json, CompatibleArrayType>::value and
not std::is_same<typename Json::array_t,
CompatibleArrayType>::value,
int> = 0>
void from_json(const Json
&j, CompatibleArrayType &
arr)
int> = 0
>
void from_json(const Json
& j, CompatibleArrayType&
arr)
{
if (j.is_null())
{
throw std::domain_error("type must be array, but is " + type_name(j));
}
// when T == Json, do not check if value_t is correct
if (not std::is_same<typename CompatibleArrayType::value_type, Json>::value)
{
if (!j.is_array())
{
throw std::domain_error("type must be array, but is " + type_name(j));
}
from_json_array_impl(j, arr, priority_tag<1>{});
}
from_json_array_impl(j, arr, priority_tag<1> {});
}
template <
typename Json, typename CompatibleObjectType,
enable_if_t<is_compatible_object_type<Json, CompatibleObjectType>::value,
int> = 0>
void from_json(const Json
&j, CompatibleObjectType &
obj)
int> = 0
>
void from_json(const Json
& j, CompatibleObjectType&
obj)
{
if (!j.is_object())
{
throw std::domain_error("type must be object, but is " + type_name(j));
}
auto inner_object = j.template get_ptr<const typename Json::object_t*>();
using std::begin;
...
...
@@ -724,25 +750,35 @@ void from_json(const Json &j, CompatibleObjectType &obj)
// in case of a custom BooleanType which is not an arithmetic type?
template <
typename Json, typename ArithmeticType,
enable_if_t<
enable_if_t
<
std::is_arithmetic<ArithmeticType>::value and
not std::is_same<ArithmeticType, typename Json::number_unsigned_t>::value and
not std::is_same<ArithmeticType, typename Json::number_integer_t>::value and
not std::is_same<ArithmeticType, typename Json::number_float_t>::value and
not std::is_same<ArithmeticType, typename Json::boolean_t>::value,
int
> = 0
>
void from_json(const Json
&j, ArithmeticType &
val)
int
> = 0
>
void from_json(const Json
& j, ArithmeticType&
val)
{
if (j.is_number_unsigned())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>());
}
else if (j.is_number_integer())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>());
}
else if (j.is_number_float())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>());
}
else if (j.is_boolean())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::boolean_t*>());
}
else
{
throw std::domain_error("type must be number, but is " + type_name(j));
}
}
struct to_json_fn
...
...
@@ -762,20 +798,20 @@ struct to_json_fn
static_assert(sizeof(Json) == 0, "to_json method in T's namespace can not be called");
}
public:
public:
template <typename Json, typename T>
void operator()(Json &j, T &&
val) const
noexcept(noexcept(std::declval<to_json_fn>().call(j, std::forward<T>(val), priority_tag<1>
{})))
void operator()(Json& j, T&&
val) const
noexcept(noexcept(std::declval<to_json_fn>().call(j, std::forward<T>(val), priority_tag<1>
{})))
{
return call(j, std::forward<T>(val), priority_tag<1>
{});
return call(j, std::forward<T>(val), priority_tag<1>
{});
}
};
struct from_json_fn
{
private:
private:
template <typename Json, typename T>
auto call(const Json &j, T &
val, priority_tag<1>) const
auto call(const Json& j, T&
val, priority_tag<1>) const
noexcept(noexcept(from_json(j, val)))
-> decltype(from_json(j, val), void())
{
...
...
@@ -783,17 +819,17 @@ private:
}
template <typename Json, typename T>
void call(const Json
&, T&, priority_tag<0>) const noexcept
void call(const Json
&, T&, priority_tag<0>) const noexcept
{
static_assert(sizeof(Json) == 0, "from_json method in T's namespace can not be called");
}
public:
public:
template <typename Json, typename T>
void operator()(const Json &j, T &
val) const
noexcept(noexcept(std::declval<from_json_fn>().call(j, val, priority_tag<1>
{})))
void operator()(const Json& j, T&
val) const
noexcept(noexcept(std::declval<from_json_fn>().call(j, val, priority_tag<1>
{})))
{
return call(j, val, priority_tag<1>
{});
return call(j, val, priority_tag<1>
{});
}
};
...
...
@@ -830,8 +866,8 @@ struct DecimalSeparator : std::numpunct<char>
inline namespace
{
constexpr const auto
& to_json = detail::static_const<detail::to_json_fn>::value;
constexpr const auto
& from_json = detail::static_const<detail::from_json_fn>::value;
constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value;
}
// default JSONSerializer template argument, doesn't care about template argument
...
...
@@ -846,7 +882,7 @@ struct adl_serializer
}
template <typename Json, typename T>
static void to_json(Json
&j, T &&
val) noexcept(
static void to_json(Json
& j, T&&
val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<T>(val))))
{
::nlohmann::to_json(j, std::forward<T>(val));
...
...
@@ -947,7 +983,7 @@ class basic_json
{
private:
template <::nlohmann::value_t> friend struct detail::external_constructor;
template <typename Json> friend std::string detail::type_name(const Json
&);
template <typename Json> friend std::string detail::type_name(const Json&);
/// workaround type for MSVC
using basic_json_t = basic_json<ObjectType, ArrayType, StringType,
BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType,
...
...
@@ -1854,8 +1890,8 @@ class basic_json
basic_json_t, U>::value and
detail::has_to_json<basic_json, U>::value,
int> = 0>
basic_json(T &&val) noexcept(noexcept(JSONSerializer<U>::to_json(
std::declval<basic_json_t
&>(), std::forward<T>(val))))
basic_json(T &&
val) noexcept(noexcept(JSONSerializer<U>::to_json(
std::declval<basic_json_t
&>(), std::forward<T>(val))))
{
JSONSerializer<U>::to_json(*this, std::forward<T>(val));
}
...
...
@@ -3041,17 +3077,17 @@ class basic_json
template <
typename T,
typename U = uncvref_t<T>,
enable_if_t<
enable_if_t
<
not std::is_same<basic_json_t, U>::value and
detail::has_from_json<basic_json_t, U>::value and
not detail::has_non_default_from_json<basic_json_t,
U>::value,
int
> = 0
>
int
> = 0
>
// do we really want the uncvref ? if a user call get<int &>, shouldn't we
// static assert ?
// i know there is a special behaviour for boolean_t* and such
auto get() const noexcept(noexcept(JSONSerializer<U>::from_json(
std::declval<const basic_json_t &>(), std::declval<U
&>())))
std::declval<const basic_json_t&>(), std::declval<U
&>())))
-> U
{
static_assert(std::is_default_constructible<U>::value and
...
...
@@ -3083,8 +3119,8 @@ class basic_json
enable_if_t<not std::is_same<basic_json_t, uncvref_t<T>>::value and
detail::has_non_default_from_json<basic_json_t,
uncvref_t<T>>::value,
int> = 0>
uncvref_t<T> get() const noexcept(noexcept(JSONSerializer<T>::from_json(std::declval<const basic_json_t
&>())))
int> = 0
>
uncvref_t<T> get() const noexcept(noexcept(JSONSerializer<T>::from_json(std::declval<const basic_json_t&>())))
{
return JSONSerializer<T>::from_json(*this);
}
...
...
@@ -7871,7 +7907,10 @@ class basic_json
@since version 1.0.0
*/
std::string type_name() const { return detail::type_name(*this); }
std::string type_name() const
{
return detail::type_name(*this);
}
private:
/*!
...
...
@@ -10838,14 +10877,14 @@ class basic_json
}
private:
friend bool operator==(json_pointer const &
lhs,
json_pointer const &
rhs) noexcept
friend bool operator==(json_pointer const&
lhs,
json_pointer const&
rhs) noexcept
{
return lhs.reference_tokens == rhs.reference_tokens;
}
friend bool operator!=(json_pointer const &
lhs,
json_pointer const &
rhs) noexcept
friend bool operator!=(json_pointer const&
lhs,
json_pointer const&
rhs) noexcept
{
return !(lhs == rhs);
}
...
...
@@ -11536,7 +11575,8 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept
2, // integer
2, // unsigned
2, // float
}};
}
};
// discarded values are not comparable
if (lhs == value_t::discarded or rhs == value_t::discarded)
...
...
@@ -11571,25 +11611,25 @@ using json = basic_json<>;
// specialization of std::swap, and std::hash
namespace std
{
/*!
@brief exchanges the values of two JSON objects
/*!
@brief exchanges the values of two JSON objects
@since version 1.0.0
*/
template<>
inline void swap(nlohmann::json& j1,
@since version 1.0.0
*/
template<>
inline void swap(nlohmann::json& j1,
nlohmann::json& j2) noexcept(
is_nothrow_move_constructible<nlohmann::json>::value and
is_nothrow_move_assignable<nlohmann::json>::value
)
{
{
j1.swap(j2);
}
}
/// hash value for JSON objects
template<>
struct hash<nlohmann::json>
{
/// hash value for JSON objects
template<>
struct hash<nlohmann::json>
{
/*!
@brief return a hash value for a JSON object
...
...
@@ -11601,7 +11641,7 @@ namespace std
const auto& h = hash<nlohmann::json::string_t>();
return h(j.dump());
}
};
};
} // namespace std
/*!
...
...
test/src/unit-conversions.cpp
View file @
3e15b551
test/src/unit-noexcept.cpp
View file @
3e15b551
...
...
@@ -11,8 +11,8 @@ enum test
struct
pod
{};
struct
pod_bis
{};
void
to_json
(
json
&
,
pod
)
noexcept
;
void
to_json
(
json
&
,
pod_bis
);
void
to_json
(
json
&
,
pod
)
noexcept
;
void
to_json
(
json
&
,
pod_bis
);
void
from_json
(
const
json
&
,
pod
)
noexcept
;
void
from_json
(
const
json
&
,
pod_bis
);
static
json
j
;
...
...
test/src/unit-regression.cpp
View file @
3e15b551
...
...
@@ -63,7 +63,7 @@ TEST_CASE("regression tests")
SECTION
(
"pull request #71 - handle enum type"
)
{
enum
{
t
=
0
,
u
=
1
};
enum
{
t
=
0
,
u
=
1
};
json
j
=
json
::
array
();
j
.
push_back
(
t
);
...
...
test/src/unit-udt.cpp
View file @
3e15b551
...
...
@@ -114,22 +114,22 @@ void to_json(Json& j, country c)
}
template
<
typename
Json
>
void
to_json
(
Json
&
j
,
const
person
&
p
)
void
to_json
(
Json
&
j
,
const
person
&
p
)
{
j
=
Json
{{
"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
)
{
j
=
a
.
m_val
;
}
void
to_json
(
nlohmann
::
json
&
j
,
const
contact
&
c
)
void
to_json
(
nlohmann
::
json
&
j
,
const
contact
&
c
)
{
j
=
json
{{
"person"
,
c
.
m_person
},
{
"address"
,
c
.
m_address
}};
}
void
to_json
(
nlohmann
::
json
&
j
,
const
contact_book
&
cb
)
void
to_json
(
nlohmann
::
json
&
j
,
const
contact_book
&
cb
)
{
j
=
json
{{
"name"
,
cb
.
m_book_name
},
{
"contacts"
,
cb
.
m_contacts
}};
}
...
...
@@ -140,28 +140,28 @@ bool operator==(age lhs, age rhs)
return
lhs
.
m_val
==
rhs
.
m_val
;
}
bool
operator
==
(
const
address
&
lhs
,
const
address
&
rhs
)
bool
operator
==
(
const
address
&
lhs
,
const
address
&
rhs
)
{
return
lhs
.
m_val
==
rhs
.
m_val
;
}
bool
operator
==
(
const
name
&
lhs
,
const
name
&
rhs
)
bool
operator
==
(
const
name
&
lhs
,
const
name
&
rhs
)
{
return
lhs
.
m_val
==
rhs
.
m_val
;
}
bool
operator
==
(
const
person
&
lhs
,
const
person
&
rhs
)
bool
operator
==
(
const
person
&
lhs
,
const
person
&
rhs
)
{
return
std
::
tie
(
lhs
.
m_name
,
lhs
.
m_age
)
==
std
::
tie
(
rhs
.
m_name
,
rhs
.
m_age
);
}
bool
operator
==
(
const
contact
&
lhs
,
const
contact
&
rhs
)
bool
operator
==
(
const
contact
&
lhs
,
const
contact
&
rhs
)
{
return
std
::
tie
(
lhs
.
m_person
,
lhs
.
m_address
)
==
std
::
tie
(
rhs
.
m_person
,
rhs
.
m_address
);
}
bool
operator
==
(
const
contact_book
&
lhs
,
const
contact_book
&
rhs
)
bool
operator
==
(
const
contact_book
&
lhs
,
const
contact_book
&
rhs
)
{
return
std
::
tie
(
lhs
.
m_book_name
,
lhs
.
m_contacts
)
==
std
::
tie
(
rhs
.
m_book_name
,
rhs
.
m_contacts
);
...
...
@@ -172,19 +172,19 @@ bool operator==(const contact_book & lhs, const contact_book & rhs)
namespace
udt
{
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
age
&
a
)
void
from_json
(
const
Json
&
j
,
age
&
a
)
{
a
.
m_val
=
j
.
template
get
<
int
>
();
}
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
name
&
n
)
void
from_json
(
const
Json
&
j
,
name
&
n
)
{
n
.
m_val
=
j
.
template
get
<
std
::
string
>
();
}
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
country
&
c
)
void
from_json
(
const
Json
&
j
,
country
&
c
)
{
const
auto
str
=
j
.
template
get
<
std
::
string
>
();
static
const
std
::
map
<
std
::
string
,
country
>
m
=
...
...
@@ -200,25 +200,25 @@ void from_json(const Json & j, country& c)
}
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
person
&
p
)
void
from_json
(
const
Json
&
j
,
person
&
p
)
{
p
.
m_age
=
j
[
"age"
].
template
get
<
age
>
();
p
.
m_name
=
j
[
"name"
].
template
get
<
name
>
();
p
.
m_country
=
j
[
"country"
].
template
get
<
country
>
();
}
void
from_json
(
const
nlohmann
::
json
&
j
,
address
&
a
)
void
from_json
(
const
nlohmann
::
json
&
j
,
address
&
a
)
{
a
.
m_val
=
j
.
get
<
std
::
string
>
();
}
void
from_json
(
const
nlohmann
::
json
&
j
,
contact
&
c
)
void
from_json
(
const
nlohmann
::
json
&
j
,
contact
&
c
)
{
c
.
m_person
=
j
[
"person"
].
get
<
person
>
();
c
.
m_address
=
j
[
"address"
].
get
<
address
>
();
}
void
from_json
(
const
nlohmann
::
json
&
j
,
contact_book
&
cb
)
void
from_json
(
const
nlohmann
::
json
&
j
,
contact_book
&
cb
)
{
cb
.
m_book_name
=
j
[
"name"
].
get
<
name
>
();
cb
.
m_contacts
=
j
[
"contacts"
].
get
<
std
::
vector
<
contact
>>
();
...
...
@@ -297,7 +297,7 @@ namespace nlohmann
template
<
typename
T
>
struct
adl_serializer
<
std
::
shared_ptr
<
T
>>
{
static
void
to_json
(
json
&
j
,
const
std
::
shared_ptr
<
T
>
&
opt
)
static
void
to_json
(
json
&
j
,
const
std
::
shared_ptr
<
T
>&
opt
)
{
if
(
opt
)
{
...
...
@@ -309,7 +309,7 @@ struct adl_serializer<std::shared_ptr<T>>
}
}
static
void
from_json
(
const
json
&
j
,
std
::
shared_ptr
<
T
>&
opt
)
static
void
from_json
(
const
json
&
j
,
std
::
shared_ptr
<
T
>&
opt
)
{
if
(
j
.
is_null
())
{
...
...
@@ -325,12 +325,12 @@ struct adl_serializer<std::shared_ptr<T>>
template
<>
struct
adl_serializer
<
udt
::
legacy_type
>
{
static
void
to_json
(
json
&
j
,
const
udt
::
legacy_type
&
l
)
static
void
to_json
(
json
&
j
,
const
udt
::
legacy_type
&
l
)
{
j
=
std
::
stoi
(
l
.
number
);
}
static
void
from_json
(
const
json
&
j
,
udt
::
legacy_type
&
l
)
static
void
from_json
(
const
json
&
j
,
udt
::
legacy_type
&
l
)
{
l
.
number
=
std
::
to_string
(
j
.
get
<
int
>
());
}
...
...
@@ -395,18 +395,18 @@ template <>
struct
adl_serializer
<
std
::
vector
<
float
>>
{
using
type
=
std
::
vector
<
float
>
;
static
void
to_json
(
json
&
j
,
const
type
&
)
static
void
to_json
(
json
&
j
,
const
type
&
)
{
j
=
"hijacked!"
;
}
static
void
from_json
(
const
json
&
,
type
&
opt
)
static
void
from_json
(
const
json
&
,
type
&
opt
)
{
opt
=
{
42.0
,
42.0
,
42.0
};
}
// preferred version
static
type
from_json
(
const
json
&
)
static
type
from_json
(
const
json
&
)
{
return
{
4.0
,
5.0
,
6.0
};
}
...
...
@@ -419,7 +419,7 @@ TEST_CASE("even supported types can be specialized", "[udt]")
CHECK
(
j
.
dump
()
==
R"("hijacked!")"
);
auto
f
=
j
.
get
<
std
::
vector
<
float
>>
();
// the single argument from_json method is preferred
CHECK
((
f
==
std
::
vector
<
float
>
{
4.0
,
5.0
,
6.0
}));
CHECK
((
f
==
std
::
vector
<
float
>
{
4.0
,
5.0
,
6.0
}));
}
namespace
nlohmann
...
...
@@ -427,7 +427,7 @@ namespace nlohmann
template
<
typename
T
>
struct
adl_serializer
<
std
::
unique_ptr
<
T
>>
{
static
void
to_json
(
json
&
j
,
const
std
::
unique_ptr
<
T
>
&
opt
)
static
void
to_json
(
json
&
j
,
const
std
::
unique_ptr
<
T
>&
opt
)
{
if
(
opt
)
{
...
...
@@ -440,7 +440,7 @@ struct adl_serializer<std::unique_ptr<T>>
}
// this is the overload needed for non-copyable types,
static
std
::
unique_ptr
<
T
>
from_json
(
const
json
&
j
)
static
std
::
unique_ptr
<
T
>
from_json
(
const
json
&
j
)
{
if
(
j
.
is_null
())
{
...
...
@@ -494,9 +494,9 @@ struct pod_serializer
// use adl for non-pods, or scalar types
template
<
typename
Json
,
typename
U
=
T
,
typename
std
::
enable_if
<
not
(
std
::
is_pod
<
U
>::
value
and
std
::
is_class
<
U
>::
value
),
int
>::
type
=
0
>
static
void
from_json
(
const
Json
&
j
,
U
&
t
)
typename
std
::
enable_if
<
not
(
std
::
is_pod
<
U
>::
value
and
std
::
is_class
<
U
>::
value
),
int
>::
type
=
0
>
static
void
from_json
(
const
Json
&
j
,
U
&
t
)
{
using
nlohmann
::
from_json
;
from_json
(
j
,
t
);
...
...
@@ -506,7 +506,7 @@ struct pod_serializer
template
<
typename
Json
,
typename
U
=
T
,
typename
std
::
enable_if
<
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
Json
&
j
,
U
&
t
)
{
std
::
uint64_t
value
;
// TODO The following block is no longer relevant in this serializer, make another one that shows the issue
...
...
@@ -524,15 +524,15 @@ struct pod_serializer
// calling get calls from_json, for now, we cannot do this in custom
// serializers
nlohmann
::
from_json
(
j
,
value
);
auto
bytes
=
static_cast
<
char
*>
(
static_cast
<
void
*>
(
&
value
));
auto
bytes
=
static_cast
<
char
*>
(
static_cast
<
void
*>
(
&
value
));
std
::
memcpy
(
&
t
,
bytes
,
sizeof
(
value
));
}
template
<
typename
Json
,
typename
U
=
T
,
typename
std
::
enable_if
<
not
(
std
::
is_pod
<
U
>::
value
and
std
::
is_class
<
U
>::
value
),
int
>::
type
=
0
>
static
void
to_json
(
Json
&
j
,
const
T
&
t
)
typename
std
::
enable_if
<
not
(
std
::
is_pod
<
U
>::
value
and
std
::
is_class
<
U
>::
value
),
int
>::
type
=
0
>
static
void
to_json
(
Json
&
j
,
const
T
&
t
)
{
using
nlohmann
::
to_json
;
to_json
(
j
,
t
);
...
...
@@ -541,9 +541,9 @@ struct pod_serializer
template
<
typename
Json
,
typename
U
=
T
,
typename
std
::
enable_if
<
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
(
Json
&
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
];
for
(
auto
i
=
1
;
i
<
8
;
++
i
)
value
|=
std
::
uint64_t
{
bytes
[
i
]}
<<
8
*
i
;
...
...
@@ -566,13 +566,13 @@ struct non_pod
};
template
<
typename
Json
>
void
to_json
(
Json
&
j
,
const
non_pod
&
np
)
void
to_json
(
Json
&
j
,
const
non_pod
&
np
)
{
j
=
np
.
s
;
}
template
<
typename
Json
>
void
from_json
(
const
Json
&
j
,
non_pod
&
np
)
void
from_json
(
const
Json
&
j
,
non_pod
&
np
)
{
np
.
s
=
j
.
template
get
<
std
::
string
>
();
}
...
...
@@ -583,7 +583,7 @@ bool operator==(small_pod lhs, small_pod rhs) noexcept
std
::
tie
(
rhs
.
begin
,
rhs
.
middle
,
rhs
.
end
);
}
bool
operator
==
(
const
non_pod
&
lhs
,
const
non_pod
&
rhs
)
noexcept
bool
operator
==
(
const
non_pod
&
lhs
,
const
non_pod
&
rhs
)
noexcept
{
return
lhs
.
s
==
rhs
.
s
;
}
...
...
@@ -622,13 +622,13 @@ using custom_json = nlohmann::basic_json<std::map, std::vector, std::string, boo
template
<
typename
T
,
typename
>
struct
another_adl_serializer
{
static
void
from_json
(
const
custom_json
&
j
,
T
&
t
)
static
void
from_json
(
const
custom_json
&
j
,
T
&
t
)
{
using
nlohmann
::
from_json
;
from_json
(
j
,
t
);
}
static
void
to_json
(
custom_json
&
j
,
const
T
&
t
)
static
void
to_json
(
custom_json
&
j
,
const
T
&
t
)
{
using
nlohmann
::
to_json
;
to_json
(
j
,
t
);
...
...
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