Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
907484fb
Commit
907484fb
authored
Nov 24, 2016
by
Théo DELRIEU
Committed by
Théo DELRIEU
Jan 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format biggest lines
parent
47bc4021
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
74 deletions
+119
-74
json.hpp
src/json.hpp
+119
-74
No files found.
src/json.hpp
View file @
907484fb
...
@@ -183,19 +183,20 @@ template <class RealType, class CompatibleObjectType>
...
@@ -183,19 +183,20 @@ template <class RealType, class CompatibleObjectType>
struct
is_compatible_object_type_impl
<
true
,
RealType
,
CompatibleObjectType
>
struct
is_compatible_object_type_impl
<
true
,
RealType
,
CompatibleObjectType
>
{
{
static
constexpr
auto
value
=
static
constexpr
auto
value
=
std
::
is_constructible
<
typename
RealType
::
key_type
,
typename
CompatibleObjectType
::
key_type
>::
value
and
std
::
is_constructible
<
typename
RealType
::
key_type
,
std
::
is_constructible
<
typename
RealType
::
mapped_type
,
typename
CompatibleObjectType
::
mapped_type
>::
value
;
typename
CompatibleObjectType
::
key_type
>::
value
and
std
::
is_constructible
<
typename
RealType
::
mapped_type
,
typename
CompatibleObjectType
::
mapped_type
>::
value
;
};
};
template
<
class
RealType
,
class
CompatibleObjectType
>
template
<
class
RealType
,
class
CompatibleObjectType
>
struct
is_compatible_object_type
struct
is_compatible_object_type
{
{
static
auto
constexpr
value
=
is_compatible_object_type_impl
<
static
auto
constexpr
value
=
is_compatible_object_type_impl
<
conjunction
<
negation
<
std
::
is_same
<
void
,
CompatibleObjectType
>>
,
conjunction
<
negation
<
std
::
is_same
<
void
,
CompatibleObjectType
>>
,
has_mapped_type
<
CompatibleObjectType
>
,
has_mapped_type
<
CompatibleObjectType
>
,
has_key_type
<
CompatibleObjectType
>>::
value
,
has_key_type
<
CompatibleObjectType
>>::
value
,
RealType
,
CompatibleObjectType
>::
value
;
RealType
,
CompatibleObjectType
>::
value
;
};
};
template
<
bool
B
,
class
BasicJson
,
class
CompatibleArrayType
>
template
<
bool
B
,
class
BasicJson
,
class
CompatibleArrayType
>
...
@@ -205,28 +206,34 @@ template <class BasicJson, class CompatibleArrayType>
...
@@ -205,28 +206,34 @@ template <class BasicJson, class CompatibleArrayType>
struct
is_compatible_array_type_impl
<
true
,
BasicJson
,
CompatibleArrayType
>
struct
is_compatible_array_type_impl
<
true
,
BasicJson
,
CompatibleArrayType
>
{
{
static
constexpr
auto
value
=
static
constexpr
auto
value
=
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJson
::
iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJson
::
const_iterator
>::
value
and
typename
BasicJson
::
iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJson
::
reverse_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJson
::
const_reverse_iterator
>::
value
and
typename
BasicJson
::
const_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJson
::
array_t
::
iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJson
::
array_t
::
const_iterator
>::
value
;
typename
BasicJson
::
reverse_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJson
::
const_reverse_iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJson
::
array_t
::
iterator
>::
value
and
not
std
::
is_same
<
CompatibleArrayType
,
typename
BasicJson
::
array_t
::
const_iterator
>::
value
;
};
};
template
<
class
BasicJson
,
class
CompatibleArrayType
>
template
<
class
BasicJson
,
class
CompatibleArrayType
>
struct
is_compatible_array_type
struct
is_compatible_array_type
{
{
static
auto
constexpr
value
=
disjunction
<
std
::
is_same
<
BasicJson
,
CompatibleArrayType
>
,
static
auto
constexpr
value
=
disjunction
<
is_compatible_array_type_impl
<
std
::
is_same
<
BasicJson
,
CompatibleArrayType
>
,
conjunction
<
negation
<
is_compatible_array_type_impl
<
// MSVC has troubles on that one
conjunction
<
negation
<
std
::
is_same
<
void
,
CompatibleArrayType
>>
,
// MSVC has troubles without this
negation
<
is_compatible_object_type
<
std
::
is_same
<
void
,
CompatibleArrayType
>>
,
typename
BasicJson
::
object_t
,
CompatibleArrayType
>>
,
negation
<
is_compatible_object_type
<
has_value_type
<
CompatibleArrayType
>
,
typename
BasicJson
::
object_t
,
CompatibleArrayType
>>
,
has_iterator
<
CompatibleArrayType
>>::
value
,
has_value_type
<
CompatibleArrayType
>
,
BasicJson
,
CompatibleArrayType
>>::
value
;
has_iterator
<
CompatibleArrayType
>>::
value
,
BasicJson
,
CompatibleArrayType
>>::
value
;
};
};
template
<
bool
,
typename
,
typename
>
template
<
bool
,
typename
,
typename
>
...
@@ -235,15 +242,19 @@ struct is_compatible_integer_type_impl : std::false_type{};
...
@@ -235,15 +242,19 @@ struct is_compatible_integer_type_impl : std::false_type{};
template
<
typename
RealIntegerType
,
typename
CompatibleNumberIntegerType
>
template
<
typename
RealIntegerType
,
typename
CompatibleNumberIntegerType
>
struct
is_compatible_integer_type_impl
<
true
,
RealIntegerType
,
CompatibleNumberIntegerType
>
struct
is_compatible_integer_type_impl
<
true
,
RealIntegerType
,
CompatibleNumberIntegerType
>
{
{
static
constexpr
auto
value
=
std
::
is_constructible
<
RealIntegerType
,
CompatibleNumberIntegerType
>::
value
and
static
constexpr
auto
value
=
std
::
numeric_limits
<
CompatibleNumberIntegerType
>::
is_integer
and
std
::
is_constructible
<
RealIntegerType
,
std
::
numeric_limits
<
CompatibleNumberIntegerType
>::
is_signed
;
CompatibleNumberIntegerType
>::
value
and
std
::
numeric_limits
<
CompatibleNumberIntegerType
>::
is_integer
and
std
::
numeric_limits
<
CompatibleNumberIntegerType
>::
is_signed
;
};
};
template
<
typename
RealIntegerType
,
typename
CompatibleNumberIntegerType
>
template
<
typename
RealIntegerType
,
typename
CompatibleNumberIntegerType
>
struct
is_compatible_integer_type
struct
is_compatible_integer_type
{
{
static
constexpr
auto
value
=
is_compatible_integer_type_impl
<
std
::
is_arithmetic
<
CompatibleNumberIntegerType
>::
value
,
RealIntegerType
,
CompatibleNumberIntegerType
>::
value
;
static
constexpr
auto
value
=
is_compatible_integer_type_impl
<
std
::
is_arithmetic
<
CompatibleNumberIntegerType
>::
value
,
RealIntegerType
,
CompatibleNumberIntegerType
>::
value
;
};
};
template
<
bool
,
typename
,
typename
>
template
<
bool
,
typename
,
typename
>
...
@@ -252,37 +263,43 @@ struct is_compatible_unsigned_integer_type_impl : std::false_type{};
...
@@ -252,37 +263,43 @@ struct is_compatible_unsigned_integer_type_impl : std::false_type{};
template
<
typename
RealUnsignedType
,
typename
CompatibleNumberUnsignedType
>
template
<
typename
RealUnsignedType
,
typename
CompatibleNumberUnsignedType
>
struct
is_compatible_unsigned_integer_type_impl
<
true
,
RealUnsignedType
,
CompatibleNumberUnsignedType
>
struct
is_compatible_unsigned_integer_type_impl
<
true
,
RealUnsignedType
,
CompatibleNumberUnsignedType
>
{
{
static
constexpr
auto
value
=
std
::
is_constructible
<
RealUnsignedType
,
CompatibleNumberUnsignedType
>::
value
and
static
constexpr
auto
value
=
std
::
numeric_limits
<
CompatibleNumberUnsignedType
>::
is_integer
and
std
::
is_constructible
<
RealUnsignedType
,
not
std
::
numeric_limits
<
CompatibleNumberUnsignedType
>::
is_signed
;
CompatibleNumberUnsignedType
>::
value
and
std
::
numeric_limits
<
CompatibleNumberUnsignedType
>::
is_integer
and
not
std
::
numeric_limits
<
CompatibleNumberUnsignedType
>::
is_signed
;
};
};
template
<
typename
RealUnsignedType
,
typename
CompatibleNumberUnsignedType
>
template
<
typename
RealUnsignedType
,
typename
CompatibleNumberUnsignedType
>
struct
is_compatible_unsigned_integer_type
struct
is_compatible_unsigned_integer_type
{
{
static
constexpr
auto
value
=
is_compatible_unsigned_integer_type_impl
<
std
::
is_arithmetic
<
CompatibleNumberUnsignedType
>::
value
,
RealUnsignedType
,
CompatibleNumberUnsignedType
>::
value
;
static
constexpr
auto
value
=
is_compatible_unsigned_integer_type_impl
<
std
::
is_arithmetic
<
CompatibleNumberUnsignedType
>::
value
,
RealUnsignedType
,
CompatibleNumberUnsignedType
>::
value
;
};
};
template
<
typename
RealFloat
,
typename
CompatibleFloat
>
template
<
typename
RealFloat
,
typename
CompatibleFloat
>
struct
is_compatible_float_type
struct
is_compatible_float_type
{
{
static
constexpr
auto
value
=
std
::
is_constructible
<
RealFloat
,
CompatibleFloat
>::
value
and
static
constexpr
auto
value
=
std
::
is_floating_point
<
CompatibleFloat
>::
value
;
std
::
is_constructible
<
RealFloat
,
CompatibleFloat
>::
value
and
std
::
is_floating_point
<
CompatibleFloat
>::
value
;
};
};
template
<
typename
T
,
typename
BasicJson
>
template
<
typename
T
,
typename
BasicJson
>
struct
is_compatible_basic_json_type
struct
is_compatible_basic_json_type
{
{
static
auto
constexpr
value
=
static
auto
constexpr
value
=
std
::
is_same
<
T
,
BasicJson
>::
value
or
std
::
is_same
<
T
,
BasicJson
>::
value
or
std
::
is_constructible
<
typename
BasicJson
::
string_t
,
T
>::
value
or
std
::
is_constructible
<
typename
BasicJson
::
string_t
,
T
>::
value
or
std
::
is_same
<
typename
BasicJson
::
boolean_t
,
T
>::
value
or
std
::
is_same
<
typename
BasicJson
::
boolean_t
,
T
>::
value
or
is_compatible_array_type
<
BasicJson
,
T
>::
value
or
is_compatible_array_type
<
BasicJson
,
T
>::
value
or
is_compatible_object_type
<
typename
BasicJson
::
object_t
,
T
>::
value
or
is_compatible_object_type
<
typename
BasicJson
::
object_t
,
T
>::
value
or
is_compatible_float_type
<
typename
BasicJson
::
number_float_t
,
T
>::
value
or
is_compatible_float_type
<
typename
BasicJson
::
number_float_t
,
T
>::
value
or
is_compatible_integer_type
<
typename
BasicJson
::
number_integer_t
,
is_compatible_integer_type
<
typename
BasicJson
::
number_integer_t
,
T
>::
value
or
T
>::
value
or
is_compatible_unsigned_integer_type
<
typename
BasicJson
::
number_unsigned_t
,
T
>::
value
;
is_compatible_unsigned_integer_type
<
typename
BasicJson
::
number_unsigned_t
,
T
>::
value
;
};
};
template
<
template
<
typename
,
typename
>
class
JSONSerializer
,
typename
Json
,
template
<
template
<
typename
,
typename
>
class
JSONSerializer
,
typename
Json
,
...
@@ -322,23 +339,24 @@ void from_json();
...
@@ -322,23 +339,24 @@ void from_json();
struct
to_json_fn
struct
to_json_fn
{
{
template
<
typename
Json
,
typename
T
>
template
<
typename
Json
,
typename
T
>
constexpr
auto
constexpr
auto
operator
()(
Json
&&
j
,
T
&&
val
)
const
operator
()(
Json
&&
j
,
T
&&
val
)
const
noexcept
(
noexcept
(
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
))))
noexcept
(
noexcept
(
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
))))
->
decltype
(
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
)),
void
())
->
decltype
(
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
)),
{
void
())
return
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
));
{
}
return
to_json
(
std
::
forward
<
Json
>
(
j
),
std
::
forward
<
T
>
(
val
));
}
};
};
struct
from_json_fn
struct
from_json_fn
{
{
template
<
typename
Json
,
typename
T
>
template
<
typename
Json
,
typename
T
>
constexpr
auto
operator
()(
Json
&&
j
,
T
&
val
)
const
constexpr
auto
operator
()(
Json
&&
j
,
T
&
val
)
const
noexcept
(
noexcept
(
from_json
(
std
::
forward
<
Json
>
(
j
),
val
)))
noexcept
(
noexcept
(
from_json
(
std
::
forward
<
Json
>
(
j
),
val
)))
->
decltype
(
from_json
(
std
::
forward
<
Json
>
(
j
),
val
),
void
())
->
decltype
(
from_json
(
std
::
forward
<
Json
>
(
j
),
val
),
void
())
{
{
return
from_json
(
std
::
forward
<
Json
>
(
j
),
val
);
return
from_json
(
std
::
forward
<
Json
>
(
j
),
val
);
}
}
};
};
...
@@ -1555,10 +1573,17 @@ class basic_json
...
@@ -1555,10 +1573,17 @@ class basic_json
// constructor chosen when JSONSerializer::to_json exists for type T
// constructor chosen when JSONSerializer::to_json exists for type T
// first check avoids being chosen instead of move/copy constructor
// first check avoids being chosen instead of move/copy constructor
template
<
typename
T
,
enable_if_t
<
detail
::
conjunction
<
detail
::
negation
<
std
::
is_same
<
uncvref_t
<
T
>
,
basic_json_t
>>
,
template
<
detail
::
negation
<
std
::
is_base_of
<
std
::
istream
,
uncvref_t
<
T
>>>
,
typename
T
,
detail
::
negation
<
detail
::
is_compatible_basic_json_type
<
uncvref_t
<
T
>
,
basic_json_t
>>
,
detail
::
has_to_json
<
enable_if_t
<
JSONSerializer
,
basic_json
,
uncvref_t
<
T
>>>::
value
,
int
>
=
0
>
detail
::
conjunction
<
detail
::
negation
<
std
::
is_same
<
uncvref_t
<
T
>
,
basic_json_t
>>
,
detail
::
negation
<
std
::
is_base_of
<
std
::
istream
,
uncvref_t
<
T
>>>
,
detail
::
negation
<
detail
::
is_compatible_basic_json_type
<
uncvref_t
<
T
>
,
basic_json_t
>>
,
detail
::
has_to_json
<
JSONSerializer
,
basic_json
,
uncvref_t
<
T
>>>::
value
,
int
>
=
0
>
explicit
basic_json
(
T
&&
val
)
explicit
basic_json
(
T
&&
val
)
{
{
JSONSerializer
<
uncvref_t
<
T
>>::
to_json
(
*
this
,
std
::
forward
<
T
>
(
val
));
JSONSerializer
<
uncvref_t
<
T
>>::
to_json
(
*
this
,
std
::
forward
<
T
>
(
val
));
...
@@ -1757,7 +1782,11 @@ detail::negation<detail::is_compatible_basic_json_type<uncvref_t<T>, basic_json_
...
@@ -1757,7 +1782,11 @@ detail::negation<detail::is_compatible_basic_json_type<uncvref_t<T>, basic_json_
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
typename
CompatibleNumberIntegerType
,
enable_if_t
<
detail
::
is_compatible_integer_type
<
number_integer_t
,
CompatibleNumberIntegerType
>::
value
,
int
>
=
0
>
template
<
typename
CompatibleNumberIntegerType
,
enable_if_t
<
detail
::
is_compatible_integer_type
<
number_integer_t
,
CompatibleNumberIntegerType
>::
value
,
int
>
=
0
>
basic_json
(
const
CompatibleNumberIntegerType
val
)
noexcept
basic_json
(
const
CompatibleNumberIntegerType
val
)
noexcept
:
m_type
(
value_t
::
number_integer
),
:
m_type
(
value_t
::
number_integer
),
m_value
(
static_cast
<
number_integer_t
>
(
val
))
m_value
(
static_cast
<
number_integer_t
>
(
val
))
...
@@ -1811,7 +1840,11 @@ detail::negation<detail::is_compatible_basic_json_type<uncvref_t<T>, basic_json_
...
@@ -1811,7 +1840,11 @@ detail::negation<detail::is_compatible_basic_json_type<uncvref_t<T>, basic_json_
@since version 2.0.0
@since version 2.0.0
*/
*/
template
<
typename
CompatibleNumberUnsignedType
,
enable_if_t
<
detail
::
is_compatible_unsigned_integer_type
<
number_unsigned_t
,
CompatibleNumberUnsignedType
>::
value
,
int
>
=
0
>
template
<
typename
CompatibleNumberUnsignedType
,
enable_if_t
<
detail
::
is_compatible_unsigned_integer_type
<
number_unsigned_t
,
CompatibleNumberUnsignedType
>::
value
,
int
>
=
0
>
basic_json
(
const
CompatibleNumberUnsignedType
val
)
noexcept
basic_json
(
const
CompatibleNumberUnsignedType
val
)
noexcept
:
m_type
(
value_t
::
number_unsigned
),
:
m_type
(
value_t
::
number_unsigned
),
m_value
(
static_cast
<
number_unsigned_t
>
(
val
))
m_value
(
static_cast
<
number_unsigned_t
>
(
val
))
...
@@ -1887,7 +1920,10 @@ detail::negation<detail::is_compatible_basic_json_type<uncvref_t<T>, basic_json_
...
@@ -1887,7 +1920,10 @@ detail::negation<detail::is_compatible_basic_json_type<uncvref_t<T>, basic_json_
@since version 1.0.0
@since version 1.0.0
*/
*/
template
<
typename
CompatibleNumberFloatType
,
enable_if_t
<
detail
::
is_compatible_float_type
<
number_float_t
,
CompatibleNumberFloatType
>::
value
,
int
>
=
0
>
template
<
typename
CompatibleNumberFloatType
,
enable_if_t
<
detail
::
is_compatible_float_type
<
number_float_t
,
CompatibleNumberFloatType
>::
value
,
int
>
=
0
>
basic_json
(
const
CompatibleNumberFloatType
val
)
noexcept
basic_json
(
const
CompatibleNumberFloatType
val
)
noexcept
:
basic_json
(
number_float_t
(
val
))
:
basic_json
(
number_float_t
(
val
))
{
{
...
@@ -2941,13 +2977,17 @@ detail::negation<detail::is_compatible_basic_json_type<uncvref_t<T>, basic_json_
...
@@ -2941,13 +2977,17 @@ detail::negation<detail::is_compatible_basic_json_type<uncvref_t<T>, basic_json_
}
}
/// get an array (explicit)
/// get an array (explicit)
template
<
class
T
,
typename
std
::
enable_if
<
template
<
std
::
is_convertible
<
basic_json_t
,
typename
T
::
value_type
>::
value
and
class
T
,
not
std
::
is_same
<
basic_json_t
,
typename
T
::
value_type
>::
value
and
typename
std
::
enable_if
<
not
std
::
is_arithmetic
<
T
>::
value
and
std
::
is_convertible
<
basic_json_t
,
typename
T
::
value_type
>::
value
and
not
std
::
is_convertible
<
std
::
string
,
T
>::
value
and
not
std
::
is_same
<
basic_json_t
,
not
detail
::
has_mapped_type
<
T
>::
value
,
int
>::
type
=
0
>
typename
T
::
value_type
>::
value
and
T
get_impl
(
T
*
/*unused*/
)
const
not
std
::
is_arithmetic
<
T
>::
value
and
not
std
::
is_convertible
<
std
::
string
,
T
>::
value
and
not
detail
::
has_mapped_type
<
T
>::
value
,
int
>::
type
=
0
>
T
get_impl
(
T
*
)
const
{
{
if
(
is_array
())
if
(
is_array
())
{
{
...
@@ -3225,9 +3265,14 @@ detail::negation<detail::is_compatible_basic_json_type<uncvref_t<T>, basic_json_
...
@@ -3225,9 +3265,14 @@ detail::negation<detail::is_compatible_basic_json_type<uncvref_t<T>, basic_json_
return
get_impl
(
static_cast
<
ValueType
*>
(
nullptr
));
return
get_impl
(
static_cast
<
ValueType
*>
(
nullptr
));
}
}
template
<
typename
T
,
template
<
enable_if_t
<
detail
::
conjunction
<
detail
::
negation
<
detail
::
is_compatible_basic_json_type
<
uncvref_t
<
T
>
,
basic_json_t
>>
,
typename
T
,
detail
::
has_from_json
<
JSONSerializer
,
basic_json_t
,
uncvref_t
<
T
>>>::
value
,
int
>
=
0
>
enable_if_t
<
detail
::
conjunction
<
detail
::
negation
<
detail
::
is_compatible_basic_json_type
<
uncvref_t
<
T
>
,
basic_json_t
>>
,
detail
::
has_from_json
<
JSONSerializer
,
basic_json_t
,
uncvref_t
<
T
>>>::
value
,
int
>
=
0
>
auto
get
()
const
->
uncvref_t
<
T
>
auto
get
()
const
->
uncvref_t
<
T
>
{
{
using
type
=
uncvref_t
<
T
>
;
using
type
=
uncvref_t
<
T
>
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment