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
d566bb81
Commit
d566bb81
authored
Jan 20, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use switchs where appropriate
parent
1e20887c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
78 deletions
+90
-78
src/json.hpp
src/json.hpp
+45
-39
src/json.hpp.re2c
src/json.hpp.re2c
+45
-39
No files found.
src/json.hpp
View file @
d566bb81
...
...
@@ -498,22 +498,23 @@ template <typename Json, typename ArithmeticType,
int
>
=
0
>
void
get_arithmetic_value
(
const
Json
&
j
,
ArithmeticType
&
val
)
{
// unsigned must be checked first, since is_number_integer() == true for unsigned
if
(
j
.
is_number_unsigned
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_unsigned_t
*
>());
}
else
if
(
j
.
is_number_integer
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_integer_t
*
>());
}
else
if
(
j
.
is_number_float
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_float_t
*
>());
}
else
{
JSON_THROW
(
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
)));
switch
(
static_cast
<
value_t
>
(
j
))
{
case
value_t
:
:
number_unsigned
:
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_unsigned_t
*
>());
break
;
case
value_t
:
:
number_integer
:
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_integer_t
*
>());
break
;
case
value_t
:
:
number_float
:
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_float_t
*
>());
break
;
default:
JSON_THROW
(
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
)));
}
}
...
...
@@ -752,32 +753,37 @@ template <
typename
Json
,
typename
ArithmeticType
,
enable_if_t
<
std
::
is_arithmetic
<
ArithmeticType
>
::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
number_unsigned_t
>::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
number_integer_t
>::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
number_float_t
>::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
number_unsigned_t
>::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
number_integer_t
>::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
number_float_t
>::
value
and
not
std
::
is_same
<
ArithmeticType
,
typename
Json
::
boolean_t
>::
value
,
int
>
=
0
>
void
from_json
(
const
Json
&
j
,
ArithmeticType
&
val
)
void
from_json
(
const
Json
&
j
,
ArithmeticType
&
val
)
{
if
(
j
.
is_number_unsigned
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_unsigned_t
*
>());
}
else
if
(
j
.
is_number_integer
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_integer_t
*
>());
}
else
if
(
j
.
is_number_float
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_float_t
*
>());
}
else
if
(
j
.
is_boolean
())
{
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
boolean_t
*
>());
}
else
{
JSON_THROW
(
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
)));
switch
(
static_cast
<
value_t
>
(
j
))
{
case
value_t
:
:
number_unsigned
:
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_unsigned_t
*
>());
break
;
case
value_t
:
:
number_integer
:
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_integer_t
*
>());
break
;
case
value_t
:
:
number_float
:
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
number_float_t
*
>());
break
;
case
value_t
:
:
boolean
:
val
=
static_cast
<
ArithmeticType
>
(
*
j
.
template
get_ptr
<
const
typename
Json
::
boolean_t
*
>());
break
;
default:
JSON_THROW
(
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
)));
}
}
...
...
src/json.hpp.re2c
View file @
d566bb81
...
...
@@ -498,22 +498,23 @@ template <typename Json, typename ArithmeticType,
int> = 0>
void get_arithmetic_value(const Json& j, ArithmeticType& val)
{
// unsigned must be checked first, since is_number_integer() == true for unsigned
if (j.is_number_unsigned())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>());
}
else if (j.is_number_integer())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>());
}
else if (j.is_number_float())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>());
}
else
{
JSON_THROW(std::domain_error("type must be number, but is " + type_name(j)));
switch (static_cast<value_t>(j))
{
case value_t::number_unsigned:
val = static_cast<ArithmeticType>(
*j.template get_ptr<const typename Json::number_unsigned_t*>());
break;
case value_t::number_integer:
val = static_cast<ArithmeticType>(
*j.template get_ptr<const typename Json::number_integer_t*>());
break;
case value_t::number_float:
val = static_cast<ArithmeticType>(
*j.template get_ptr<const typename Json::number_float_t*>());
break;
default:
JSON_THROW(
std::domain_error("type must be number, but is " + type_name(j)));
}
}
...
...
@@ -752,32 +753,37 @@ template <
typename Json, typename ArithmeticType,
enable_if_t <
std::is_arithmetic<ArithmeticType>::value and
not std::is_same<ArithmeticType, typename Json::number_unsigned_t>::value and
not std::is_same<ArithmeticType, typename Json::number_integer_t>::value and
not std::is_same<ArithmeticType, typename Json::number_float_t>::value and
not std::is_same<ArithmeticType,
typename Json::number_unsigned_t>::value and
not std::is_same<ArithmeticType,
typename Json::number_integer_t>::value and
not std::is_same<ArithmeticType,
typename Json::number_float_t>::value and
not std::is_same<ArithmeticType, typename Json::boolean_t>::value,
int > = 0 >
void from_json(const
Json& j, ArithmeticType& val)
void from_json(const Json& j, ArithmeticType& val)
{
if (j.is_number_unsigned())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_unsigned_t*>());
}
else if (j.is_number_integer())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_integer_t*>());
}
else if (j.is_number_float())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::number_float_t*>());
}
else if (j.is_boolean())
{
val = static_cast<ArithmeticType>(*j.template get_ptr<const typename Json::boolean_t*>());
}
else
{
JSON_THROW(std::domain_error("type must be number, but is " + type_name(j)));
switch (static_cast<value_t>(j))
{
case value_t::number_unsigned:
val = static_cast<ArithmeticType>(
*j.template get_ptr<const typename Json::number_unsigned_t*>());
break;
case value_t::number_integer:
val = static_cast<ArithmeticType>(
*j.template get_ptr<const typename Json::number_integer_t*>());
break;
case value_t::number_float:
val = static_cast<ArithmeticType>(
*j.template get_ptr<const typename Json::number_float_t*>());
break;
case value_t::boolean:
val = static_cast<ArithmeticType>(
*j.template get_ptr<const typename Json::boolean_t*>());
break;
default:
JSON_THROW(
std::domain_error("type must be number, but is " + type_name(j)));
}
}
...
...
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