Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Alexander Lapshin
common
Commits
75d39329
Commit
75d39329
authored
Aug 15, 2021
by
Alexander Lapshin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new json loading helpers
parent
da459ff0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
2 deletions
+40
-2
json_functions.h
json/json_functions.h
+40
-2
No files found.
json/json_functions.h
View file @
75d39329
...
@@ -296,6 +296,44 @@ template <typename T> bool loadjson(const jsonval& parent, const std::string& ke
...
@@ -296,6 +296,44 @@ template <typename T> bool loadjson(const jsonval& parent, const std::string& ke
return
true
;
return
true
;
}
}
template
<
typename
T
>
bool
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
T
&
item
,
void
(
*
f
)(
const
std
::
string
&
,
T
&
),
const
bool
exist
=
true
,
bool
*
loaded
=
nullptr
)
{
try
{
jsonval
::
ConstMemberIterator
itr
;
if
(
!
extract_value
(
parent
,
key
,
exist
,
loaded
,
itr
))
{
return
false
;
}
if
(
!
itr
->
value
.
IsString
())
{
throw
Exp
()
<<
"element is not an string"
;
}
f
(
itr
->
value
.
GetString
(),
item
);
}
catch
(
std
::
exception
&
e
)
{
throw
Exp
()
<<
"failed to load key '"
<<
key
<<
"'"
<<
" - "
<<
trim
(
e
.
what
())
<<
"
\n
"
;
}
return
true
;
}
template
<
typename
T
>
bool
loadjson
(
const
std
::
map
<
std
::
string
,
std
::
string
>&
parent
,
const
std
::
string
&
key
,
T
&
item
,
void
(
*
f
)(
const
std
::
string
&
,
T
&
),
const
bool
exist
=
true
,
bool
*
loaded
=
nullptr
)
{
try
{
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
itr
;
if
(
!
extract_value
(
parent
,
key
,
exist
,
loaded
,
itr
))
{
return
false
;
}
f
(
itr
->
second
,
item
);
}
catch
(
std
::
exception
&
e
)
{
throw
Exp
()
<<
"failed to load key '"
<<
key
<<
"'"
<<
" - "
<<
trim
(
e
.
what
())
<<
"
\n
"
;
}
return
true
;
}
static
bool
loadjson
(
const
std
::
map
<
std
::
string
,
std
::
string
>&
parent
,
const
std
::
string
&
key
,
svalue
<
std
::
string
>&
value
,
const
bool
exist
=
true
)
static
bool
loadjson
(
const
std
::
map
<
std
::
string
,
std
::
string
>&
parent
,
const
std
::
string
&
key
,
svalue
<
std
::
string
>&
value
,
const
bool
exist
=
true
)
{
{
try
{
try
{
...
@@ -749,9 +787,9 @@ template <typename T, typename TK> void PutValue(jsonalloc& alc, jsonval& ss, co
...
@@ -749,9 +787,9 @@ template <typename T, typename TK> void PutValue(jsonalloc& alc, jsonval& ss, co
template
<
typename
T
,
typename
TK
>
void
PutMapAsVec
(
jsonalloc
&
alc
,
jsonval
&
ss
,
const
std
::
string
&
conName
,
const
std
::
map
<
TK
,
T
>&
vec
,
bool
(
*
f
)(
rapidjson
::
Document
::
AllocatorType
&
,
jsonval
&
,
const
T
&
))
template
<
typename
T
,
typename
TK
>
void
PutMapAsVec
(
jsonalloc
&
alc
,
jsonval
&
ss
,
const
std
::
string
&
conName
,
const
std
::
map
<
TK
,
T
>&
vec
,
bool
(
*
f
)(
rapidjson
::
Document
::
AllocatorType
&
,
jsonval
&
,
const
T
&
))
{
{
jsonval
jsvec
(
rapidjson
::
kArrayType
);
jsonval
jsvec
(
rapidjson
::
kArrayType
);
for
(
auto
&
it
=
vec
.
begin
();
it
!=
vec
.
end
();
++
it
)
{
for
(
const
auto
&
it
:
vec
)
{
jsonval
child
(
rapidjson
::
kObjectType
);
jsonval
child
(
rapidjson
::
kObjectType
);
if
(
f
(
alc
,
child
,
it
->
second
))
{
if
(
f
(
alc
,
child
,
it
.
second
))
{
jsvec
.
PushBack
(
child
,
alc
);
jsvec
.
PushBack
(
child
,
alc
);
}
}
}
}
...
...
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