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
d5b21b05
Unverified
Commit
d5b21b05
authored
Aug 16, 2018
by
Niels Lohmann
Committed by
GitHub
Aug 16, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1153 from theodelrieu/refactor/no_virtual_sax
Refactor/no virtual sax
parents
3ac2d81a
0cc3db4f
Changes
21
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
795 additions
and
339 deletions
+795
-339
Makefile
Makefile
+4
-1
include/nlohmann/detail/conversions/from_json.hpp
include/nlohmann/detail/conversions/from_json.hpp
+2
-1
include/nlohmann/detail/conversions/to_json.hpp
include/nlohmann/detail/conversions/to_json.hpp
+2
-1
include/nlohmann/detail/input/binary_reader.hpp
include/nlohmann/detail/input/binary_reader.hpp
+12
-10
include/nlohmann/detail/input/json_sax.hpp
include/nlohmann/detail/input/json_sax.hpp
+47
-50
include/nlohmann/detail/input/parser.hpp
include/nlohmann/detail/input/parser.hpp
+8
-6
include/nlohmann/detail/iterators/iter_impl.hpp
include/nlohmann/detail/iterators/iter_impl.hpp
+1
-1
include/nlohmann/detail/meta/cpp_future.hpp
include/nlohmann/detail/meta/cpp_future.hpp
+83
-0
include/nlohmann/detail/meta/detected.hpp
include/nlohmann/detail/meta/detected.hpp
+56
-0
include/nlohmann/detail/meta/is_sax.hpp
include/nlohmann/detail/meta/is_sax.hpp
+141
-0
include/nlohmann/detail/meta/type_traits.hpp
include/nlohmann/detail/meta/type_traits.hpp
+2
-74
include/nlohmann/detail/meta/void_t.hpp
include/nlohmann/detail/meta/void_t.hpp
+10
-0
include/nlohmann/detail/output/serializer.hpp
include/nlohmann/detail/output/serializer.hpp
+1
-1
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+9
-8
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+343
-112
test/src/unit-cbor.cpp
test/src/unit-cbor.cpp
+13
-13
test/src/unit-class_parser.cpp
test/src/unit-class_parser.cpp
+15
-15
test/src/unit-deserialization.cpp
test/src/unit-deserialization.cpp
+18
-18
test/src/unit-inspection.cpp
test/src/unit-inspection.cpp
+2
-2
test/src/unit-msgpack.cpp
test/src/unit-msgpack.cpp
+13
-13
test/src/unit-ubjson.cpp
test/src/unit-ubjson.cpp
+13
-13
No files found.
Makefile
View file @
d5b21b05
...
...
@@ -21,7 +21,10 @@ SRCS = include/nlohmann/json.hpp \
include/nlohmann/detail/json_ref.hpp
\
include/nlohmann/detail/macro_scope.hpp
\
include/nlohmann/detail/macro_unscope.hpp
\
include/nlohmann/detail/meta.hpp
\
include/nlohmann/detail/meta/cpp_future.hpp
\
include/nlohmann/detail/meta/detected.hpp
\
include/nlohmann/detail/meta/type_traits.hpp
\
include/nlohmann/detail/meta/void_t.hpp
\
include/nlohmann/detail/output/binary_writer.hpp
\
include/nlohmann/detail/output/output_adapters.hpp
\
include/nlohmann/detail/output/serializer.hpp
\
...
...
include/nlohmann/detail/conversions/from_json.hpp
View file @
d5b21b05
...
...
@@ -15,7 +15,8 @@
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp>
namespace
nlohmann
...
...
include/nlohmann/detail/conversions/to_json.hpp
View file @
d5b21b05
...
...
@@ -8,7 +8,8 @@
#include <valarray> // valarray
#include <vector> // vector
#include <nlohmann/detail/meta.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/value_t.hpp>
#include <nlohmann/detail/iterators/iteration_proxy.hpp>
...
...
include/nlohmann/detail/input/binary_reader.hpp
View file @
d5b21b05
...
...
@@ -17,6 +17,7 @@
#include <nlohmann/detail/input/json_sax.hpp>
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/is_sax.hpp>
#include <nlohmann/detail/value_t.hpp>
namespace
nlohmann
...
...
@@ -30,14 +31,14 @@ namespace detail
/*!
@brief deserialization of CBOR, MessagePack, and UBJSON values
*/
template
<
typename
BasicJsonType
>
template
<
typename
BasicJsonType
,
typename
SAX
=
json_sax_dom_parser
<
BasicJsonType
>
>
class
binary_reader
{
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
using
number_unsigned_t
=
typename
BasicJsonType
::
number_unsigned_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
json_sax_t
=
json_sax
<
BasicJsonType
>
;
using
json_sax_t
=
SAX
;
public:
/*!
...
...
@@ -47,6 +48,7 @@ class binary_reader
*/
explicit
binary_reader
(
input_adapter_t
adapter
)
:
ia
(
std
::
move
(
adapter
))
{
(
void
)
detail
::
is_sax_static_asserts
<
SAX
,
BasicJsonType
>
{};
assert
(
ia
);
}
...
...
@@ -321,7 +323,7 @@ class binary_reader
}
case
0x9F
:
// array (indefinite length)
return
get_cbor_array
(
json_sax_t
::
no_limit
);
return
get_cbor_array
(
std
::
size_t
(
-
1
)
);
// map (0x00..0x17 pairs of data items follow)
case
0xA0
:
...
...
@@ -375,7 +377,7 @@ class binary_reader
}
case
0xBF
:
// map (indefinite length)
return
get_cbor_object
(
json_sax_t
::
no_limit
);
return
get_cbor_object
(
std
::
size_t
(
-
1
)
);
case
0xF4
:
// false
return
sax
->
boolean
(
false
);
...
...
@@ -1020,7 +1022,7 @@ class binary_reader
}
/*!
@param[in] len the length of the array or
json_sax_t::no_limit
for an
@param[in] len the length of the array or
std::size_t(-1)
for an
array of indefinite size
@return whether array creation completed
*/
...
...
@@ -1031,7 +1033,7 @@ class binary_reader
return
false
;
}
if
(
len
!=
json_sax_t
::
no_limit
)
if
(
len
!=
std
::
size_t
(
-
1
)
)
for
(
std
::
size_t
i
=
0
;
i
<
len
;
++
i
)
{
if
(
JSON_UNLIKELY
(
not
parse_cbor_internal
()))
...
...
@@ -1054,7 +1056,7 @@ class binary_reader
}
/*!
@param[in] len the length of the object or
json_sax_t::no_limit
for an
@param[in] len the length of the object or
std::size_t(-1)
for an
object of indefinite size
@return whether object creation completed
*/
...
...
@@ -1066,7 +1068,7 @@ class binary_reader
}
string_t
key
;
if
(
len
!=
json_sax_t
::
no_limit
)
if
(
len
!=
std
::
size_t
(
-
1
)
)
{
for
(
std
::
size_t
i
=
0
;
i
<
len
;
++
i
)
{
...
...
@@ -1558,7 +1560,7 @@ class binary_reader
}
else
{
if
(
JSON_UNLIKELY
(
not
sax
->
start_array
()))
if
(
JSON_UNLIKELY
(
not
sax
->
start_array
(
-
1
)))
{
return
false
;
}
...
...
@@ -1628,7 +1630,7 @@ class binary_reader
}
else
{
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
()))
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
(
-
1
)))
{
return
false
;
}
...
...
include/nlohmann/detail/input/json_sax.hpp
View file @
d5b21b05
This diff is collapsed.
Click to expand it.
include/nlohmann/detail/input/parser.hpp
View file @
d5b21b05
...
...
@@ -9,6 +9,7 @@
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/is_sax.hpp>
#include <nlohmann/detail/input/input_adapters.hpp>
#include <nlohmann/detail/input/json_sax.hpp>
#include <nlohmann/detail/input/lexer.hpp>
...
...
@@ -54,8 +55,6 @@ class parser
value
};
using
json_sax_t
=
json_sax
<
BasicJsonType
>
;
using
parser_callback_t
=
std
::
function
<
bool
(
int
depth
,
parse_event_t
event
,
BasicJsonType
&
parsed
)
>
;
...
...
@@ -144,8 +143,10 @@ class parser
return
sax_parse
(
&
sax_acceptor
,
strict
);
}
bool
sax_parse
(
json_sax_t
*
sax
,
const
bool
strict
=
true
)
template
<
typename
SAX
>
bool
sax_parse
(
SAX
*
sax
,
const
bool
strict
=
true
)
{
(
void
)
detail
::
is_sax_static_asserts
<
SAX
,
BasicJsonType
>
{};
const
bool
result
=
sax_parse_internal
(
sax
);
// strict mode: next byte must be EOF
...
...
@@ -160,7 +161,8 @@ class parser
}
private:
bool
sax_parse_internal
(
json_sax_t
*
sax
)
template
<
typename
SAX
>
bool
sax_parse_internal
(
SAX
*
sax
)
{
// stack to remember the hieararchy of structured values we are parsing
// true = array; false = object
...
...
@@ -177,7 +179,7 @@ class parser
{
case
token_type
:
:
begin_object
:
{
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
()))
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
(
-
1
)))
{
return
false
;
}
...
...
@@ -225,7 +227,7 @@ class parser
case
token_type
:
:
begin_array
:
{
if
(
JSON_UNLIKELY
(
not
sax
->
start_array
()))
if
(
JSON_UNLIKELY
(
not
sax
->
start_array
(
-
1
)))
{
return
false
;
}
...
...
include/nlohmann/detail/iterators/iter_impl.hpp
View file @
d5b21b05
...
...
@@ -8,7 +8,7 @@
#include <nlohmann/detail/iterators/internal_iterator.hpp>
#include <nlohmann/detail/iterators/primitive_iterator.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta.hpp>
#include <nlohmann/detail/meta
/cpp_future
.hpp>
#include <nlohmann/detail/value_t.hpp>
namespace
nlohmann
...
...
include/nlohmann/detail/meta/cpp_future.hpp
0 → 100644
View file @
d5b21b05
#pragma once
#include <ciso646> // not
#include <cstddef> // size_t
#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
namespace
nlohmann
{
namespace
detail
{
// alias templates to reduce boilerplate
template
<
bool
B
,
typename
T
=
void
>
using
enable_if_t
=
typename
std
::
enable_if
<
B
,
T
>::
type
;
template
<
typename
T
>
using
uncvref_t
=
typename
std
::
remove_cv
<
typename
std
::
remove_reference
<
T
>::
type
>::
type
;
// implementation of C++14 index_sequence and affiliates
// source: https://stackoverflow.com/a/32223343
template
<
std
::
size_t
...
Ints
>
struct
index_sequence
{
using
type
=
index_sequence
;
using
value_type
=
std
::
size_t
;
static
constexpr
std
::
size_t
size
()
noexcept
{
return
sizeof
...(
Ints
);
}
};
template
<
class
Sequence1
,
class
Sequence2
>
struct
merge_and_renumber
;
template
<
std
::
size_t
...
I1
,
std
::
size_t
...
I2
>
struct
merge_and_renumber
<
index_sequence
<
I1
...
>
,
index_sequence
<
I2
...
>>
:
index_sequence
<
I1
...,
(
sizeof
...(
I1
)
+
I2
)...
>
{};
template
<
std
::
size_t
N
>
struct
make_index_sequence
:
merge_and_renumber
<
typename
make_index_sequence
<
N
/
2
>::
type
,
typename
make_index_sequence
<
N
-
N
/
2
>::
type
>
{};
template
<
>
struct
make_index_sequence
<
0
>
:
index_sequence
<>
{};
template
<
>
struct
make_index_sequence
<
1
>
:
index_sequence
<
0
>
{};
template
<
typename
...
Ts
>
using
index_sequence_for
=
make_index_sequence
<
sizeof
...(
Ts
)
>
;
/*
Implementation of two C++17 constructs: conjunction, negation. This is needed
to avoid evaluating all the traits in a condition
For example: not std::is_same<void, T>::value and has_value_type<T>::value
will not compile when T = void (on MSVC at least). Whereas
conjunction<negation<std::is_same<void, T>>, has_value_type<T>>::value will
stop evaluating if negation<...>::value == false
Please note that those constructs must be used with caution, since symbols can
become very long quickly (which can slow down compilation and cause MSVC
internal compiler errors). Only use it when you have to (see example ahead).
*/
template
<
class
...
>
struct
conjunction
:
std
::
true_type
{};
template
<
class
B1
>
struct
conjunction
<
B1
>
:
B1
{};
template
<
class
B1
,
class
...
Bn
>
struct
conjunction
<
B1
,
Bn
...
>
:
std
::
conditional
<
bool
(
B1
::
value
),
conjunction
<
Bn
...
>
,
B1
>::
type
{};
template
<
class
B
>
struct
negation
:
std
::
integral_constant
<
bool
,
not
B
::
value
>
{};
// dispatch utility (taken from ranges-v3)
template
<
unsigned
N
>
struct
priority_tag
:
priority_tag
<
N
-
1
>
{};
template
<
>
struct
priority_tag
<
0
>
{};
// taken from ranges-v3
template
<
typename
T
>
struct
static_const
{
static
constexpr
T
value
{};
};
template
<
typename
T
>
constexpr
T
static_const
<
T
>::
value
;
}
}
include/nlohmann/detail/meta/detected.hpp
0 → 100644
View file @
d5b21b05
#pragma once
#include <type_traits>
#include <nlohmann/detail/meta/void_t.hpp>
// http://en.cppreference.com/w/cpp/experimental/is_detected
namespace
nlohmann
{
namespace
detail
{
struct
nonesuch
{
nonesuch
()
=
delete
;
~
nonesuch
()
=
delete
;
nonesuch
(
nonesuch
const
&
)
=
delete
;
void
operator
=
(
nonesuch
const
&
)
=
delete
;
};
template
<
class
Default
,
class
AlwaysVoid
,
template
<
class
...
>
class
Op
,
class
...
Args
>
struct
detector
{
using
value_t
=
std
::
false_type
;
using
type
=
Default
;
};
template
<
class
Default
,
template
<
class
...
>
class
Op
,
class
...
Args
>
struct
detector
<
Default
,
void_t
<
Op
<
Args
...
>>
,
Op
,
Args
...
>
{
using
value_t
=
std
::
true_type
;
using
type
=
Op
<
Args
...
>
;
};
template
<
template
<
class
...
>
class
Op
,
class
...
Args
>
using
is_detected
=
typename
detector
<
nonesuch
,
void
,
Op
,
Args
...
>::
value_t
;
template
<
template
<
class
...
>
class
Op
,
class
...
Args
>
using
detected_t
=
typename
detector
<
nonesuch
,
void
,
Op
,
Args
...
>::
type
;
template
<
class
Default
,
template
<
class
...
>
class
Op
,
class
...
Args
>
using
detected_or
=
detector
<
Default
,
void
,
Op
,
Args
...
>
;
template
<
class
Default
,
template
<
class
...
>
class
Op
,
class
...
Args
>
using
detected_or_t
=
typename
detected_or
<
Default
,
Op
,
Args
...
>::
type
;
template
<
class
Expected
,
template
<
class
...
>
class
Op
,
class
...
Args
>
using
is_detected_exact
=
std
::
is_same
<
Expected
,
detected_t
<
Op
,
Args
...
>>
;
template
<
class
To
,
template
<
class
...
>
class
Op
,
class
...
Args
>
using
is_detected_convertible
=
std
::
is_convertible
<
detected_t
<
Op
,
Args
...
>
,
To
>
;
}
}
include/nlohmann/detail/meta/is_sax.hpp
0 → 100644
View file @
d5b21b05
#pragma once
#include <cstdint> // size_t
#include <utility> // declval
#include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
namespace
nlohmann
{
namespace
detail
{
template
<
typename
T
>
using
null_function_t
=
decltype
(
std
::
declval
<
T
&>
().
null
());
template
<
typename
T
>
using
boolean_function_t
=
decltype
(
std
::
declval
<
T
&>
().
boolean
(
std
::
declval
<
bool
>
()));
template
<
typename
T
,
typename
Integer
>
using
number_integer_function_t
=
decltype
(
std
::
declval
<
T
&>
().
number_integer
(
std
::
declval
<
Integer
>
()));
template
<
typename
T
,
typename
Unsigned
>
using
number_unsigned_function_t
=
decltype
(
std
::
declval
<
T
&>
().
number_unsigned
(
std
::
declval
<
Unsigned
>
()));
template
<
typename
T
,
typename
Float
,
typename
String
>
using
number_float_function_t
=
decltype
(
std
::
declval
<
T
&>
().
number_float
(
std
::
declval
<
Float
>
(),
std
::
declval
<
const
String
&>
()));
template
<
typename
T
,
typename
String
>
using
string_function_t
=
decltype
(
std
::
declval
<
T
&>
().
string
(
std
::
declval
<
String
&>
()));
template
<
typename
T
>
using
start_object_function_t
=
decltype
(
std
::
declval
<
T
&>
().
start_object
(
std
::
declval
<
std
::
size_t
>
()));
template
<
typename
T
,
typename
String
>
using
key_function_t
=
decltype
(
std
::
declval
<
T
&>
().
key
(
std
::
declval
<
String
&>
()));
template
<
typename
T
>
using
end_object_function_t
=
decltype
(
std
::
declval
<
T
&>
().
end_object
());
template
<
typename
T
>
using
start_array_function_t
=
decltype
(
std
::
declval
<
T
&>
().
start_array
(
std
::
declval
<
std
::
size_t
>
()));
template
<
typename
T
>
using
end_array_function_t
=
decltype
(
std
::
declval
<
T
&>
().
end_array
());
template
<
typename
T
,
typename
Exception
>
using
parse_error_function_t
=
decltype
(
std
::
declval
<
T
&>
().
parse_error
(
std
::
declval
<
std
::
size_t
>
(),
std
::
declval
<
const
std
::
string
&>
(),
std
::
declval
<
const
Exception
&>
()));
template
<
typename
SAX
,
typename
BasicJsonType
>
struct
is_sax
{
private:
static_assert
(
is_basic_json
<
BasicJsonType
>::
value
,
"BasicJsonType must be of type basic_json<...>"
);
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
using
number_unsigned_t
=
typename
BasicJsonType
::
number_unsigned_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
exception_t
=
typename
BasicJsonType
::
exception
;
public:
static
constexpr
bool
value
=
is_detected_exact
<
bool
,
null_function_t
,
SAX
>::
value
&&
is_detected_exact
<
bool
,
boolean_function_t
,
SAX
>::
value
&&
is_detected_exact
<
bool
,
number_integer_function_t
,
SAX
,
number_integer_t
>::
value
&&
is_detected_exact
<
bool
,
number_unsigned_function_t
,
SAX
,
number_unsigned_t
>::
value
&&
is_detected_exact
<
bool
,
number_float_function_t
,
SAX
,
number_float_t
,
string_t
>::
value
&&
is_detected_exact
<
bool
,
string_function_t
,
SAX
,
string_t
>::
value
&&
is_detected_exact
<
bool
,
start_object_function_t
,
SAX
>::
value
&&
is_detected_exact
<
bool
,
key_function_t
,
SAX
,
string_t
>::
value
&&
is_detected_exact
<
bool
,
end_object_function_t
,
SAX
>::
value
&&
is_detected_exact
<
bool
,
start_array_function_t
,
SAX
>::
value
&&
is_detected_exact
<
bool
,
end_array_function_t
,
SAX
>::
value
&&
is_detected_exact
<
bool
,
parse_error_function_t
,
SAX
,
exception_t
>::
value
;
};
template
<
typename
SAX
,
typename
BasicJsonType
>
struct
is_sax_static_asserts
{
private:
static_assert
(
is_basic_json
<
BasicJsonType
>::
value
,
"BasicJsonType must be of type basic_json<...>"
);
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
using
number_unsigned_t
=
typename
BasicJsonType
::
number_unsigned_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
exception_t
=
typename
BasicJsonType
::
exception
;
public:
static_assert
(
is_detected_exact
<
bool
,
null_function_t
,
SAX
>::
value
,
"Missing/invalid function: bool null()"
);
static_assert
(
is_detected_exact
<
bool
,
boolean_function_t
,
SAX
>::
value
,
"Missing/invalid function: bool boolean(bool)"
);
static_assert
(
is_detected_exact
<
bool
,
boolean_function_t
,
SAX
>::
value
,
"Missing/invalid function: bool boolean(bool)"
);
static_assert
(
is_detected_exact
<
bool
,
number_integer_function_t
,
SAX
,
number_integer_t
>::
value
,
"Missing/invalid function: bool number_integer(number_integer_t)"
);
static_assert
(
is_detected_exact
<
bool
,
number_unsigned_function_t
,
SAX
,
number_unsigned_t
>::
value
,
"Missing/invalid function: bool number_unsigned(number_unsigned_t)"
);
static_assert
(
is_detected_exact
<
bool
,
number_float_function_t
,
SAX
,
number_float_t
,
string_t
>::
value
,
"Missing/invalid function: bool number_float(number_float_t, const string_t&)"
);
static_assert
(
is_detected_exact
<
bool
,
string_function_t
,
SAX
,
string_t
>::
value
,
"Missing/invalid function: bool string(string_t&)"
);
static_assert
(
is_detected_exact
<
bool
,
start_object_function_t
,
SAX
>::
value
,
"Missing/invalid function: bool start_object(std::size_t)"
);
static_assert
(
is_detected_exact
<
bool
,
key_function_t
,
SAX
,
string_t
>::
value
,
"Missing/invalid function: bool key(string_t&)"
);
static_assert
(
is_detected_exact
<
bool
,
end_object_function_t
,
SAX
>::
value
,
"Missing/invalid function: bool end_object()"
);
static_assert
(
is_detected_exact
<
bool
,
start_array_function_t
,
SAX
>::
value
,
"Missing/invalid function: bool start_array(std::size_t)"
);
static_assert
(
is_detected_exact
<
bool
,
end_array_function_t
,
SAX
>::
value
,
"Missing/invalid function: bool end_array()"
);
static_assert
(
is_detected_exact
<
bool
,
parse_error_function_t
,
SAX
,
exception_t
>::
value
,
"Missing/invalid function: bool parse_error(std::size_t, const "
"std::string&, const exception&)"
);
};
}
}
include/nlohmann/detail/meta.hpp
→
include/nlohmann/detail/meta
/type_traits
.hpp
View file @
d5b21b05
#pragma once
#include <ciso646> // not
#include <cstddef> // size_t
#include <limits> // numeric_limits
#include <type_traits> //
conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_referenc
e, true_type
#include <type_traits> //
false_type, is_constructible, is_integral, is_sam
e, true_type
#include <utility> // declval
#include <nlohmann/json_fwd.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/macro_scope.hpp>
namespace
nlohmann
...
...
@@ -30,68 +30,6 @@ template<typename> struct is_basic_json : std::false_type {};
NLOHMANN_BASIC_JSON_TPL_DECLARATION
struct
is_basic_json
<
NLOHMANN_BASIC_JSON_TPL
>
:
std
::
true_type
{};
// alias templates to reduce boilerplate
template
<
bool
B
,
typename
T
=
void
>
using
enable_if_t
=
typename
std
::
enable_if
<
B
,
T
>::
type
;
template
<
typename
T
>
using
uncvref_t
=
typename
std
::
remove_cv
<
typename
std
::
remove_reference
<
T
>::
type
>::
type
;
// implementation of C++14 index_sequence and affiliates
// source: https://stackoverflow.com/a/32223343
template
<
std
::
size_t
...
Ints
>
struct
index_sequence
{
using
type
=
index_sequence
;
using
value_type
=
std
::
size_t
;
static
constexpr
std
::
size_t
size
()
noexcept
{
return
sizeof
...(
Ints
);
}
};
template
<
class
Sequence1
,
class
Sequence2
>
struct
merge_and_renumber
;
template
<
std
::
size_t
...
I1
,
std
::
size_t
...
I2
>
struct
merge_and_renumber
<
index_sequence
<
I1
...
>
,
index_sequence
<
I2
...
>>
:
index_sequence
<
I1
...,
(
sizeof
...(
I1
)
+
I2
)...
>
{};
template
<
std
::
size_t
N
>
struct
make_index_sequence
:
merge_and_renumber
<
typename
make_index_sequence
<
N
/
2
>::
type
,
typename
make_index_sequence
<
N
-
N
/
2
>::
type
>
{};
template
<
>
struct
make_index_sequence
<
0
>
:
index_sequence
<>
{};
template
<
>
struct
make_index_sequence
<
1
>
:
index_sequence
<
0
>
{};
template
<
typename
...
Ts
>
using
index_sequence_for
=
make_index_sequence
<
sizeof
...(
Ts
)
>
;
/*
Implementation of two C++17 constructs: conjunction, negation. This is needed
to avoid evaluating all the traits in a condition
For example: not std::is_same<void, T>::value and has_value_type<T>::value
will not compile when T = void (on MSVC at least). Whereas
conjunction<negation<std::is_same<void, T>>, has_value_type<T>>::value will
stop evaluating if negation<...>::value == false
Please note that those constructs must be used with caution, since symbols can
become very long quickly (which can slow down compilation and cause MSVC
internal compiler errors). Only use it when you have to (see example ahead).
*/
template
<
class
...
>
struct
conjunction
:
std
::
true_type
{};
template
<
class
B1
>
struct
conjunction
<
B1
>
:
B1
{};
template
<
class
B1
,
class
...
Bn
>
struct
conjunction
<
B1
,
Bn
...
>
:
std
::
conditional
<
bool
(
B1
::
value
),
conjunction
<
Bn
...
>
,
B1
>::
type
{};
template
<
class
B
>
struct
negation
:
std
::
integral_constant
<
bool
,
not
B
::
value
>
{};
// dispatch utility (taken from ranges-v3)
template
<
unsigned
N
>
struct
priority_tag
:
priority_tag
<
N
-
1
>
{};
template
<
>
struct
priority_tag
<
0
>
{};
////////////////////////
// has_/is_ functions //
////////////////////////
...
...
@@ -264,15 +202,5 @@ struct is_compatible_type
is_compatible_complete_type
<
BasicJsonType
,
CompatibleType
>>
{
};
// taken from ranges-v3
template
<
typename
T
>
struct
static_const
{
static
constexpr
T
value
{};
};
template
<
typename
T
>
constexpr
T
static_const
<
T
>::
value
;
}
}
include/nlohmann/detail/meta/void_t.hpp
0 → 100644
View file @
d5b21b05
#pragma once
namespace
nlohmann
{
namespace
detail
{
template
<
typename
...
>
using
void_t
=
void
;
}
}
include/nlohmann/detail/output/serializer.hpp
View file @
d5b21b05
...
...
@@ -16,7 +16,7 @@
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/conversions/to_chars.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta.hpp>
#include <nlohmann/detail/meta
/cpp_future
.hpp>
#include <nlohmann/detail/output/output_adapters.hpp>
#include <nlohmann/detail/value_t.hpp>
...
...
include/nlohmann/json.hpp
View file @
d5b21b05
...
...
@@ -48,7 +48,8 @@ SOFTWARE.
#include <nlohmann/json_fwd.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/value_t.hpp>
#include <nlohmann/detail/conversions/from_json.hpp>
...
...
@@ -170,7 +171,7 @@ class basic_json
friend
class
::
nlohmann
::
detail
::
iter_impl
;
template
<
typename
BasicJsonType
,
typename
CharType
>
friend
class
::
nlohmann
::
detail
::
binary_writer
;
template
<
typename
BasicJsonType
>
template
<
typename
BasicJsonType
,
typename
SAX
>
friend
class
::
nlohmann
::
detail
::
binary_reader
;
template
<
typename
BasicJsonType
>
friend
class
::
nlohmann
::
detail
::
json_sax_dom_parser
;
...
...
@@ -211,6 +212,7 @@ class basic_json
using
initializer_list_t
=
std
::
initializer_list
<
detail
::
json_ref
<
basic_json
>>
;
using
input_format_t
=
detail
::
input_format_t
;
using
json_sax_t
=
json_sax
<
basic_json
>
;
////////////////
// exceptions //
...
...
@@ -1112,8 +1114,6 @@ class basic_json
*/
using
parser_callback_t
=
typename
parser
::
parser_callback_t
;
using
json_sax_t
=
typename
parser
::
json_sax_t
;
//////////////////
// constructors //
//////////////////
...
...
@@ -6013,7 +6013,8 @@ class basic_json
return
parser
(
i
).
accept
(
true
);
}
static
bool
sax_parse
(
detail
::
input_adapter
&&
i
,
json_sax_t
*
sax
,
template
<
typename
SAX
>
static
bool
sax_parse
(
detail
::
input_adapter
&&
i
,
SAX
*
sax
,
input_format_t
format
=
input_format_t
::
json
,
const
bool
strict
=
true
)
{
...
...
@@ -6023,7 +6024,7 @@ class basic_json
case
input_format_t
:
:
json
:
return
parser
(
std
::
move
(
i
)).
sax_parse
(
sax
,
strict
);
default:
return
binary_reader
(
std
::
move
(
i
)).
sax_parse
(
format
,
sax
,
strict
);
return
detail
::
binary_reader
<
basic_json
,
SAX
>
(
std
::
move
(
i
)).
sax_parse
(
format
,
sax
,
strict
);
}
}
...
...
@@ -6096,11 +6097,11 @@ class basic_json
return
parser
(
detail
::
input_adapter
(
first
,
last
)).
accept
(
true
);
}
template
<
class
IteratorType
,
typename
std
::
enable_if
<
template
<
class
IteratorType
,
class
SAX
,
typename
std
::
enable_if
<
std
::
is_base_of
<
std
::
random_access_iterator_tag
,
typename
std
::
iterator_traits
<
IteratorType
>
::
iterator_category
>::
value
,
int
>::
type
=
0
>
static
bool
sax_parse
(
IteratorType
first
,
IteratorType
last
,
json_sax_t
*
sax
)
static
bool
sax_parse
(
IteratorType
first
,
IteratorType
last
,
SAX
*
sax
)
{
return
parser
(
detail
::
input_adapter
(
first
,
last
)).
sax_parse
(
sax
);
}
...
...
single_include/nlohmann/json.hpp
View file @
d5b21b05
This diff is collapsed.
Click to expand it.
test/src/unit-cbor.cpp
View file @
d5b21b05
...
...
@@ -34,68 +34,68 @@ using nlohmann::json;
#include <fstream>
class
SaxCountdown
:
public
nlohmann
::
json
::
json_sax_t
class
SaxCountdown
{
public:
explicit
SaxCountdown
(
const
int
count
)
:
events_left
(
count
)
{}
bool
null
()
override
bool
null
()
{
return
events_left
--
>
0
;
}
bool
boolean
(
bool
)
override
bool
boolean
(
bool
)
{
return
events_left
--
>
0
;
}
bool
number_integer
(
json
::
number_integer_t
)
override
bool
number_integer
(
json
::
number_integer_t
)
{
return
events_left
--
>
0
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
)
{
return
events_left
--
>
0
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
)
override
bool
string
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
start_object
(
std
::
size_t
)
override
bool
start_object
(
std
::
size_t
)
{
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
)
override
bool
key
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
end_object
()
override
bool
end_object
()
{
return
events_left
--
>
0
;
}
bool
start_array
(
std
::
size_t
)
override
bool
start_array
(
std
::
size_t
)
{
return
events_left
--
>
0
;
}
bool
end_array
()
override
bool
end_array
()
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
return
false
;
}
...
...
test/src/unit-class_parser.cpp
View file @
d5b21b05
...
...
@@ -35,48 +35,48 @@ using nlohmann::json;
#include <valarray>
class
SaxEventLogger
:
public
nlohmann
::
json
::
json_sax_t
class
SaxEventLogger
{
public:
bool
null
()
override
bool
null
()
{
events
.
push_back
(
"null()"
);
return
true
;
}
bool
boolean
(
bool
val
)
override
bool
boolean
(
bool
val
)
{
events
.
push_back
(
val
?
"boolean(true)"
:
"boolean(false)"
);
return
true
;
}
bool
number_integer
(
json
::
number_integer_t
val
)
override
bool
number_integer
(
json
::
number_integer_t
val
)
{
events
.
push_back
(
"number_integer("
+
std
::
to_string
(
val
)
+
")"
);
return
true
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
val
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
val
)
{
events
.
push_back
(
"number_unsigned("
+
std
::
to_string
(
val
)
+
")"
);
return
true
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
s
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
s
)
{
events
.
push_back
(
"number_float("
+
s
+
")"
);
return
true
;
}
bool
string
(
std
::
string
&
val
)
override
bool
string
(
std
::
string
&
val
)
{
events
.
push_back
(
"string("
+
val
+
")"
);
return
true
;
}
bool
start_object
(
std
::
size_t
elements
)
override
bool
start_object
(
std
::
size_t
elements
)
{
if
(
elements
==
no_limit
)
if
(
elements
==
std
::
size_t
(
-
1
)
)
{
events
.
push_back
(
"start_object()"
);
}
...
...
@@ -87,21 +87,21 @@ class SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
key
(
std
::
string
&
val
)
override
bool
key
(
std
::
string
&
val
)
{
events
.
push_back
(
"key("
+
val
+
")"
);
return
true
;
}
bool
end_object
()
override
bool
end_object
()
{
events
.
push_back
(
"end_object()"
);
return
true
;
}
bool
start_array
(
std
::
size_t
elements
)
override
bool
start_array
(
std
::
size_t
elements
)
{
if
(
elements
==
no_limit
)
if
(
elements
==
std
::
size_t
(
-
1
)
)
{
events
.
push_back
(
"start_array()"
);
}
...
...
@@ -112,13 +112,13 @@ class SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
end_array
()
override
bool
end_array
()
{
events
.
push_back
(
"end_array()"
);
return
true
;
}
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
errored
=
true
;
events
.
push_back
(
"parse_error("
+
std
::
to_string
(
position
)
+
")"
);
...
...
test/src/unit-deserialization.cpp
View file @
d5b21b05
...
...
@@ -35,45 +35,45 @@ using nlohmann::json;
#include <iostream>
#include <valarray>
struct
SaxEventLogger
:
public
nlohmann
::
json
::
json_sax_t
struct
SaxEventLogger
{
bool
null
()
override
bool
null
()
{
events
.
push_back
(
"null()"
);
return
true
;
}
bool
boolean
(
bool
val
)
override
bool
boolean
(
bool
val
)
{
events
.
push_back
(
val
?
"boolean(true)"
:
"boolean(false)"
);
return
true
;
}
bool
number_integer
(
json
::
number_integer_t
val
)
override
bool
number_integer
(
json
::
number_integer_t
val
)
{
events
.
push_back
(
"number_integer("
+
std
::
to_string
(
val
)
+
")"
);
return
true
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
val
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
val
)
{
events
.
push_back
(
"number_unsigned("
+
std
::
to_string
(
val
)
+
")"
);
return
true
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
s
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
s
)
{
events
.
push_back
(
"number_float("
+
s
+
")"
);
return
true
;
}
bool
string
(
std
::
string
&
val
)
override
bool
string
(
std
::
string
&
val
)
{
events
.
push_back
(
"string("
+
val
+
")"
);
return
true
;
}
bool
start_object
(
std
::
size_t
elements
)
override
bool
start_object
(
std
::
size_t
elements
)
{
if
(
elements
==
std
::
size_t
(
-
1
))
{
...
...
@@ -86,19 +86,19 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
key
(
std
::
string
&
val
)
override
bool
key
(
std
::
string
&
val
)
{
events
.
push_back
(
"key("
+
val
+
")"
);
return
true
;
}
bool
end_object
()
override
bool
end_object
()
{
events
.
push_back
(
"end_object()"
);
return
true
;
}
bool
start_array
(
std
::
size_t
elements
)
override
bool
start_array
(
std
::
size_t
elements
)
{
if
(
elements
==
std
::
size_t
(
-
1
))
{
...
...
@@ -111,13 +111,13 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
end_array
()
override
bool
end_array
()
{
events
.
push_back
(
"end_array()"
);
return
true
;
}
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
events
.
push_back
(
"parse_error("
+
std
::
to_string
(
position
)
+
")"
);
return
false
;
...
...
@@ -128,9 +128,9 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t
struct
SaxEventLoggerExitAfterStartObject
:
public
SaxEventLogger
{
bool
start_object
(
std
::
size_t
elements
)
override
bool
start_object
(
std
::
size_t
elements
)
{
if
(
elements
==
no_limit
)
if
(
elements
==
-
1
)
{
events
.
push_back
(
"start_object()"
);
}
...
...
@@ -144,7 +144,7 @@ struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger
struct
SaxEventLoggerExitAfterKey
:
public
SaxEventLogger
{
bool
key
(
std
::
string
&
val
)
override
bool
key
(
std
::
string
&
val
)
{
events
.
push_back
(
"key("
+
val
+
")"
);
return
false
;
...
...
@@ -153,9 +153,9 @@ struct SaxEventLoggerExitAfterKey : public SaxEventLogger
struct
SaxEventLoggerExitAfterStartArray
:
public
SaxEventLogger
{
bool
start_array
(
std
::
size_t
elements
)
override
bool
start_array
(
std
::
size_t
elements
)
{
if
(
elements
==
no_limit
)
if
(
elements
==
-
1
)
{
events
.
push_back
(
"start_array()"
);
}
...
...
test/src/unit-inspection.cpp
View file @
d5b21b05
...
...
@@ -317,8 +317,8 @@ TEST_CASE("object inspection")
SECTION
(
"round trips"
)
{
for
(
const
auto
&
s
:
{
"3.141592653589793"
,
"1000000000000000010E5"
})
{
"3.141592653589793"
,
"1000000000000000010E5"
})
{
json
j1
=
json
::
parse
(
s
);
std
::
string
s1
=
j1
.
dump
();
...
...
test/src/unit-msgpack.cpp
View file @
d5b21b05
...
...
@@ -34,68 +34,68 @@ using nlohmann::json;
#include <fstream>
class
SaxCountdown
:
public
nlohmann
::
json
::
json_sax_t
class
SaxCountdown
{
public:
explicit
SaxCountdown
(
const
int
count
)
:
events_left
(
count
)
{}
bool
null
()
override
bool
null
()
{
return
events_left
--
>
0
;
}
bool
boolean
(
bool
)
override
bool
boolean
(
bool
)
{
return
events_left
--
>
0
;
}
bool
number_integer
(
json
::
number_integer_t
)
override
bool
number_integer
(
json
::
number_integer_t
)
{
return
events_left
--
>
0
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
)
{
return
events_left
--
>
0
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
)
override
bool
string
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
start_object
(
std
::
size_t
)
override
bool
start_object
(
std
::
size_t
)
{
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
)
override
bool
key
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
end_object
()
override
bool
end_object
()
{
return
events_left
--
>
0
;
}
bool
start_array
(
std
::
size_t
)
override
bool
start_array
(
std
::
size_t
)
{
return
events_left
--
>
0
;
}
bool
end_array
()
override
bool
end_array
()
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
return
false
;
}
...
...
test/src/unit-ubjson.cpp
View file @
d5b21b05
...
...
@@ -34,68 +34,68 @@ using nlohmann::json;
#include <fstream>
class
SaxCountdown
:
public
nlohmann
::
json
::
json_sax_t
class
SaxCountdown
{
public:
explicit
SaxCountdown
(
const
int
count
)
:
events_left
(
count
)
{}
bool
null
()
override
bool
null
()
{
return
events_left
--
>
0
;
}
bool
boolean
(
bool
)
override
bool
boolean
(
bool
)
{
return
events_left
--
>
0
;
}
bool
number_integer
(
json
::
number_integer_t
)
override
bool
number_integer
(
json
::
number_integer_t
)
{
return
events_left
--
>
0
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
)
{
return
events_left
--
>
0
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
)
override
bool
string
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
start_object
(
std
::
size_t
)
override
bool
start_object
(
std
::
size_t
)
{
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
)
override
bool
key
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
end_object
()
override
bool
end_object
()
{
return
events_left
--
>
0
;
}
bool
start_array
(
std
::
size_t
)
override
bool
start_array
(
std
::
size_t
)
{
return
events_left
--
>
0
;
}
bool
end_array
()
override
bool
end_array
()
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
return
false
;
}
...
...
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