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
cb3d455b
Commit
cb3d455b
authored
Jan 09, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
do not const_cast when calling get_ptr
parent
3494014b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
json.hpp
src/json.hpp
+11
-11
No files found.
src/json.hpp
View file @
cb3d455b
...
@@ -494,11 +494,11 @@ template <typename Json, typename ArithmeticType,
...
@@ -494,11 +494,11 @@ template <typename Json, typename ArithmeticType,
void
get_arithmetic_value
(
Json
const
&
j
,
ArithmeticType
&
val
)
void
get_arithmetic_value
(
Json
const
&
j
,
ArithmeticType
&
val
)
{
{
if
(
j
.
is_number_integer
())
if
(
j
.
is_number_integer
())
val
=
*
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
number_integer_t
*>
();
val
=
*
j
.
template
get_ptr
<
const
typename
Json
::
number_integer_t
*>
();
else
if
(
j
.
is_number_unsigned
())
else
if
(
j
.
is_number_unsigned
())
val
=
*
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
number_unsigned_t
*>
();
val
=
*
j
.
template
get_ptr
<
const
typename
Json
::
number_unsigned_t
*>
();
else
if
(
j
.
is_number_float
())
else
if
(
j
.
is_number_float
())
val
=
*
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
number_float_t
*>
();
val
=
*
j
.
template
get_ptr
<
const
typename
Json
::
number_float_t
*>
();
else
else
throw
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
));
throw
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
));
}
}
...
@@ -578,7 +578,7 @@ void from_json(Json const& j, typename Json::boolean_t& b)
...
@@ -578,7 +578,7 @@ void from_json(Json const& j, typename Json::boolean_t& b)
{
{
if
(
!
j
.
is_boolean
())
if
(
!
j
.
is_boolean
())
throw
std
::
domain_error
(
"type must be boolean, but is "
+
type_name
(
j
));
throw
std
::
domain_error
(
"type must be boolean, but is "
+
type_name
(
j
));
b
=
*
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
boolean_t
*>
();
b
=
*
j
.
template
get_ptr
<
const
typename
Json
::
boolean_t
*>
();
}
}
template
<
typename
Json
>
template
<
typename
Json
>
...
@@ -586,7 +586,7 @@ void from_json(Json const& j, typename Json::string_t& s)
...
@@ -586,7 +586,7 @@ void from_json(Json const& j, typename Json::string_t& s)
{
{
if
(
!
j
.
is_string
())
if
(
!
j
.
is_string
())
throw
std
::
domain_error
(
"type must be string, but is "
+
type_name
(
j
));
throw
std
::
domain_error
(
"type must be string, but is "
+
type_name
(
j
));
s
=
*
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
string_t
*>
();
s
=
*
j
.
template
get_ptr
<
const
typename
Json
::
string_t
*>
();
}
}
template
<
typename
Json
>
template
<
typename
Json
>
...
@@ -621,7 +621,7 @@ void from_json(Json const &j, typename Json::array_t &arr)
...
@@ -621,7 +621,7 @@ void from_json(Json const &j, typename Json::array_t &arr)
{
{
if
(
!
j
.
is_array
())
if
(
!
j
.
is_array
())
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
(
j
));
throw
std
::
domain_error
(
"type must be array, but is "
+
type_name
(
j
));
arr
=
*
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
array_t
*>
();
arr
=
*
j
.
template
get_ptr
<
const
typename
Json
::
array_t
*>
();
}
}
// forward_list doesn't have an insert method, TODO find a way to avoid including forward_list
// forward_list doesn't have an insert method, TODO find a way to avoid including forward_list
...
@@ -679,7 +679,7 @@ void from_json(Json const &j, CompatibleObjectType &obj)
...
@@ -679,7 +679,7 @@ void from_json(Json const &j, CompatibleObjectType &obj)
if
(
!
j
.
is_object
())
if
(
!
j
.
is_object
())
throw
std
::
domain_error
(
"type must be object, but is "
+
type_name
(
j
));
throw
std
::
domain_error
(
"type must be object, but is "
+
type_name
(
j
));
auto
inner_object
=
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
object_t
*>
();
auto
inner_object
=
j
.
template
get_ptr
<
const
typename
Json
::
object_t
*>
();
using
std
::
begin
;
using
std
::
begin
;
using
std
::
end
;
using
std
::
end
;
// we could avoid the assignment, but this might require a for loop, which
// we could avoid the assignment, but this might require a for loop, which
...
@@ -703,13 +703,13 @@ template <
...
@@ -703,13 +703,13 @@ template <
void
from_json
(
Json
const
&
j
,
ArithmeticType
&
val
)
void
from_json
(
Json
const
&
j
,
ArithmeticType
&
val
)
{
{
if
(
j
.
is_number_integer
())
if
(
j
.
is_number_integer
())
val
=
*
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
number_integer_t
*>
();
val
=
*
j
.
template
get_ptr
<
const
typename
Json
::
number_integer_t
*>
();
else
if
(
j
.
is_number_unsigned
())
else
if
(
j
.
is_number_unsigned
())
val
=
*
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
number_unsigned_t
*>
();
val
=
*
j
.
template
get_ptr
<
const
typename
Json
::
number_unsigned_t
*>
();
else
if
(
j
.
is_number_float
())
else
if
(
j
.
is_number_float
())
val
=
*
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
number_float_t
*>
();
val
=
*
j
.
template
get_ptr
<
const
typename
Json
::
number_float_t
*>
();
else
if
(
j
.
is_boolean
())
else
if
(
j
.
is_boolean
())
val
=
*
const_cast
<
Json
&>
(
j
).
template
get_ptr
<
typename
Json
::
boolean_t
*>
();
val
=
*
j
.
template
get_ptr
<
const
typename
Json
::
boolean_t
*>
();
else
else
throw
std
::
domain_error
(
"type must be number, but is "
+
type_name
(
j
));
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