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,140 +81,166 @@ inline bool extract_value(const std::map<std::string, std::string>& parent, cons ...@@ -81,140 +81,166 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value;
if (!a.IsArray()) { const jsonval& a = itr->value;
throw Exp() << "error: element is not an array";
}
for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) { if (!a.IsArray()) {
if (it->IsString()) { throw Exp() << "element is not an array";
std::string str = it->GetString();
vec.push_back(str);
}
else if (it->IsInt()) {
std::ostringstream ss;
ss << it->GetInt();
vec.push_back(ss.str());
}
else if (it->IsBool()) {
std::ostringstream ss;
ss << it->GetBool();
vec.push_back(ss.str());
} }
else if (it->IsDouble()) {
std::ostringstream ss; for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) {
ss << it->GetDouble(); if (it->IsString()) {
vec.push_back(ss.str()); std::string str = it->GetString();
} vec.push_back(str);
else { }
throw Exp() << "error: unsupported type"; else if (it->IsInt()) {
std::ostringstream ss;
ss << it->GetInt();
vec.push_back(ss.str());
}
else if (it->IsBool()) {
std::ostringstream ss;
ss << it->GetBool();
vec.push_back(ss.str());
}
else if (it->IsDouble()) {
std::ostringstream ss;
ss << it->GetDouble();
vec.push_back(ss.str());
}
else {
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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value;
if (!a.IsArray()) { const jsonval& a = itr->value;
throw Exp() << "error: element is not an array";
}
for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) { if (!a.IsArray()) {
if (it->IsInt()) { throw Exp() << "element is not an array";
vec.push_back(it->GetInt());
} }
else {
throw Exp() << "error: unsupported type"; for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) {
if (it->IsInt()) {
vec.push_back(it->GetInt());
}
else {
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<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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value;
if (!a.IsArray()) { const jsonval& a = itr->value;
throw Exp() << "error: element is not an array";
}
for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) { if (!a.IsArray()) {
if (it->IsInt()) { throw Exp() << "element is not an array";
vec.push_back(it->GetInt());
} }
else {
throw Exp() << "error: unsupported type"; for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) {
if (it->IsInt()) {
vec.push_back(it->GetInt());
}
else {
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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value;
if (!a.IsArray()) { const jsonval& a = itr->value;
throw Exp() << "error: element is not an array";
}
for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) { if (!a.IsArray()) {
if (it->IsDouble()) { throw Exp() << "element is not an array";
vec.push_back(it->GetDouble());
}
else if (it->IsInt()) {
vec.push_back(it->GetInt());
} }
else {
throw Exp() << "error: unsupported type"; for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) {
if (it->IsDouble()) {
vec.push_back(it->GetDouble());
}
else if (it->IsInt()) {
vec.push_back(it->GetInt());
}
else {
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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
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++) {
T item;
item.load(a[i]);
vec.emplace_back(item);
}
for (rapidjson::SizeType i = 0; i < a.Size(); i++) { }
T item; catch (std::exception& e) {
item.load(a[i]); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
vec.emplace_back(item);
} }
return true; return true;
...@@ -222,112 +248,142 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, std: ...@@ -222,112 +248,142 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, std:
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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
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++) {
T item; T item;
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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
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)
{ {
std::map<std::string, std::string>::const_iterator itr; try {
std::map<std::string, std::string>::const_iterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) { if (!extract_value(parent, key, exist, loaded, itr)) {
return false; return false;
} }
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)
{ {
jsonval::ConstMemberIterator itr; try {
jsonval::ConstMemberIterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) { if (!extract_value(parent, key, exist, loaded, itr)) {
return false; return false;
} }
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)
{ {
jsonval::ConstMemberIterator itr; try {
jsonval::ConstMemberIterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) { if (!extract_value(parent, key, exist, loaded, itr)) {
return false; return false;
} }
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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
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,38 +426,43 @@ template <typename T, typename T2> void loadjson(const jsonval& parent, std::map ...@@ -370,38 +426,43 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsNumber()) { if (a.IsNumber()) {
value = a.GetDouble(); value = a.GetDouble();
} }
else if (a.IsString()) { else if (a.IsString()) {
const std::string str = a.GetString();
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
}
return false;
}
const std::string str = a.GetString(); if (!Converter::ToNumber(str, value)) {
if (str.empty() && !exist) { throw Exp() << "bad value format '" << str << "'";
if (loaded) {
*loaded = false;
} }
return false;
} }
else {
if (!Converter::ToNumber(str, value)) { throw Exp() << "unexpected type";
throw (Exp() << "bad value format '" << str << "'" << " in container '");
} }
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -409,32 +470,37 @@ static bool loadjson(const jsonval& parent, const std::string& key, double& valu ...@@ -409,32 +470,37 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsNumber()) { if (a.IsNumber()) {
value = a.GetDouble(); value = a.GetDouble();
} }
else if (a.IsString()) { else if (a.IsString()) {
const std::string str = a.GetString();
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
}
return false;
}
const std::string str = a.GetString(); if (!Converter::ToNumber(str, value)) {
if (str.empty() && !exist) { throw Exp() << "bad value format '" << str << "'";
if (loaded) {
*loaded = false;
} }
return false;
} }
else {
if (!Converter::ToNumber(str, value)) { throw Exp() << "unexpected type";
throw (Exp() << "bad value format '" << str << "'" << " in container '");
} }
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -442,32 +508,37 @@ static bool loadjson(const jsonval& parent, const std::string& key, float& value ...@@ -442,32 +508,37 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsNumber()) { if (a.IsNumber()) {
value = a.GetInt(); value = a.GetInt();
} }
else if (a.IsString()) { else if (a.IsString()) {
const std::string str = a.GetString();
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
}
return false;
}
std::string str = a.GetString(); if (!Converter::ToNumber(str, value)) {
if (str.empty() && !exist) { throw Exp() << "bad value format '" << str << "'";
if (loaded) {
*loaded = false;
} }
return false;
} }
else {
if (!Converter::ToNumber(str, value)) { throw Exp() << "unexpected type";
throw (Exp() << "bad value format '" << str << "'" << " in container '");
} }
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -475,32 +546,37 @@ static bool loadjson(const jsonval& parent, const std::string& key, int& value, ...@@ -475,32 +546,37 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsNumber()) { if (a.IsNumber()) {
value = a.GetInt(); value = a.GetInt();
} }
else if (a.IsString()) { else if (a.IsString()) {
const std::string str = a.GetString();
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
}
return false;
}
std::string str = a.GetString(); if (!Converter::ToNumber(str, value)) {
if (str.empty() && !exist) { throw Exp() << "bad value format '" << str << "'";
if (loaded) {
*loaded = false;
} }
return false;
} }
else {
if (!Converter::ToNumber(str, value)) { throw Exp() << "unexpected type";
throw (Exp() << "bad value format '" << str << "'" << " in container '");
} }
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -508,32 +584,37 @@ static bool loadjson(const jsonval& parent, const std::string& key, short& value ...@@ -508,32 +584,37 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsNumber()) { if (a.IsNumber()) {
value = a.GetInt(); value = a.GetInt();
} }
else if (a.IsString()) { else if (a.IsString()) {
const std::string str = a.GetString();
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
}
return false;
}
std::string str = a.GetString(); if (!Converter::ToNumber(str, value)) {
if (str.empty() && !exist) { throw Exp() << "bad value format '" << str << "'";
if (loaded) {
*loaded = false;
} }
return false;
} }
else {
if (!Converter::ToNumber(str, value)) { throw Exp() << "unexpected type";
throw (Exp() << "bad value format '" << str << "'" << " in container '");
} }
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -541,35 +622,40 @@ static bool loadjson(const jsonval& parent, const std::string& key, size_t& valu ...@@ -541,35 +622,40 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsInt()) { if (a.IsInt()) {
value = a.GetInt(); value = a.GetInt();
} }
else if (a.IsBool()) { else if (a.IsBool()) {
value = a.GetBool(); value = a.GetBool();
} }
else if (a.IsString()) { else if (a.IsString()) {
std::string str = a.GetString();
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
}
return false;
}
std::string str = a.GetString(); if (!Converter::ToNumber(str, value)) {
if (str.empty() && !exist) { throw Exp() << "bad value format '" << str << "'";
if (loaded) {
*loaded = false;
} }
return false;
} }
else {
if (!Converter::ToNumber(str, value)) { throw Exp() << "unexpected type";
throw (Exp() << "bad value format '" << str << "'" << " in container '");
} }
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -577,23 +663,28 @@ static bool loadjson(const jsonval& parent, const std::string& key, bool& value, ...@@ -577,23 +663,28 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsString()) { if (a.IsString()) {
value = a.GetString(); value = a.GetString();
} }
else if (a.IsInt()) { else if (a.IsInt()) {
std::stringstream stream; std::stringstream stream;
stream << a.GetInt(); stream << a.GetInt();
value = stream.str(); value = stream.str();
}
else {
throw Exp() << "unexpected type";
}
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); 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,40 +947,45 @@ static void loadStrJson(const std::string& data, rapidjson::Document& document) ...@@ -856,40 +947,45 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
jsonval::ConstMemberIterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) { if (!extract_value(parent, key, exist, loaded, itr)) {
return false; return false;
} }
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsDouble()) { if (a.IsDouble()) {
value = a.GetDouble(); value = a.GetDouble();
} }
else if (a.IsInt()) { else if (a.IsInt()) {
value = static_cast<double>(a.GetInt()); value = static_cast<double>(a.GetInt());
} }
else if (a.IsString()) { else if (a.IsString()) {
const std::string str = a.GetString();
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
}
return false;
}
const std::string str = a.GetString(); double val;
if (str.empty() && !exist) { if (!Converter::ToNumber(str, val)) {
if (loaded) { throw Exp() << "bad value format '" << str << "'";
*loaded = false;
} }
return false;
}
double val; value = val;
if (!Converter::ToNumber(str, val)) { }
throw (Exp() << "bad value format '" << str << "'" << " in container '"); else {
throw Exp() << "unexpected type";
} }
value = val;
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -897,37 +993,42 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<doubl ...@@ -897,37 +993,42 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
jsonval::ConstMemberIterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) { if (!extract_value(parent, key, exist, loaded, itr)) {
return false; return false;
} }
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsInt()) { if (a.IsInt()) {
value = a.GetInt(); value = a.GetInt();
} }
else if (a.IsString()) { else if (a.IsString()) {
const std::string str = a.GetString();
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
}
return false;
}
const std::string str = a.GetString(); int val;
if (str.empty() && !exist) { if (!Converter::ToNumber(str, val)) {
if (loaded) { throw Exp() << "bad value format '" << str << "'";
*loaded = false;
} }
return false;
}
int val; value = val;
if (!Converter::ToNumber(str, val)) { }
throw (Exp() << "bad value format '" << str << "'" << " in container '"); else {
throw Exp() << "unexpected type";
} }
value = val;
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -935,23 +1036,28 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<int>& ...@@ -935,23 +1036,28 @@ 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)
{ {
std::map<std::string, std::string>::const_iterator itr; try {
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)) {
return false; return false;
} }
const std::string& str = itr->second; const std::string& str = itr->second;
if (str.empty() && !exist) { if (str.empty() && !exist) {
if (loaded) { if (loaded) {
*loaded = false; *loaded = false;
}
return false;
} }
return false;
}
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,23 +1065,28 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -959,23 +1065,28 @@ 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)
{ {
std::map<std::string, std::string>::const_iterator itr; try {
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)) {
return false; return false;
} }
const std::string& str = itr->second; const std::string& str = itr->second;
if (str.empty() && !exist) { if (str.empty() && !exist) {
if (loaded) { if (loaded) {
*loaded = false; *loaded = false;
}
return false;
} }
return false;
}
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,23 +1094,28 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -983,23 +1094,28 @@ 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)
{ {
std::map<std::string, std::string>::const_iterator itr; try {
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)) {
return false; return false;
} }
const std::string& str = itr->second; const std::string& str = itr->second;
if (str.empty() && !exist) { if (str.empty() && !exist) {
if (loaded) { if (loaded) {
*loaded = false; *loaded = false;
}
return false;
} }
return false;
}
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,23 +1123,28 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -1007,23 +1123,28 @@ 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)
{ {
std::map<std::string, std::string>::const_iterator itr; try {
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)) {
return false; return false;
} }
const std::string& str = itr->second; const std::string& str = itr->second;
if (str.empty() && !exist) { if (str.empty() && !exist) {
if (loaded) { if (loaded) {
*loaded = false; *loaded = false;
}
return false;
} }
return false;
}
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,69 +1152,84 @@ static bool loadjson(const std::map<std::string, std::string>& parent, const std ...@@ -1031,69 +1152,84 @@ 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)
{ {
std::map<std::string, std::string>::const_iterator itr; try {
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)) {
return false; return false;
} }
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)
{ {
std::map<std::string, std::string>::const_iterator itr; try {
std::map<std::string, std::string>::const_iterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) { if (!extract_value(parent, key, exist, loaded, itr)) {
return false; return false;
} }
const std::string& str = itr->second; const std::string& str = itr->second;
if (str.empty() && !exist) { if (str.empty() && !exist) {
if (loaded) { if (loaded) {
*loaded = false; *loaded = false;
}
return false;
} }
return false;
}
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)
{ {
std::map<std::string, std::string>::const_iterator itr; try {
std::map<std::string, std::string>::const_iterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) { if (!extract_value(parent, key, exist, loaded, itr)) {
return false; return false;
} }
const std::string& str = itr->second; const std::string& str = itr->second;
if (str.empty() && !exist) { if (str.empty() && !exist) {
if (loaded) { if (loaded) {
*loaded = false; *loaded = false;
}
return false;
} }
return false;
}
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,73 +6,88 @@ ...@@ -6,73 +6,88 @@
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)
{ {
jsonval::ConstMemberIterator itr; try {
if (!extract_value(parent, key, exist, loaded, itr)) { jsonval::ConstMemberIterator itr;
return false; if (!extract_value(parent, key, exist, loaded, itr)) {
} return false;
}
const jsonval& a = itr->value;
if (!a.IsArray()) { const jsonval& a = itr->value;
throw Exp() << "error: element is not an array";
}
for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) { if (!a.IsArray()) {
if (it->IsString()) { throw Exp() << "element is not an array";
vec.emplace_back(StrToDate(it->GetString()));
} }
else {
throw Exp() << "error: unsupported type"; for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) {
if (it->IsString()) {
vec.emplace_back(StrToDate(it->GetString()));
}
else {
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)
{ {
const jsonval::ConstMemberIterator itr = parent.FindMember(key.c_str()); try {
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 " << key; throw Exp() << "error: element not found " << key;
} }
else if (itr == parent.MemberEnd() && !exist) { else if (itr == parent.MemberEnd() && !exist) {
if (loaded) { if (loaded) {
*loaded = false; *loaded = false;
}
return;
} }
return;
}
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsString()) { if (a.IsString()) {
TimeGD gd; TimeGD gd;
StrToDate(a.GetString(), gd); StrToDate(a.GetString(), gd);
value = gd; value = gd;
if (loaded) { if (loaded) {
*loaded = true; *loaded = true;
}
}
else {
throw Exp() << "unexpected type";
} }
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); 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)
{ {
const jsonval::ConstMemberIterator itr = parent.FindMember(key.c_str()); try {
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;
if (a.IsString()) { if (a.IsString()) {
StrToDate(a.GetString(), value); StrToDate(a.GetString(), value);
}
else {
throw Exp() << "unexpected type";
}
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
} }
...@@ -93,20 +108,25 @@ static void PutValue(jsonalloc& alc, jsonval& ss, const std::string& conName, co ...@@ -93,20 +108,25 @@ 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)
{ {
jsonval::ConstMemberIterator itr; try {
jsonval::ConstMemberIterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) { if (!extract_value(parent, key, exist, loaded, itr)) {
return false; return false;
} }
const jsonval& a = itr->value; const jsonval& a = itr->value;
if (a.IsString()) { if (a.IsString()) {
value = StrToDate(a.GetString()); value = StrToDate(a.GetString());
}
else {
throw Exp() << "unexpected type";
}
} }
else { catch (std::exception& e) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '"); throw Exp() << "failed to load key '" << key << "'" << " - " << trim(e.what()) << "\n";
} }
return true; return true;
...@@ -114,36 +134,46 @@ static bool loadjson(const jsonval& parent, const std::string& key, svalue<TimeJ ...@@ -114,36 +134,46 @@ 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)
{ {
std::map<std::string, std::string>::const_iterator itr; try {
std::map<std::string, std::string>::const_iterator itr;
bool* loaded = nullptr; bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) { if (!extract_value(parent, key, exist, loaded, itr)) {
return false; return false;
} }
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)
{ {
std::map<std::string, std::string>::const_iterator itr; try {
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)) {
return false; return false;
} }
const std::string& str = itr->second; const std::string& str = itr->second;
if (str.empty() && !exist) { if (str.empty() && !exist) {
if (loaded) { if (loaded) {
*loaded = false; *loaded = false;
}
return false;
} }
return false;
}
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