Commit da459ff0 authored by Alexander Lapshin's avatar Alexander Lapshin

added try catch blocks to json loading functions

parent 831edfb3
...@@ -18,7 +18,7 @@ typedef rapidjson::Document::AllocatorType jsonalloc; ...@@ -18,7 +18,7 @@ typedef rapidjson::Document::AllocatorType jsonalloc;
typedef rapidjson::Value jsonval; typedef rapidjson::Value jsonval;
typedef rapidjson::Document jsondoc; typedef rapidjson::Document jsondoc;
inline bool extract_value(const jsonval& parent, const std::string& key, bool exist, bool* loaded, jsonval::ConstMemberIterator& result) inline bool extract_value(const jsonval& parent, const std::string& key, const bool exist, bool* loaded, jsonval::ConstMemberIterator& result)
{ {
const jsonval::ConstMemberIterator itr = parent.FindMember(key.c_str()); const jsonval::ConstMemberIterator itr = parent.FindMember(key.c_str());
...@@ -55,7 +55,7 @@ inline bool extract_value(const jsonval& parent, const std::string& key, bool ex ...@@ -55,7 +55,7 @@ inline bool extract_value(const jsonval& parent, const std::string& key, bool ex
return true; return true;
} }
inline bool extract_value(const std::map<std::string, std::string>& parent, const std::string& key, bool exist, bool* loaded, std::map<std::string, std::string>::const_iterator& result) inline bool extract_value(const std::map<std::string, std::string>& parent, const std::string& key, const bool exist, bool* loaded, std::map<std::string, std::string>::const_iterator& result)
{ {
const auto itr = parent.find(key); const auto itr = parent.find(key);
...@@ -81,6 +81,7 @@ inline bool extract_value(const std::map<std::string, std::string>& parent, cons ...@@ -81,6 +81,7 @@ inline bool extract_value(const std::map<std::string, std::string>& parent, cons
static bool loadjson(const jsonval& parent, const std::string& key, std::vector<std::string>& vec, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, std::vector<std::string>& 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;
...@@ -89,7 +90,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector< ...@@ -89,7 +90,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) {
...@@ -113,15 +114,20 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector< ...@@ -113,15 +114,20 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector<
vec.push_back(ss.str()); vec.push_back(ss.str());
} }
else { else {
throw Exp() << "error: unsupported type"; throw Exp() << "unsupported type '" << it->GetType() << "'";
} }
} }
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
}
return true; return true;
} }
static bool loadjson(const jsonval& parent, const std::string& key, std::vector<size_t>& vec, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, std::vector<size_t>& 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;
...@@ -130,7 +136,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector< ...@@ -130,7 +136,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) {
...@@ -138,8 +144,12 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector< ...@@ -138,8 +144,12 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector<
vec.push_back(it->GetInt()); vec.push_back(it->GetInt());
} }
else { else {
throw Exp() << "error: unsupported type"; throw Exp() << "unsupported type '" << it->GetType() << "'";
}
}
} }
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -147,6 +157,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector< ...@@ -147,6 +157,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector<
static bool loadjson(const jsonval& parent, const std::string& key, std::vector<int>& vec, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, std::vector<int>& 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;
...@@ -155,7 +166,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector< ...@@ -155,7 +166,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) {
...@@ -163,15 +174,20 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector< ...@@ -163,15 +174,20 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector<
vec.push_back(it->GetInt()); vec.push_back(it->GetInt());
} }
else { else {
throw Exp() << "error: unsupported type"; throw Exp() << "unsupported type '" << it->GetType() << "'";
} }
} }
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
}
return true; return true;
} }
static bool loadjson(const jsonval& parent, const std::string& key, std::vector<double>& vec, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, std::vector<double>& 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;
...@@ -180,7 +196,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector< ...@@ -180,7 +196,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) {
...@@ -191,15 +207,20 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector< ...@@ -191,15 +207,20 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::vector<
vec.push_back(it->GetInt()); vec.push_back(it->GetInt());
} }
else { else {
throw Exp() << "error: unsupported type"; throw Exp() << "unsupported type '" << it->GetType() << "'";
}
}
} }
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
} }
template <typename T> bool loadjson(const jsonval& parent, std::string key, std::vector<T>& vec, const bool exist = true, bool* loaded = nullptr) template <typename T> bool loadjson(const jsonval& parent, const std::string& key, std::vector<T>& 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;
...@@ -208,7 +229,7 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, std: ...@@ -208,7 +229,7 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, std:
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 (rapidjson::SizeType i = 0; i < a.Size(); i++) { for (rapidjson::SizeType i = 0; i < a.Size(); i++) {
...@@ -217,11 +238,17 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, std: ...@@ -217,11 +238,17 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, std:
vec.emplace_back(item); vec.emplace_back(item);
} }
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
}
return true; return true;
} }
template <typename T, typename Tid> bool loadjson(const jsonval& parent, const std::string key, std::map<Tid, T>& map, const bool exist = true, bool* loaded = nullptr) template <typename T, typename Tid> bool loadjson(const jsonval& parent, const std::string key, std::map<Tid, T>& map, 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;
...@@ -230,7 +257,7 @@ template <typename T, typename Tid> bool loadjson(const jsonval& parent, const s ...@@ -230,7 +257,7 @@ template <typename T, typename Tid> bool loadjson(const jsonval& parent, const s
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 (rapidjson::SizeType i = 0; i < a.Size(); i++) { for (rapidjson::SizeType i = 0; i < a.Size(); i++) {
...@@ -238,12 +265,17 @@ template <typename T, typename Tid> bool loadjson(const jsonval& parent, const s ...@@ -238,12 +265,17 @@ template <typename T, typename Tid> bool loadjson(const jsonval& parent, const s
item.load(a[i]); item.load(a[i]);
map[item.getId()] = item; map[item.getId()] = item;
} }
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
}
return true; return true;
} }
template <typename T> bool loadjson(const jsonval& parent, std::string key, T& item, void (*f)(const jsonval&, T&), const bool exist = true, bool* loaded = nullptr) template <typename T> bool loadjson(const jsonval& parent, const std::string& key, T& item, void (*f)(const jsonval&, T&), 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;
...@@ -252,16 +284,21 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, T& i ...@@ -252,16 +284,21 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, T& i
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (!a.IsObject()) { if (!a.IsObject()) {
throw Exp() << "error: element is not an object"; throw Exp() << "element is not an object";
} }
f(a, item); f(a, item);
}
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, 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 {
std::map<std::string, std::string>::const_iterator itr; std::map<std::string, std::string>::const_iterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
...@@ -270,12 +307,17 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -270,12 +307,17 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
} }
value.set(itr->second); value.set(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 jsonval& parent, const std::string& key, svalue<std::string>& value, const bool exist = true) static bool loadjson(const jsonval& parent, const std::string& key, svalue<std::string>& value, const bool exist = true)
{ {
try {
jsonval::ConstMemberIterator itr; jsonval::ConstMemberIterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
...@@ -284,16 +326,21 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<std:: ...@@ -284,16 +326,21 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<std::
} }
if (!itr->value.IsString()) { if (!itr->value.IsString()) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "unexpected type";
} }
value.set(itr->value.GetString()); value.set(itr->value.GetString());
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
}
return true; 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)
{ {
try {
jsonval::ConstMemberIterator itr; jsonval::ConstMemberIterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
...@@ -304,18 +351,23 @@ template <typename T> static bool loadjson(const jsonval& parent, const std::str ...@@ -304,18 +351,23 @@ template <typename T> static bool loadjson(const jsonval& parent, const std::str
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (!a.IsObject()) { if (!a.IsObject()) {
throw Exp() << "error: element is not an object"; throw Exp() << "element is not an object";
} }
T val; T val;
val.load(itr->value); val.load(itr->value);
value = val; value = val;
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
}
return true; return true;
} }
template <typename T> bool loadjson(const jsonval& parent, const std::string& key, T& item, const bool exist = true, bool* loaded = nullptr) template <typename T> bool loadjson(const jsonval& parent, const std::string& key, T& item, 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;
...@@ -324,10 +376,14 @@ template <typename T> bool loadjson(const jsonval& parent, const std::string& ke ...@@ -324,10 +376,14 @@ template <typename T> bool loadjson(const jsonval& parent, const std::string& ke
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (!a.IsObject()) { if (!a.IsObject()) {
throw Exp() << "error: element is not an object"; throw Exp() << "element is not an object";
} }
item.load(a); item.load(a);
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
}
return true; return true;
} }
...@@ -349,7 +405,7 @@ template <typename T> void loadjson(const jsonval& parent, std::vector<T>& vec) ...@@ -349,7 +405,7 @@ template <typename T> void loadjson(const jsonval& parent, std::vector<T>& vec)
} }
} }
else { else {
throw Exp() << "error: element is not an array"; throw Exp() << "element is not an array";
} }
} }
...@@ -370,12 +426,13 @@ template <typename T, typename T2> void loadjson(const jsonval& parent, std::map ...@@ -370,12 +426,13 @@ template <typename T, typename T2> void loadjson(const jsonval& parent, std::map
} }
} }
else { else {
throw Exp() << "error: element is not an array"; throw Exp() << "element is not an array";
} }
} }
static bool loadjson(const jsonval& parent, const std::string& key, double& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, double& value, 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;
...@@ -397,11 +454,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, double& valu ...@@ -397,11 +454,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, double& valu
} }
if (!Converter::ToNumber(str, value)) { if (!Converter::ToNumber(str, value)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
} }
} }
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;
...@@ -409,6 +470,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, double& valu ...@@ -409,6 +470,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, double& valu
static bool loadjson(const jsonval& parent, const std::string& key, float& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, float& value, 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;
...@@ -430,11 +492,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, float& value ...@@ -430,11 +492,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, float& value
} }
if (!Converter::ToNumber(str, value)) { if (!Converter::ToNumber(str, value)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
} }
} }
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;
...@@ -442,6 +508,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, float& value ...@@ -442,6 +508,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, float& value
static bool loadjson(const jsonval& parent, const std::string& key, int& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, int& value, 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;
...@@ -454,7 +521,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, int& value, ...@@ -454,7 +521,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, int& 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;
...@@ -463,11 +530,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, int& value, ...@@ -463,11 +530,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, int& value,
} }
if (!Converter::ToNumber(str, value)) { if (!Converter::ToNumber(str, value)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
} }
} }
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;
...@@ -475,6 +546,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, int& value, ...@@ -475,6 +546,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, int& value,
static bool loadjson(const jsonval& parent, const std::string& key, short& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, short& value, 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;
...@@ -487,7 +559,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, short& value ...@@ -487,7 +559,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, short& 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;
...@@ -496,11 +568,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, short& value ...@@ -496,11 +568,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, short& value
} }
if (!Converter::ToNumber(str, value)) { if (!Converter::ToNumber(str, value)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
} }
} }
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;
...@@ -508,6 +584,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, short& value ...@@ -508,6 +584,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, short& value
static bool loadjson(const jsonval& parent, const std::string& key, size_t& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, size_t& value, 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;
...@@ -520,7 +597,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, size_t& valu ...@@ -520,7 +597,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, size_t& 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;
...@@ -529,11 +606,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, size_t& valu ...@@ -529,11 +606,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, size_t& valu
} }
if (!Converter::ToNumber(str, value)) { if (!Converter::ToNumber(str, value)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
} }
} }
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;
...@@ -541,6 +622,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, size_t& valu ...@@ -541,6 +622,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, size_t& valu
static bool loadjson(const jsonval& parent, const std::string& key, bool& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, bool& value, 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;
...@@ -565,11 +647,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, bool& value, ...@@ -565,11 +647,15 @@ static bool loadjson(const jsonval& parent, const std::string& key, bool& value,
} }
if (!Converter::ToNumber(str, value)) { if (!Converter::ToNumber(str, value)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
} }
} }
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;
...@@ -577,6 +663,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, bool& value, ...@@ -577,6 +663,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, bool& value,
static bool loadjson(const jsonval& parent, const std::string& key, std::string& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const jsonval& parent, const std::string& key, std::string& value, 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;
...@@ -593,7 +680,11 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::string& ...@@ -593,7 +680,11 @@ static bool loadjson(const jsonval& parent, const std::string& key, std::string&
value = stream.str(); value = stream.str();
} }
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;
...@@ -655,10 +746,10 @@ template <typename T, typename TK> void PutValue(jsonalloc& alc, jsonval& ss, co ...@@ -655,10 +746,10 @@ template <typename T, typename TK> void PutValue(jsonalloc& alc, jsonval& ss, co
ss.AddMember(jname, jsvec, alc); ss.AddMember(jname, jsvec, alc);
} }
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 (typename std::map<TK, T>::const_iterator it = vec.begin(); it != vec.end(); ++it) { for (auto& it = vec.begin(); it != vec.end(); ++it) {
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);
...@@ -705,7 +796,7 @@ inline void PutValue(jsonalloc& alc, jsonval& ss, const std::string& conName, co ...@@ -705,7 +796,7 @@ inline void PutValue(jsonalloc& alc, jsonval& ss, const std::string& conName, co
ss.AddMember(jname, jsvec, alc); ss.AddMember(jname, jsvec, alc);
} }
template <typename T> void PutValue(jsonalloc& alc, jsonval& ss, const std::string conName, const std::vector<T>& vec) template <typename T> void PutValue(jsonalloc& alc, jsonval& ss, const std::string& conName, const std::vector<T>& vec)
{ {
jsonval jsvec(rapidjson::kArrayType); jsonval jsvec(rapidjson::kArrayType);
for (typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end(); ++it) { for (typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end(); ++it) {
...@@ -718,7 +809,7 @@ template <typename T> void PutValue(jsonalloc& alc, jsonval& ss, const std::stri ...@@ -718,7 +809,7 @@ template <typename T> void PutValue(jsonalloc& alc, jsonval& ss, const std::stri
ss.AddMember(jname, jsvec, alc); ss.AddMember(jname, jsvec, alc);
} }
template <typename T> void PutValue(jsonalloc& alc, jsonval& ss, const std::string conName, const T& object) template <typename T> void PutValue(jsonalloc& alc, jsonval& ss, const std::string& conName, const T& object)
{ {
jsonval obj(rapidjson::kObjectType); jsonval obj(rapidjson::kObjectType);
PutValue(alc, obj, object); PutValue(alc, obj, object);
...@@ -856,6 +947,7 @@ static void loadStrJson(const std::string& data, rapidjson::Document& document) ...@@ -856,6 +947,7 @@ static void loadStrJson(const std::string& data, rapidjson::Document& document)
static bool loadjson(const jsonval& parent, const std::string& key, svalue<double>& value, const bool exist = true) static bool loadjson(const jsonval& parent, const std::string& key, svalue<double>& value, const bool exist = true)
{ {
try {
jsonval::ConstMemberIterator itr; jsonval::ConstMemberIterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
...@@ -883,13 +975,17 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<doubl ...@@ -883,13 +975,17 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<doubl
double val; double val;
if (!Converter::ToNumber(str, val)) { if (!Converter::ToNumber(str, val)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
} }
value = val; value = val;
} }
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;
...@@ -897,6 +993,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<doubl ...@@ -897,6 +993,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<doubl
static bool loadjson(const jsonval& parent, const std::string& key, svalue<int>& value, const bool exist = true) static bool loadjson(const jsonval& parent, const std::string& key, svalue<int>& value, const bool exist = true)
{ {
try {
jsonval::ConstMemberIterator itr; jsonval::ConstMemberIterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
...@@ -921,13 +1018,17 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<int>& ...@@ -921,13 +1018,17 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<int>&
int val; int val;
if (!Converter::ToNumber(str, val)) { if (!Converter::ToNumber(str, val)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
} }
value = val; value = val;
} }
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;
...@@ -935,6 +1036,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<int>& ...@@ -935,6 +1036,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<int>&
static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, double& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, double& 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)) {
...@@ -951,7 +1053,11 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -951,7 +1053,11 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
} }
if (!Converter::ToNumber(str, value)) { if (!Converter::ToNumber(str, value)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
}
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -959,6 +1065,7 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -959,6 +1065,7 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, int& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, int& 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)) {
...@@ -975,7 +1082,11 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -975,7 +1082,11 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
} }
if (!Converter::ToNumber(str, value)) { if (!Converter::ToNumber(str, value)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
}
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -983,6 +1094,7 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -983,6 +1094,7 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, long long& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, long long& 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)) {
...@@ -999,7 +1111,11 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -999,7 +1111,11 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
} }
if (!Converter::ToNumber(str, value)) { if (!Converter::ToNumber(str, value)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
}
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -1007,6 +1123,7 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -1007,6 +1123,7 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, bool& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, bool& 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)) {
...@@ -1023,7 +1140,11 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -1023,7 +1140,11 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
} }
if (!Converter::ToNumber(str, value)) { if (!Converter::ToNumber(str, value)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
}
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -1031,6 +1152,7 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -1031,6 +1152,7 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, std::string& value, const bool exist = true, bool* loaded = nullptr) static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, std::string& 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)) {
...@@ -1038,12 +1160,17 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -1038,12 +1160,17 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
} }
value = itr->second; value = 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, svalue<double>& value, const bool exist = true) static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, svalue<double>& 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;
...@@ -1062,16 +1189,21 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -1062,16 +1189,21 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
double val; double val;
if (!Converter::ToNumber(str, val)) { if (!Converter::ToNumber(str, val)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
} }
value = val; value = val;
}
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, svalue<int>& value, const bool exist = true) static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, svalue<int>& 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;
...@@ -1090,10 +1222,14 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -1090,10 +1222,14 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std
int val; int val;
if (!Converter::ToNumber(str, val)) { if (!Converter::ToNumber(str, val)) {
throw (Exp() << "bad value format '" << str << "'" << " in container '"); throw Exp() << "bad value format '" << str << "'";
} }
value = val; value = val;
}
catch (std::exception& e) {
throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
}
return true; return true;
} }
...@@ -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;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment