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
5009c7a9
Commit
5009c7a9
authored
Jul 05, 2021
by
Alexander Lapshin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+ json loading methods
parent
447bd92d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
2 deletions
+34
-2
json_functions.h
json/json_functions.h
+34
-2
No files found.
json/json_functions.h
View file @
5009c7a9
...
@@ -260,6 +260,38 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, T& i
...
@@ -260,6 +260,38 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, T& i
return
true
;
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
)
{
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
itr
;
bool
*
loaded
=
nullptr
;
if
(
!
extract_value
(
parent
,
key
,
exist
,
loaded
,
itr
))
{
return
false
;
}
value
.
set
(
itr
->
second
);
return
true
;
}
static
bool
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
svalue
<
std
::
string
>&
value
,
const
bool
exist
=
true
)
{
jsonval
::
ConstMemberIterator
itr
;
bool
*
loaded
=
nullptr
;
if
(
!
extract_value
(
parent
,
key
,
exist
,
loaded
,
itr
))
{
return
false
;
}
if
(
!
itr
->
value
.
IsString
())
{
throw
(
Exp
()
<<
"element '"
<<
key
<<
"'"
<<
" has unexpected format '"
);
}
value
.
set
(
itr
->
value
.
GetString
());
return
true
;
}
template
<
typename
T
>
static
bool
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
svalue
<
T
>&
value
,
const
bool
exist
=
true
)
template
<
typename
T
>
static
bool
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
svalue
<
T
>&
value
,
const
bool
exist
=
true
)
{
{
jsonval
::
ConstMemberIterator
itr
;
jsonval
::
ConstMemberIterator
itr
;
...
@@ -356,7 +388,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, double& valu
...
@@ -356,7 +388,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, double& valu
}
}
else
if
(
a
.
IsString
())
{
else
if
(
a
.
IsString
())
{
std
::
string
str
=
a
.
GetString
();
const
std
::
string
str
=
a
.
GetString
();
if
(
str
.
empty
()
&&
!
exist
)
{
if
(
str
.
empty
()
&&
!
exist
)
{
if
(
loaded
)
{
if
(
loaded
)
{
*
loaded
=
false
;
*
loaded
=
false
;
...
@@ -389,7 +421,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, float& value
...
@@ -389,7 +421,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, float& value
}
}
else
if
(
a
.
IsString
())
{
else
if
(
a
.
IsString
())
{
std
::
string
str
=
a
.
GetString
();
const
std
::
string
str
=
a
.
GetString
();
if
(
str
.
empty
()
&&
!
exist
)
{
if
(
str
.
empty
()
&&
!
exist
)
{
if
(
loaded
)
{
if
(
loaded
)
{
*
loaded
=
false
;
*
loaded
=
false
;
...
...
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