Commit 5009c7a9 authored by Alexander Lapshin's avatar Alexander Lapshin

+ json loading methods

parent 447bd92d
......@@ -260,6 +260,38 @@ template <typename T> bool loadjson(const jsonval& parent, std::string key, T& i
return true;
}
static bool loadjson(const std::map<std::string, std::string>& parent, const std::string& key, svalue<std::string>& value, const bool exist = true)
{
std::map<std::string, std::string>::const_iterator itr;
bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) {
return false;
}
value.set(itr->second);
return true;
}
static bool loadjson(const jsonval& parent, const std::string& key, svalue<std::string>& value, const bool exist = true)
{
jsonval::ConstMemberIterator itr;
bool* loaded = nullptr;
if (!extract_value(parent, key, exist, loaded, itr)) {
return false;
}
if (!itr->value.IsString()) {
throw (Exp() << "element '" << key << "'" << " has unexpected format '");
}
value.set(itr->value.GetString());
return true;
}
template <typename T> static bool loadjson(const jsonval& parent, const std::string& key, svalue<T>& value, const bool exist = true)
{
jsonval::ConstMemberIterator itr;
......@@ -356,7 +388,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, double& valu
}
else if (a.IsString()) {
std::string str = a.GetString();
const std::string str = a.GetString();
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
......@@ -389,7 +421,7 @@ static bool loadjson(const jsonval& parent, const std::string& key, float& value
}
else if (a.IsString()) {
std::string str = a.GetString();
const std::string str = a.GetString();
if (str.empty() && !exist) {
if (loaded) {
*loaded = false;
......
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