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
e6e6805c
Unverified
Commit
e6e6805c
authored
Apr 01, 2019
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add built-in array support in get_to
parent
2806b201
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
0 deletions
+56
-0
include/nlohmann/detail/conversions/from_json.hpp
include/nlohmann/detail/conversions/from_json.hpp
+10
-0
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+13
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+23
-0
test/src/unit-conversions.cpp
test/src/unit-conversions.cpp
+10
-0
No files found.
include/nlohmann/detail/conversions/from_json.hpp
View file @
e6e6805c
...
@@ -157,6 +157,16 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
...
@@ -157,6 +157,16 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
std
::
copy
(
j
.
m_value
.
array
->
begin
(),
j
.
m_value
.
array
->
end
(),
std
::
begin
(
l
));
std
::
copy
(
j
.
m_value
.
array
->
begin
(),
j
.
m_value
.
array
->
end
(),
std
::
begin
(
l
));
}
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
>
auto
from_json
(
const
BasicJsonType
&
j
,
T
(
&
arr
)[
N
])
->
decltype
(
j
.
template
get
<
T
>(),
void
())
{
for
(
std
::
size_t
i
=
0
;
i
<
N
;
++
i
)
{
arr
[
i
]
=
j
.
at
(
i
).
template
get
<
T
>();
}
}
template
<
typename
BasicJsonType
>
template
<
typename
BasicJsonType
>
void
from_json_array_impl
(
const
BasicJsonType
&
j
,
typename
BasicJsonType
::
array_t
&
arr
,
priority_tag
<
3
>
/*unused*/
)
void
from_json_array_impl
(
const
BasicJsonType
&
j
,
typename
BasicJsonType
::
array_t
&
arr
,
priority_tag
<
3
>
/*unused*/
)
{
{
...
...
include/nlohmann/json.hpp
View file @
e6e6805c
...
@@ -2684,6 +2684,19 @@ class basic_json
...
@@ -2684,6 +2684,19 @@ class basic_json
return
v
;
return
v
;
}
}
template
<
typename
T
,
std
::
size_t
N
,
typename
Array
=
T
(
&
)[
N
],
detail
::
enable_if_t
<
detail
::
has_from_json
<
basic_json_t
,
Array
>
::
value
,
int
>
=
0
>
Array
get_to
(
T
(
&
v
)[
N
])
const
noexcept
(
noexcept
(
JSONSerializer
<
Array
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
v
)))
{
JSONSerializer
<
Array
>::
from_json
(
*
this
,
v
);
return
v
;
}
/*!
/*!
@brief get a pointer value (implicit)
@brief get a pointer value (implicit)
...
...
single_include/nlohmann/json.hpp
View file @
e6e6805c
...
@@ -1445,6 +1445,16 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
...
@@ -1445,6 +1445,16 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
std
::
copy
(
j
.
m_value
.
array
->
begin
(),
j
.
m_value
.
array
->
end
(),
std
::
begin
(
l
));
std
::
copy
(
j
.
m_value
.
array
->
begin
(),
j
.
m_value
.
array
->
end
(),
std
::
begin
(
l
));
}
}
template
<
typename
BasicJsonType
,
typename
T
,
std
::
size_t
N
>
auto
from_json
(
const
BasicJsonType
&
j
,
T
(
&
arr
)[
N
])
->
decltype
(
j
.
template
get
<
T
>(),
void
())
{
for
(
std
::
size_t
i
=
0
;
i
<
N
;
++
i
)
{
arr
[
i
]
=
j
.
at
(
i
).
template
get
<
T
>();
}
}
template
<
typename
BasicJsonType
>
template
<
typename
BasicJsonType
>
void
from_json_array_impl
(
const
BasicJsonType
&
j
,
typename
BasicJsonType
::
array_t
&
arr
,
priority_tag
<
3
>
/*unused*/
)
void
from_json_array_impl
(
const
BasicJsonType
&
j
,
typename
BasicJsonType
::
array_t
&
arr
,
priority_tag
<
3
>
/*unused*/
)
{
{
...
@@ -15475,6 +15485,19 @@ class basic_json
...
@@ -15475,6 +15485,19 @@ class basic_json
return
v
;
return
v
;
}
}
template
<
typename
T
,
std
::
size_t
N
,
typename
Array
=
T
(
&
)[
N
],
detail
::
enable_if_t
<
detail
::
has_from_json
<
basic_json_t
,
Array
>
::
value
,
int
>
=
0
>
Array
get_to
(
T
(
&
v
)[
N
])
const
noexcept
(
noexcept
(
JSONSerializer
<
Array
>::
from_json
(
std
::
declval
<
const
basic_json_t
&>
(),
v
)))
{
JSONSerializer
<
Array
>::
from_json
(
*
this
,
v
);
return
v
;
}
/*!
/*!
@brief get a pointer value (implicit)
@brief get a pointer value (implicit)
...
...
test/src/unit-conversions.cpp
View file @
e6e6805c
...
@@ -386,6 +386,16 @@ TEST_CASE("value conversion")
...
@@ -386,6 +386,16 @@ TEST_CASE("value conversion")
CHECK
(
json
(
a
)
==
j
);
CHECK
(
json
(
a
)
==
j
);
}
}
SECTION
(
"built-in arrays"
)
{
const
int
nbs
[]
=
{
0
,
1
,
2
};
int
nbs2
[]
=
{
0
,
0
,
0
};
json
j2
=
nbs
;
j2
.
get_to
(
nbs2
);
CHECK
(
std
::
equal
(
std
::
begin
(
nbs
),
std
::
end
(
nbs
),
std
::
begin
(
nbs2
)));
}
SECTION
(
"std::deque<json>"
)
SECTION
(
"std::deque<json>"
)
{
{
std
::
deque
<
json
>
a
{
"previous"
,
"value"
};
std
::
deque
<
json
>
a
{
"previous"
,
"value"
};
...
...
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