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
0cc3db4f
Unverified
Commit
0cc3db4f
authored
7 years ago
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add static_asserts on SAX interface
parent
38f8a51a
develop
bon8
coverity_scan
feature/optional
gcc_warning_flags
icpc
issue2228
issue2615
issue2932
issue3232_use_catch
master
release/3.10.2
release/3.10.3
release/3.10.4
release/3.10.5
string_view
string_view2
update_doctest
3.6.1
3.3.0
3.2.0
v3.10.5
v3.10.4
v3.10.3
v3.10.2
v3.10.1
v3.10.0
v3.9.1
v3.9.0
v3.8.0
v3.7.3
v3.7.2
v3.7.1
v3.7.0
v3.6.1
v3.6.0
v3.5.0
v3.4.0
v3.3.0
v3.2.0
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
361 additions
and
0 deletions
+361
-0
include/nlohmann/detail/input/binary_reader.hpp
include/nlohmann/detail/input/binary_reader.hpp
+2
-0
include/nlohmann/detail/input/parser.hpp
include/nlohmann/detail/input/parser.hpp
+2
-0
include/nlohmann/detail/meta/is_sax.hpp
include/nlohmann/detail/meta/is_sax.hpp
+141
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+216
-0
No files found.
include/nlohmann/detail/input/binary_reader.hpp
View file @
0cc3db4f
...
...
@@ -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
...
...
@@ -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
);
}
...
...
This diff is collapsed.
Click to expand it.
include/nlohmann/detail/input/parser.hpp
View file @
0cc3db4f
...
...
@@ -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>
...
...
@@ -145,6 +146,7 @@ class parser
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
...
...
This diff is collapsed.
Click to expand it.
include/nlohmann/detail/meta/is_sax.hpp
0 → 100644
View file @
0cc3db4f
#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&)"
);
};
}
}
This diff is collapsed.
Click to expand it.
single_include/nlohmann/json.hpp
View file @
0cc3db4f
...
...
@@ -3557,6 +3557,218 @@ scan_number_done:
// #include <nlohmann/detail/macro_scope.hpp>
// #include <nlohmann/detail/meta/is_sax.hpp>
#include <cstdint> // size_t
#include <utility> // declval
// #include <nlohmann/detail/meta/detected.hpp>
#include <type_traits>
// #include <nlohmann/detail/meta/void_t.hpp>
namespace
nlohmann
{
namespace
detail
{
template
<
typename
...
>
using
void_t
=
void
;
}
}
// 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/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/input/input_adapters.hpp>
// #include <nlohmann/detail/input/json_sax.hpp>
...
...
@@ -4383,6 +4595,7 @@ class parser
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
...
...
@@ -5757,6 +5970,8 @@ class output_adapter
// #include <nlohmann/detail/macro_scope.hpp>
// #include <nlohmann/detail/meta/is_sax.hpp>
// #include <nlohmann/detail/value_t.hpp>
...
...
@@ -5788,6 +6003,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
);
}
...
...
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