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
303a0c58
Unverified
Commit
303a0c58
authored
Mar 07, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into feature/sax2
parents
5beab805
d183d34b
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
1167 additions
and
163 deletions
+1167
-163
include/nlohmann/detail/meta.hpp
include/nlohmann/detail/meta.hpp
+1
-1
include/nlohmann/detail/output/binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+87
-77
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+99
-2
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+187
-80
test/CMakeLists.txt
test/CMakeLists.txt
+1
-0
test/Makefile
test/Makefile
+1
-1
test/src/unit-class_parser.cpp
test/src/unit-class_parser.cpp
+83
-0
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+78
-0
test/src/unit-udt.cpp
test/src/unit-udt.cpp
+79
-2
test/thirdparty/fifo_map/LICENSE.MIT
test/thirdparty/fifo_map/LICENSE.MIT
+21
-0
test/thirdparty/fifo_map/fifo_map.hpp
test/thirdparty/fifo_map/fifo_map.hpp
+530
-0
No files found.
include/nlohmann/detail/meta.hpp
View file @
303a0c58
...
@@ -233,7 +233,7 @@ struct is_compatible_complete_type
...
@@ -233,7 +233,7 @@ struct is_compatible_complete_type
{
{
static
constexpr
bool
value
=
static
constexpr
bool
value
=
not
std
::
is_base_of
<
std
::
istream
,
CompatibleCompleteType
>::
value
and
not
std
::
is_base_of
<
std
::
istream
,
CompatibleCompleteType
>::
value
and
not
std
::
is_same
<
BasicJsonType
,
CompatibleCompleteType
>::
value
and
not
is_basic_json
<
CompatibleCompleteType
>::
value
and
not
is_basic_json_nested_type
<
BasicJsonType
,
CompatibleCompleteType
>::
value
and
not
is_basic_json_nested_type
<
BasicJsonType
,
CompatibleCompleteType
>::
value
and
has_to_json
<
BasicJsonType
,
CompatibleCompleteType
>::
value
;
has_to_json
<
BasicJsonType
,
CompatibleCompleteType
>::
value
;
};
};
...
...
include/nlohmann/detail/output/binary_writer.hpp
View file @
303a0c58
...
@@ -704,114 +704,124 @@ class binary_writer
...
@@ -704,114 +704,124 @@ class binary_writer
oa
->
write_characters
(
vec
.
data
(),
sizeof
(
NumberType
));
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
,
void
write_number_with_ubjson_prefix
(
const
NumberType
n
,
const
bool
add_prefix
)
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
)
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
)
{
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
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'U'
));
// uint8
}
write_number
(
static_cast
<
uint8_t
>
(
n
));
}
}
else
if
(
n
<=
(
std
::
numeric_limits
<
int16_t
>::
max
)())
write_number
(
static_cast
<
uint8_t
>
(
n
));
{
}
if
(
add_prefix
)
else
if
(
n
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int16_t
>::
max
)()))
{
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
if
(
add_prefix
)
}
write_number
(
static_cast
<
int16_t
>
(
n
));
}
else
if
(
n
<=
(
std
::
numeric_limits
<
int32_t
>::
max
)())
{
{
if
(
add_prefix
)
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'l'
));
// int32
}
write_number
(
static_cast
<
int32_t
>
(
n
));
}
}
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'
));
// int32
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'L'
));
// int64
}
write_number
(
static_cast
<
int64_t
>
(
n
));
}
}
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
else
{
{
if
((
std
::
numeric_limits
<
int8_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
int8_t
>::
max
)())
JSON_THROW
(
out_of_range
::
create
(
407
,
"number overflow serializing "
+
std
::
to_string
(
n
)));
{
}
if
(
add_prefix
)
}
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'i'
));
// int8
// UBJSON: write number (signed integer)
}
template
<
typename
NumberType
,
typename
std
::
enable_if
<
write_number
(
static_cast
<
int8_t
>
(
n
));
std
::
is_signed
<
NumberType
>
::
value
and
}
not
std
::
is_floating_point
<
NumberType
>::
value
,
int
>::
type
=
0
>
else
if
((
std
::
numeric_limits
<
uint8_t
>::
min
)()
<=
n
and
n
<=
(
std
::
numeric_limits
<
uint8_t
>::
max
)())
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
>
(
'i'
));
// int8
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'U'
));
// uint8
}
write_number
(
static_cast
<
uint8_t
>
(
n
));
}
}
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
>
(
'U'
));
// uint8
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'I'
));
// int16
}
write_number
(
static_cast
<
int16_t
>
(
n
));
}
}
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
>
(
'I'
));
// int16
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'l'
));
// int32
}
write_number
(
static_cast
<
int32_t
>
(
n
));
}
}
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'
));
// int32
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'L'
));
// int64
}
write_number
(
static_cast
<
int64_t
>
(
n
));
}
}
// LCOV_EXCL_START
write_number
(
static_cast
<
int32_t
>
(
n
));
else
}
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
}
}
/*!
/*!
...
...
include/nlohmann/json.hpp
View file @
303a0c58
...
@@ -1210,6 +1210,7 @@ class basic_json
...
@@ -1210,6 +1210,7 @@ class basic_json
- @a CompatibleType is not derived from `std::istream`,
- @a CompatibleType is not derived from `std::istream`,
- @a CompatibleType is not @ref basic_json (to avoid hijacking copy/move
- @a CompatibleType is not @ref basic_json (to avoid hijacking copy/move
constructors),
constructors),
- @a CompatibleType is not a different @ref basic_json type (i.e. with different template arguments)
- @a CompatibleType is not a @ref basic_json nested type (e.g.,
- @a CompatibleType is not a @ref basic_json nested type (e.g.,
@ref json_pointer, @ref iterator, etc ...)
@ref json_pointer, @ref iterator, etc ...)
- @ref @ref json_serializer<U> has a
- @ref @ref json_serializer<U> has a
...
@@ -1245,6 +1246,78 @@ class basic_json
...
@@ -1245,6 +1246,78 @@ class basic_json
assert_invariant
();
assert_invariant
();
}
}
/*!
@brief create a JSON value from an existing one
This is a constructor for existing @ref basic_json types.
It does not hijack copy/move constructors, since the parameter has different
template arguments than the current ones.
The constructor tries to convert the internal @ref m_value of the parameter.
@tparam BasicJsonType a type such that:
- @a BasicJsonType is a @ref basic_json type.
- @a BasicJsonType has different template arguments than @ref basic_json_t.
@param[in] val the @ref basic_json value to be converted.
@complexity Usually linear in the size of the passed @a val, also
depending on the implementation of the called `to_json()`
method.
@exceptionsafety Depends on the called constructor. For types directly
supported by the library (i.e., all types for which no `to_json()` function
was provided), strong guarantee holds: if an exception is thrown, there are
no changes to any JSON value.
@since version 3.1.2
*/
template
<
typename
BasicJsonType
,
detail
::
enable_if_t
<
detail
::
is_basic_json
<
BasicJsonType
>
::
value
and
not
std
::
is_same
<
basic_json
,
BasicJsonType
>::
value
,
int
>
=
0
>
basic_json
(
const
BasicJsonType
&
val
)
{
using
other_boolean_t
=
typename
BasicJsonType
::
boolean_t
;
using
other_number_float_t
=
typename
BasicJsonType
::
number_float_t
;
using
other_number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
using
other_number_unsigned_t
=
typename
BasicJsonType
::
number_unsigned_t
;
using
other_string_t
=
typename
BasicJsonType
::
string_t
;
using
other_object_t
=
typename
BasicJsonType
::
object_t
;
using
other_array_t
=
typename
BasicJsonType
::
array_t
;
switch
(
val
.
type
())
{
case
value_t
:
:
boolean
:
JSONSerializer
<
other_boolean_t
>::
to_json
(
*
this
,
val
.
template
get
<
other_boolean_t
>());
break
;
case
value_t
:
:
number_float
:
JSONSerializer
<
other_number_float_t
>::
to_json
(
*
this
,
val
.
template
get
<
other_number_float_t
>());
break
;
case
value_t
:
:
number_integer
:
JSONSerializer
<
other_number_integer_t
>::
to_json
(
*
this
,
val
.
template
get
<
other_number_integer_t
>());
break
;
case
value_t
:
:
number_unsigned
:
JSONSerializer
<
other_number_unsigned_t
>::
to_json
(
*
this
,
val
.
template
get
<
other_number_unsigned_t
>());
break
;
case
value_t
:
:
string
:
JSONSerializer
<
other_string_t
>::
to_json
(
*
this
,
val
.
template
get_ref
<
const
other_string_t
&
>());
break
;
case
value_t
:
:
object
:
JSONSerializer
<
other_object_t
>::
to_json
(
*
this
,
val
.
template
get_ref
<
const
other_object_t
&
>());
break
;
case
value_t
:
:
array
:
JSONSerializer
<
other_array_t
>::
to_json
(
*
this
,
val
.
template
get_ref
<
const
other_array_t
&
>());
break
;
case
value_t
:
:
null
:
*
this
=
nullptr
;
break
;
case
value_t
:
:
discarded
:
m_type
=
value_t
::
discarded
;
break
;
}
assert_invariant
();
}
/*!
/*!
@brief create a container (array or object) from an initializer list
@brief create a container (array or object) from an initializer list
...
@@ -2417,6 +2490,29 @@ class basic_json
...
@@ -2417,6 +2490,29 @@ class basic_json
return
*
this
;
return
*
this
;
}
}
/*!
@brief get special-case overload
This overloads converts the current @ref basic_json in a different
@ref basic_json type
@tparam BasicJsonType == @ref basic_json
@return a copy of *this, converted into @tparam BasicJsonType
@complexity Depending on the implementation of the called `from_json()`
method.
@since version 3.1.2
*/
template
<
typename
BasicJsonType
,
detail
::
enable_if_t
<
not
std
::
is_same
<
BasicJsonType
,
basic_json
>
::
value
and
detail
::
is_basic_json
<
BasicJsonType
>::
value
,
int
>
=
0
>
BasicJsonType
get
()
const
{
return
*
this
;
}
/*!
/*!
@brief get a value (explicit)
@brief get a value (explicit)
...
@@ -2458,7 +2554,7 @@ class basic_json
...
@@ -2458,7 +2554,7 @@ class basic_json
*/
*/
template
<
typename
ValueTypeCV
,
typename
ValueType
=
detail
::
uncvref_t
<
ValueTypeCV
>,
template
<
typename
ValueTypeCV
,
typename
ValueType
=
detail
::
uncvref_t
<
ValueTypeCV
>,
detail
::
enable_if_t
<
detail
::
enable_if_t
<
not
std
::
is_same
<
basic_json_t
,
ValueType
>::
value
and
not
detail
::
is_basic_json
<
ValueType
>::
value
and
detail
::
has_from_json
<
basic_json_t
,
ValueType
>::
value
and
detail
::
has_from_json
<
basic_json_t
,
ValueType
>::
value
and
not
detail
::
has_non_default_from_json
<
basic_json_t
,
ValueType
>::
value
,
not
detail
::
has_non_default_from_json
<
basic_json_t
,
ValueType
>::
value
,
int
>
=
0
>
int
>
=
0
>
...
@@ -2724,7 +2820,8 @@ class basic_json
...
@@ -2724,7 +2820,8 @@ class basic_json
template
<
typename
ValueType
,
typename
std
::
enable_if
<
template
<
typename
ValueType
,
typename
std
::
enable_if
<
not
std
::
is_pointer
<
ValueType
>
::
value
and
not
std
::
is_pointer
<
ValueType
>
::
value
and
not
std
::
is_same
<
ValueType
,
detail
::
json_ref
<
basic_json
>>::
value
and
not
std
::
is_same
<
ValueType
,
detail
::
json_ref
<
basic_json
>>::
value
and
not
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
not
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
and
not
detail
::
is_basic_json
<
ValueType
>::
value
#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
and
not
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
and
not
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
#endif
#endif
...
...
single_include/nlohmann/json.hpp
View file @
303a0c58
This diff is collapsed.
Click to expand it.
test/CMakeLists.txt
View file @
303a0c58
...
@@ -104,6 +104,7 @@ foreach(file ${files})
...
@@ -104,6 +104,7 @@ foreach(file ${files})
target_compile_definitions
(
${
testcase
}
PRIVATE CATCH_CONFIG_FAST_COMPILE
)
target_compile_definitions
(
${
testcase
}
PRIVATE CATCH_CONFIG_FAST_COMPILE
)
target_include_directories
(
${
testcase
}
PRIVATE
"thirdparty/catch"
)
target_include_directories
(
${
testcase
}
PRIVATE
"thirdparty/catch"
)
target_include_directories
(
${
testcase
}
PRIVATE
"thirdparty/fifo_map"
)
target_include_directories
(
${
testcase
}
PRIVATE
${
NLOHMANN_JSON_INCLUDE_BUILD_DIR
}
)
target_include_directories
(
${
testcase
}
PRIVATE
${
NLOHMANN_JSON_INCLUDE_BUILD_DIR
}
)
target_link_libraries
(
${
testcase
}
${
NLOHMANN_JSON_TARGET_NAME
}
)
target_link_libraries
(
${
testcase
}
${
NLOHMANN_JSON_TARGET_NAME
}
)
...
...
test/Makefile
View file @
303a0c58
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
# additional flags
# additional flags
CXXFLAGS
+=
-std
=
c++11
-Wall
-Wextra
-pedantic
-Wcast-align
-Wcast-qual
-Wno-ctor-dtor-privacy
-Wdisabled-optimization
-Wformat
=
2
-Winit-self
-Wmissing-declarations
-Wmissing-include-dirs
-Wold-style-cast
-Woverloaded-virtual
-Wredundant-decls
-Wshadow
-Wsign-conversion
-Wsign-promo
-Wstrict-overflow
=
5
-Wswitch
-Wundef
-Wno-unused
-Wnon-virtual-dtor
-Wreorder
-Wdeprecated
-Wno-float-equal
CXXFLAGS
+=
-std
=
c++11
-Wall
-Wextra
-pedantic
-Wcast-align
-Wcast-qual
-Wno-ctor-dtor-privacy
-Wdisabled-optimization
-Wformat
=
2
-Winit-self
-Wmissing-declarations
-Wmissing-include-dirs
-Wold-style-cast
-Woverloaded-virtual
-Wredundant-decls
-Wshadow
-Wsign-conversion
-Wsign-promo
-Wstrict-overflow
=
5
-Wswitch
-Wundef
-Wno-unused
-Wnon-virtual-dtor
-Wreorder
-Wdeprecated
-Wno-float-equal
CPPFLAGS
+=
-I
../single_include
-I
.
-I
thirdparty/catch
-DCATCH_CONFIG_FAST_COMPILE
CPPFLAGS
+=
-I
../single_include
-I
.
-I
thirdparty/catch
-
I
thirdparty/fifo_map
-
DCATCH_CONFIG_FAST_COMPILE
SOURCES
=
src/unit.cpp
\
SOURCES
=
src/unit.cpp
\
src/unit-algorithms.cpp
\
src/unit-algorithms.cpp
\
...
...
test/src/unit-class_parser.cpp
View file @
303a0c58
...
@@ -1527,6 +1527,89 @@ TEST_CASE("parser class")
...
@@ -1527,6 +1527,89 @@ TEST_CASE("parser class")
});
});
CHECK
(
j_empty_array
==
json
());
CHECK
(
j_empty_array
==
json
());
}
}
SECTION
(
"skip in GeoJSON"
)
{
auto
geojsonExample
=
R"(
{ "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
"properties": {"prop0": "value0"}
},
{ "type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
]
},
"properties": {
"prop0": "value0",
"prop1": 0.0
}
},
{ "type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
]
},
"properties": {
"prop0": "value0",
"prop1": {"this": "that"}
}
}
]
})"
;
json
::
parser_callback_t
cb
=
[
&
](
int
depth
,
json
::
parse_event_t
event
,
json
&
parsed
)
{
// skip uninteresting events
if
(
event
==
json
::
parse_event_t
::
value
and
!
parsed
.
is_primitive
())
{
return
false
;
}
switch
(
event
)
{
case
json
:
:
parse_event_t
::
key
:
{
return
true
;
}
case
json
:
:
parse_event_t
::
value
:
{
return
false
;
}
case
json
:
:
parse_event_t
::
object_start
:
{
return
true
;
}
case
json
:
:
parse_event_t
::
object_end
:
{
return
false
;
}
case
json
:
:
parse_event_t
::
array_start
:
{
return
true
;
}
case
json
:
:
parse_event_t
::
array_end
:
{
return
false
;
}
default:
{
return
true
;
}
}
};
auto
j
=
json
::
parse
(
geojsonExample
,
cb
,
true
);
CHECK
(
j
==
json
());
}
}
}
SECTION
(
"constructing from contiguous containers"
)
SECTION
(
"constructing from contiguous containers"
)
...
...
test/src/unit-regression.cpp
View file @
303a0c58
...
@@ -32,10 +32,72 @@ SOFTWARE.
...
@@ -32,10 +32,72 @@ SOFTWARE.
#include <nlohmann/json.hpp>
#include <nlohmann/json.hpp>
using
nlohmann
::
json
;
using
nlohmann
::
json
;
#include "fifo_map.hpp"
#include <fstream>
#include <fstream>
#include <list>
#include <list>
#include <cstdio>
#include <cstdio>
/////////////////////////////////////////////////////////////////////
// for #972
/////////////////////////////////////////////////////////////////////
template
<
class
K
,
class
V
,
class
dummy_compare
,
class
A
>
using
my_workaround_fifo_map
=
nlohmann
::
fifo_map
<
K
,
V
,
nlohmann
::
fifo_map_compare
<
K
>
,
A
>
;
using
my_json
=
nlohmann
::
basic_json
<
my_workaround_fifo_map
>
;
/////////////////////////////////////////////////////////////////////
// for #977
/////////////////////////////////////////////////////////////////////
namespace
ns
{
struct
foo
{
int
x
;
};
template
<
typename
,
typename
SFINAE
=
void
>
struct
foo_serializer
;
template
<
typename
T
>
struct
foo_serializer
<
T
,
typename
std
::
enable_if
<
std
::
is_same
<
foo
,
T
>::
value
>::
type
>
{
template
<
typename
BasicJsonType
>
static
void
to_json
(
BasicJsonType
&
j
,
const
T
&
value
)
{
j
=
BasicJsonType
{{
"x"
,
value
.
x
}};
}
template
<
typename
BasicJsonType
>
static
void
from_json
(
const
BasicJsonType
&
j
,
T
&
value
)
// !!!
{
nlohmann
::
from_json
(
j
.
at
(
"x"
),
value
.
x
);
}
};
template
<
typename
T
>
struct
foo_serializer
<
T
,
typename
std
::
enable_if
<
!
std
::
is_same
<
foo
,
T
>::
value
>::
type
>
{
template
<
typename
BasicJsonType
>
static
void
to_json
(
BasicJsonType
&
j
,
const
T
&
value
)
noexcept
{
::
nlohmann
::
to_json
(
j
,
value
);
}
template
<
typename
BasicJsonType
>
static
void
from_json
(
const
BasicJsonType
&
j
,
T
&
value
)
//!!!
{
::
nlohmann
::
from_json
(
j
,
value
);
}
};
}
using
foo_json
=
nlohmann
::
basic_json
<
std
::
map
,
std
::
vector
,
std
::
string
,
bool
,
std
::
int64_t
,
std
::
uint64_t
,
double
,
std
::
allocator
,
ns
::
foo_serializer
>
;
/////////////////////////////////////////////////////////////////////
// for #805
/////////////////////////////////////////////////////////////////////
namespace
namespace
{
{
struct
nocopy
struct
nocopy
...
@@ -1436,4 +1498,20 @@ TEST_CASE("regression tests")
...
@@ -1436,4 +1498,20 @@ TEST_CASE("regression tests")
//CHECK_THROWS_WITH(json::from_ubjson(v_ubjson),
//CHECK_THROWS_WITH(json::from_ubjson(v_ubjson),
// "[json.exception.out_of_range.408] excessive object size: 8658170730974374167");
// "[json.exception.out_of_range.408] excessive object size: 8658170730974374167");
}
}
SECTION
(
"issue #972 - Segmentation fault on G++ when trying to assign json string literal to custom json type"
)
{
my_json
foo
=
R"([1, 2, 3])"
_json
;
}
SECTION
(
"issue #977 - Assigning between different json types"
)
{
foo_json
lj
=
ns
::
foo
{
3
};
ns
::
foo
ff
=
lj
;
CHECK
(
lj
.
is_object
());
CHECK
(
lj
.
size
()
==
1
);
CHECK
(
lj
[
"x"
]
==
3
);
CHECK
(
ff
.
x
==
3
);
nlohmann
::
json
nj
=
lj
;
// This line works as expected
}
}
}
test/src/unit-udt.cpp
View file @
303a0c58
...
@@ -693,6 +693,83 @@ TEST_CASE("custom serializer that does adl by default", "[udt]")
...
@@ -693,6 +693,83 @@ TEST_CASE("custom serializer that does adl by default", "[udt]")
CHECK
(
me
==
cj
.
get
<
udt
::
person
>
());
CHECK
(
me
==
cj
.
get
<
udt
::
person
>
());
}
}
TEST_CASE
(
"different basic_json types conversions"
)
{
using
json
=
nlohmann
::
json
;
SECTION
(
"null"
)
{
json
j
;
custom_json
cj
=
j
;
CHECK
(
cj
==
nullptr
);
}
SECTION
(
"boolean"
)
{
json
j
=
true
;
custom_json
cj
=
j
;
CHECK
(
cj
==
true
);
}
SECTION
(
"discarded"
)
{
json
j
(
json
::
value_t
::
discarded
);
custom_json
cj
;
CHECK_NOTHROW
(
cj
=
j
);
CHECK
(
cj
.
type
()
==
custom_json
::
value_t
::
discarded
);
}
SECTION
(
"array"
)
{
json
j
=
{
1
,
2
,
3
};
custom_json
cj
=
j
;
CHECK
((
cj
==
std
::
vector
<
int
>
{
1
,
2
,
3
}));
}
SECTION
(
"integer"
)
{
json
j
=
42
;
custom_json
cj
=
j
;
CHECK
(
cj
==
42
);
}
SECTION
(
"float"
)
{
json
j
=
42.0
;
custom_json
cj
=
j
;
CHECK
(
cj
==
42.0
);
}
SECTION
(
"unsigned"
)
{
json
j
=
42u
;
custom_json
cj
=
j
;
CHECK
(
cj
==
42u
);
}
SECTION
(
"string"
)
{
json
j
=
"forty-two"
;
custom_json
cj
=
j
;
CHECK
(
cj
==
"forty-two"
);
}
SECTION
(
"object"
)
{
json
j
=
{{
"forty"
,
"two"
}};
custom_json
cj
=
j
;
auto
m
=
j
.
get
<
std
::
map
<
std
::
string
,
std
::
string
>>
();
CHECK
(
cj
==
m
);
}
SECTION
(
"get<custom_json>"
)
{
json
j
=
42
;
custom_json
cj
=
j
.
get
<
custom_json
>
();
CHECK
(
cj
==
42
);
}
}
namespace
namespace
{
{
struct
incomplete
;
struct
incomplete
;
...
@@ -730,6 +807,6 @@ TEST_CASE("Issue #924")
...
@@ -730,6 +807,6 @@ TEST_CASE("Issue #924")
// Prevent get<std::vector<Evil>>() to throw
// Prevent get<std::vector<Evil>>() to throw
auto
j
=
json
::
array
();
auto
j
=
json
::
array
();
(
void
)
j
.
get
<
Evil
>
(
);
CHECK_NOTHROW
(
j
.
get
<
Evil
>
()
);
(
void
)
j
.
get
<
std
::
vector
<
Evil
>>
(
);
CHECK_NOTHROW
(
j
.
get
<
std
::
vector
<
Evil
>>
()
);
}
}
test/thirdparty/fifo_map/LICENSE.MIT
0 → 100644
View file @
303a0c58
MIT License
Copyright (c) 2015-2017 Niels Lohmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
test/thirdparty/fifo_map/fifo_map.hpp
0 → 100644
View file @
303a0c58
This diff is collapsed.
Click to expand it.
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