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
da459ff0
Commit
da459ff0
authored
Aug 12, 2021
by
Alexander Lapshin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added try catch blocks to json loading functions
parent
831edfb3
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
653 additions
and
487 deletions
+653
-487
json_functions.h
json/json_functions.h
+555
-419
json_functions_bno.h
json/json_functions_bno.h
+98
-68
No files found.
json/json_functions.h
View file @
da459ff0
This diff is collapsed.
Click to expand it.
json/json_functions_bno.h
View file @
da459ff0
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
static
bool
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
std
::
vector
<
TimeJD
>&
vec
,
const
bool
exist
=
true
,
bool
*
loaded
=
nullptr
)
static
bool
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
std
::
vector
<
TimeJD
>&
vec
,
const
bool
exist
=
true
,
bool
*
loaded
=
nullptr
)
{
{
try
{
jsonval
::
ConstMemberIterator
itr
;
jsonval
::
ConstMemberIterator
itr
;
if
(
!
extract_value
(
parent
,
key
,
exist
,
loaded
,
itr
))
{
if
(
!
extract_value
(
parent
,
key
,
exist
,
loaded
,
itr
))
{
return
false
;
return
false
;
...
@@ -14,7 +15,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector<
...
@@ -14,7 +15,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector<
const
jsonval
&
a
=
itr
->
value
;
const
jsonval
&
a
=
itr
->
value
;
if
(
!
a
.
IsArray
())
{
if
(
!
a
.
IsArray
())
{
throw
Exp
()
<<
"error:
element is not an array"
;
throw
Exp
()
<<
"
element is not an array"
;
}
}
for
(
jsonval
::
ConstValueIterator
it
=
a
.
Begin
();
it
!=
a
.
End
();
++
it
)
{
for
(
jsonval
::
ConstValueIterator
it
=
a
.
Begin
();
it
!=
a
.
End
();
++
it
)
{
...
@@ -22,15 +23,20 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector<
...
@@ -22,15 +23,20 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector<
vec
.
emplace_back
(
StrToDate
(
it
->
GetString
()));
vec
.
emplace_back
(
StrToDate
(
it
->
GetString
()));
}
}
else
{
else
{
throw
Exp
()
<<
"error:
unsupported type"
;
throw
Exp
()
<<
"
unsupported type"
;
}
}
}
}
}
catch
(
std
::
exception
&
e
)
{
throw
Exp
()
<<
"failed to load key '"
<<
key
<<
"'"
<<
" - "
<<
trim
(
e
.
what
())
<<
"
\n
"
;
}
return
true
;
return
true
;
}
}
static
void
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
TimeJD
&
value
,
bool
exist
=
true
,
bool
*
loaded
=
nullptr
)
static
void
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
TimeJD
&
value
,
bool
exist
=
true
,
bool
*
loaded
=
nullptr
)
{
{
try
{
const
jsonval
::
ConstMemberIterator
itr
=
parent
.
FindMember
(
key
.
c_str
());
const
jsonval
::
ConstMemberIterator
itr
=
parent
.
FindMember
(
key
.
c_str
());
if
(
itr
==
parent
.
MemberEnd
()
&&
exist
)
{
if
(
itr
==
parent
.
MemberEnd
()
&&
exist
)
{
...
@@ -54,16 +60,21 @@ static void loadjson(const jsonval& parent, const std::string& key, TimeJD& valu
...
@@ -54,16 +60,21 @@ static void loadjson(const jsonval& parent, const std::string& key, TimeJD& valu
}
}
}
}
else
{
else
{
throw
(
Exp
()
<<
"element '"
<<
key
<<
"'"
<<
" has unexpected format '"
);
throw
Exp
()
<<
"unexpected type"
;
}
}
catch
(
std
::
exception
&
e
)
{
throw
Exp
()
<<
"failed to load key '"
<<
key
<<
"'"
<<
" - "
<<
trim
(
e
.
what
())
<<
"
\n
"
;
}
}
}
}
static
void
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
TimeGD
&
value
,
bool
exist
=
true
)
static
void
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
TimeGD
&
value
,
bool
exist
=
true
)
{
{
try
{
const
jsonval
::
ConstMemberIterator
itr
=
parent
.
FindMember
(
key
.
c_str
());
const
jsonval
::
ConstMemberIterator
itr
=
parent
.
FindMember
(
key
.
c_str
());
if
(
itr
==
parent
.
MemberEnd
()
&&
exist
)
{
if
(
itr
==
parent
.
MemberEnd
()
&&
exist
)
{
throw
Exp
()
<<
"error:
element not found"
;
throw
Exp
()
<<
"
element not found"
;
}
}
const
jsonval
&
a
=
itr
->
value
;
const
jsonval
&
a
=
itr
->
value
;
...
@@ -72,7 +83,11 @@ static void loadjson(const jsonval& parent, const std::string& key, TimeGD& valu
...
@@ -72,7 +83,11 @@ static void loadjson(const jsonval& parent, const std::string& key, TimeGD& valu
StrToDate
(
a
.
GetString
(),
value
);
StrToDate
(
a
.
GetString
(),
value
);
}
}
else
{
else
{
throw
(
Exp
()
<<
"element '"
<<
key
<<
"'"
<<
" has unexpected format '"
);
throw
Exp
()
<<
"unexpected type"
;
}
}
catch
(
std
::
exception
&
e
)
{
throw
Exp
()
<<
"failed to load key '"
<<
key
<<
"'"
<<
" - "
<<
trim
(
e
.
what
())
<<
"
\n
"
;
}
}
}
}
...
@@ -93,6 +108,7 @@ static void PutValue(jsonalloc& alc, jsonval& ss, const std::string& conName, co
...
@@ -93,6 +108,7 @@ static void PutValue(jsonalloc& alc, jsonval& ss, const std::string& conName, co
static
bool
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
svalue
<
TimeJD
>&
value
,
const
bool
exist
=
true
)
static
bool
loadjson
(
const
jsonval
&
parent
,
const
std
::
string
&
key
,
svalue
<
TimeJD
>&
value
,
const
bool
exist
=
true
)
{
{
try
{
jsonval
::
ConstMemberIterator
itr
;
jsonval
::
ConstMemberIterator
itr
;
bool
*
loaded
=
nullptr
;
bool
*
loaded
=
nullptr
;
...
@@ -106,7 +122,11 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<TimeJ
...
@@ -106,7 +122,11 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<TimeJ
value
=
StrToDate
(
a
.
GetString
());
value
=
StrToDate
(
a
.
GetString
());
}
}
else
{
else
{
throw
(
Exp
()
<<
"element '"
<<
key
<<
"'"
<<
" has unexpected format '"
);
throw
Exp
()
<<
"unexpected type"
;
}
}
catch
(
std
::
exception
&
e
)
{
throw
Exp
()
<<
"failed to load key '"
<<
key
<<
"'"
<<
" - "
<<
trim
(
e
.
what
())
<<
"
\n
"
;
}
}
return
true
;
return
true
;
...
@@ -114,6 +134,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<TimeJ
...
@@ -114,6 +134,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<TimeJ
static
bool
loadjson
(
const
std
::
map
<
std
::
string
,
std
::
string
>&
parent
,
const
std
::
string
&
key
,
svalue
<
TimeJD
>&
value
,
const
bool
exist
=
true
)
static
bool
loadjson
(
const
std
::
map
<
std
::
string
,
std
::
string
>&
parent
,
const
std
::
string
&
key
,
svalue
<
TimeJD
>&
value
,
const
bool
exist
=
true
)
{
{
try
{
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
itr
;
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
itr
;
bool
*
loaded
=
nullptr
;
bool
*
loaded
=
nullptr
;
...
@@ -122,12 +143,17 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
...
@@ -122,12 +143,17 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
}
}
value
=
StrToDate
(
itr
->
second
);
value
=
StrToDate
(
itr
->
second
);
}
catch
(
std
::
exception
&
e
)
{
throw
Exp
()
<<
"failed to load key '"
<<
key
<<
"'"
<<
" - "
<<
trim
(
e
.
what
())
<<
"
\n
"
;
}
return
true
;
return
true
;
}
}
static
bool
loadjson
(
const
std
::
map
<
std
::
string
,
std
::
string
>&
parent
,
const
std
::
string
&
key
,
TimeJD
&
value
,
const
bool
exist
=
true
,
bool
*
loaded
=
nullptr
)
static
bool
loadjson
(
const
std
::
map
<
std
::
string
,
std
::
string
>&
parent
,
const
std
::
string
&
key
,
TimeJD
&
value
,
const
bool
exist
=
true
,
bool
*
loaded
=
nullptr
)
{
{
try
{
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
itr
;
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
itr
;
if
(
!
extract_value
(
parent
,
key
,
exist
,
loaded
,
itr
))
{
if
(
!
extract_value
(
parent
,
key
,
exist
,
loaded
,
itr
))
{
...
@@ -144,6 +170,10 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
...
@@ -144,6 +170,10 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
}
}
value
=
StrToDate
(
str
);
value
=
StrToDate
(
str
);
}
catch
(
std
::
exception
&
e
)
{
throw
Exp
()
<<
"failed to load key '"
<<
key
<<
"'"
<<
" - "
<<
trim
(
e
.
what
())
<<
"
\n
"
;
}
return
true
;
return
true
;
}
}
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