2015-05-11 00:18:22 +02:00
|
|
|
#ifndef UTIL_H
|
|
|
|
#define UTIL_H
|
|
|
|
|
|
|
|
#include <algorithm>
|
2015-09-25 00:13:30 +02:00
|
|
|
#include <exception>
|
2015-05-11 00:18:22 +02:00
|
|
|
#include <json/json.h>
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T getJson(const Json::Value &root, const std::string &key);
|
|
|
|
|
|
|
|
template <typename T>
|
2015-10-27 16:05:09 +01:00
|
|
|
static T getJsonOrFail(const Json::Value &root, const std::string &key)
|
2015-05-11 00:18:22 +02:00
|
|
|
{
|
2015-10-27 16:05:09 +01:00
|
|
|
if (root.isObject() == false)
|
2015-05-11 00:18:22 +02:00
|
|
|
{
|
2015-10-27 16:05:09 +01:00
|
|
|
throw std::runtime_error("Invalid Json Object");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root.isMember(key) == false) {
|
2015-10-01 22:09:55 +02:00
|
|
|
throw std::runtime_error("Json key \"" + key + "\" not existing");
|
2015-05-11 00:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return getJson<T>(root, key);
|
|
|
|
}
|
|
|
|
|
2016-04-03 17:03:50 +02:00
|
|
|
std::string randHexString(unsigned int len);
|
2015-05-11 00:18:22 +02:00
|
|
|
|
|
|
|
#endif
|