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
d2d65bb2
Unverified
Commit
d2d65bb2
authored
Mar 07, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
refined SFINAE to fix some warnings
parent
476b2e09
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
174 additions
and
154 deletions
+174
-154
include/nlohmann/detail/output/binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+87
-77
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+87
-77
No files found.
include/nlohmann/detail/output/binary_writer.hpp
View file @
d2d65bb2
...
...
@@ -704,114 +704,124 @@ class binary_writer
oa
->
write_characters
(
vec
.
data
(),
sizeof
(
NumberType
));
}
template
<
typename
NumberType
>
// UBJSON: write number (floating point)
template
<
typename
NumberType
,
typename
std
::
enable_if
<
std
::
is_floating_point
<
NumberType
>
::
value
,
int
>::
type
=
0
>
void
write_number_with_ubjson_prefix
(
const
NumberType
n
,
const
bool
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'D'
));
// float64
}
write_number
(
n
);
}
// UBJSON: write number (unsigned integer)
template
<
typename
NumberType
,
typename
std
::
enable_if
<
std
::
is_unsigned
<
NumberType
>
::
value
,
int
>::
type
=
0
>
void
write_number_with_ubjson_prefix
(
const
NumberType
n
,
const
bool
add_prefix
)
{
if
(
std
::
is_floating_point
<
NumberType
>::
value
)
if
(
n
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int8_t
>::
max
)())
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'
D'
));
// float64
oa
->
write_character
(
static_cast
<
CharType
>
(
'
i'
));
// int8
}
write_number
(
n
);
write_number
(
static_cast
<
uint8_t
>
(
n
)
);
}
else
if
(
std
::
is_unsigned
<
NumberType
>::
value
)
else
if
(
n
<=
(
std
::
numeric_limits
<
uint8_t
>::
max
)()
)
{
if
(
n
<=
(
std
::
numeric_limits
<
int8_t
>::
max
)())
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'i'
));
// int8
}
write_number
(
static_cast
<
uint8_t
>
(
n
));
}
else
if
(
n
<=
(
std
::
numeric_limits
<
uint8_t
>::
max
)())
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'U'
));
// uint8
}
write_number
(
static_cast
<
uint8_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'U'
));
// uint8
}
else
if
(
n
<=
(
std
::
numeric_limits
<
int16_t
>::
max
)())
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
}
write_number
(
static_cast
<
int16_t
>
(
n
));
}
else
if
(
n
<=
(
std
::
numeric_limits
<
int32_t
>::
max
)())
write_number
(
static_cast
<
uint8_t
>
(
n
));
}
else
if
(
n
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int16_t
>::
max
)()))
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'l'
));
// int32
}
write_number
(
static_cast
<
int32_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
}
else
if
(
n
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)())
write_number
(
static_cast
<
int16_t
>
(
n
));
}
else
if
(
n
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int32_t
>::
max
)()))
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'L'
));
// int64
}
write_number
(
static_cast
<
int64_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'l'
));
// int32
}
else
write_number
(
static_cast
<
int32_t
>
(
n
));
}
else
if
(
n
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int64_t
>::
max
)()))
{
if
(
add_prefix
)
{
JSON_THROW
(
out_of_range
::
create
(
407
,
"number overflow serializing "
+
std
::
to_string
(
n
)));
oa
->
write_character
(
static_cast
<
CharType
>
(
'L'
));
// int64
}
write_number
(
static_cast
<
int64_t
>
(
n
));
}
else
{
if
((
std
::
numeric_limits
<
int8_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int8_t
>::
max
)())
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'i'
));
// int8
}
write_number
(
static_cast
<
int8_t
>
(
n
));
}
else
if
((
std
::
numeric_limits
<
uint8_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
uint8_t
>::
max
)())
JSON_THROW
(
out_of_range
::
create
(
407
,
"number overflow serializing "
+
std
::
to_string
(
n
)));
}
}
// UBJSON: write number (signed integer)
template
<
typename
NumberType
,
typename
std
::
enable_if
<
std
::
is_signed
<
NumberType
>
::
value
and
not
std
::
is_floating_point
<
NumberType
>::
value
,
int
>::
type
=
0
>
void
write_number_with_ubjson_prefix
(
const
NumberType
n
,
const
bool
add_prefix
)
{
if
((
std
::
numeric_limits
<
int8_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int8_t
>::
max
)())
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'U'
));
// uint8
}
write_number
(
static_cast
<
uint8_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'i'
));
// int8
}
else
if
((
std
::
numeric_limits
<
int16_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int16_t
>::
max
)())
write_number
(
static_cast
<
int8_t
>
(
n
));
}
else
if
(
static_cast
<
int64_t
>
((
std
::
numeric_limits
<
uint8_t
>::
min
)())
<=
n
and
n
<=
static_cast
<
int64_t
>
((
std
::
numeric_limits
<
uint8_t
>::
max
)()))
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
}
write_number
(
static_cast
<
int16_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'U'
));
// uint8
}
else
if
((
std
::
numeric_limits
<
int32_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int32_t
>::
max
)())
write_number
(
static_cast
<
uint8_t
>
(
n
));
}
else
if
((
std
::
numeric_limits
<
int16_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int16_t
>::
max
)())
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'l'
));
// int32
}
write_number
(
static_cast
<
int32_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
}
else
if
((
std
::
numeric_limits
<
int64_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)())
write_number
(
static_cast
<
int16_t
>
(
n
));
}
else
if
((
std
::
numeric_limits
<
int32_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int32_t
>::
max
)())
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'L'
));
// int64
}
write_number
(
static_cast
<
int64_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'l'
));
// int32
}
// LCOV_EXCL_START
else
write_number
(
static_cast
<
int32_t
>
(
n
));
}
else
if
((
std
::
numeric_limits
<
int64_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)())
{
if
(
add_prefix
)
{
JSON_THROW
(
out_of_range
::
create
(
407
,
"number overflow serializing "
+
std
::
to_string
(
n
)));
oa
->
write_character
(
static_cast
<
CharType
>
(
'L'
));
// int64
}
// LCOV_EXCL_STOP
write_number
(
static_cast
<
int64_t
>
(
n
));
}
// LCOV_EXCL_START
else
{
JSON_THROW
(
out_of_range
::
create
(
407
,
"number overflow serializing "
+
std
::
to_string
(
n
)));
}
// LCOV_EXCL_STOP
}
/*!
...
...
single_include/nlohmann/json.hpp
View file @
d2d65bb2
...
...
@@ -6909,114 +6909,124 @@ class binary_writer
oa
->
write_characters
(
vec
.
data
(),
sizeof
(
NumberType
));
}
template
<
typename
NumberType
>
// UBJSON: write number (floating point)
template
<
typename
NumberType
,
typename
std
::
enable_if
<
std
::
is_floating_point
<
NumberType
>
::
value
,
int
>::
type
=
0
>
void
write_number_with_ubjson_prefix
(
const
NumberType
n
,
const
bool
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'D'
));
// float64
}
write_number
(
n
);
}
// UBJSON: write number (unsigned integer)
template
<
typename
NumberType
,
typename
std
::
enable_if
<
std
::
is_unsigned
<
NumberType
>
::
value
,
int
>::
type
=
0
>
void
write_number_with_ubjson_prefix
(
const
NumberType
n
,
const
bool
add_prefix
)
{
if
(
std
::
is_floating_point
<
NumberType
>::
value
)
if
(
n
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int8_t
>::
max
)())
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'
D'
));
// float64
oa
->
write_character
(
static_cast
<
CharType
>
(
'
i'
));
// int8
}
write_number
(
n
);
write_number
(
static_cast
<
uint8_t
>
(
n
)
);
}
else
if
(
std
::
is_unsigned
<
NumberType
>::
value
)
else
if
(
n
<=
(
std
::
numeric_limits
<
uint8_t
>::
max
)()
)
{
if
(
n
<=
(
std
::
numeric_limits
<
int8_t
>::
max
)())
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'i'
));
// int8
}
write_number
(
static_cast
<
uint8_t
>
(
n
));
}
else
if
(
n
<=
(
std
::
numeric_limits
<
uint8_t
>::
max
)())
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'U'
));
// uint8
}
write_number
(
static_cast
<
uint8_t
>
(
n
));
}
else
if
(
n
<=
(
std
::
numeric_limits
<
int16_t
>::
max
)())
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
}
write_number
(
static_cast
<
int16_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'U'
));
// uint8
}
else
if
(
n
<=
(
std
::
numeric_limits
<
int32_t
>::
max
)())
write_number
(
static_cast
<
uint8_t
>
(
n
));
}
else
if
(
n
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int16_t
>::
max
)()))
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'l'
));
// int32
}
write_number
(
static_cast
<
int32_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
}
else
if
(
n
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)())
write_number
(
static_cast
<
int16_t
>
(
n
));
}
else
if
(
n
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int32_t
>::
max
)()))
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'L'
));
// int64
}
write_number
(
static_cast
<
int64_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'l'
));
// int32
}
else
write_number
(
static_cast
<
int32_t
>
(
n
));
}
else
if
(
n
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int64_t
>::
max
)()))
{
if
(
add_prefix
)
{
JSON_THROW
(
out_of_range
::
create
(
407
,
"number overflow serializing "
+
std
::
to_string
(
n
)));
oa
->
write_character
(
static_cast
<
CharType
>
(
'L'
));
// int64
}
write_number
(
static_cast
<
int64_t
>
(
n
));
}
else
{
if
((
std
::
numeric_limits
<
int8_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int8_t
>::
max
)())
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'i'
));
// int8
}
write_number
(
static_cast
<
int8_t
>
(
n
));
}
else
if
((
std
::
numeric_limits
<
uint8_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
uint8_t
>::
max
)())
JSON_THROW
(
out_of_range
::
create
(
407
,
"number overflow serializing "
+
std
::
to_string
(
n
)));
}
}
// UBJSON: write number (signed integer)
template
<
typename
NumberType
,
typename
std
::
enable_if
<
std
::
is_signed
<
NumberType
>
::
value
and
not
std
::
is_floating_point
<
NumberType
>::
value
,
int
>::
type
=
0
>
void
write_number_with_ubjson_prefix
(
const
NumberType
n
,
const
bool
add_prefix
)
{
if
((
std
::
numeric_limits
<
int8_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int8_t
>::
max
)())
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'U'
));
// uint8
}
write_number
(
static_cast
<
uint8_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'i'
));
// int8
}
else
if
((
std
::
numeric_limits
<
int16_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int16_t
>::
max
)())
write_number
(
static_cast
<
int8_t
>
(
n
));
}
else
if
(
static_cast
<
int64_t
>
((
std
::
numeric_limits
<
uint8_t
>::
min
)())
<=
n
and
n
<=
static_cast
<
int64_t
>
((
std
::
numeric_limits
<
uint8_t
>::
max
)()))
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
}
write_number
(
static_cast
<
int16_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'U'
));
// uint8
}
else
if
((
std
::
numeric_limits
<
int32_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int32_t
>::
max
)())
write_number
(
static_cast
<
uint8_t
>
(
n
));
}
else
if
((
std
::
numeric_limits
<
int16_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int16_t
>::
max
)())
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'l'
));
// int32
}
write_number
(
static_cast
<
int32_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
}
else
if
((
std
::
numeric_limits
<
int64_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)())
write_number
(
static_cast
<
int16_t
>
(
n
));
}
else
if
((
std
::
numeric_limits
<
int32_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int32_t
>::
max
)())
{
if
(
add_prefix
)
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'L'
));
// int64
}
write_number
(
static_cast
<
int64_t
>
(
n
));
oa
->
write_character
(
static_cast
<
CharType
>
(
'l'
));
// int32
}
// LCOV_EXCL_START
else
write_number
(
static_cast
<
int32_t
>
(
n
));
}
else
if
((
std
::
numeric_limits
<
int64_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)())
{
if
(
add_prefix
)
{
JSON_THROW
(
out_of_range
::
create
(
407
,
"number overflow serializing "
+
std
::
to_string
(
n
)));
oa
->
write_character
(
static_cast
<
CharType
>
(
'L'
));
// int64
}
// LCOV_EXCL_STOP
write_number
(
static_cast
<
int64_t
>
(
n
));
}
// LCOV_EXCL_START
else
{
JSON_THROW
(
out_of_range
::
create
(
407
,
"number overflow serializing "
+
std
::
to_string
(
n
)));
}
// LCOV_EXCL_STOP
}
/*!
...
...
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