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>
|
|
|
|
T getJsonOrFail(const Json::Value &root, const std::string &key)
|
|
|
|
{
|
|
|
|
const auto members = root.getMemberNames();
|
|
|
|
if (std::find(members.begin(), members.end(), key) == members.end())
|
|
|
|
{
|
2015-09-25 00:13:30 +02:00
|
|
|
throw std::runtime_error("Json key not existing");
|
2015-05-11 00:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return getJson<T>(root, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string toHexString(uint64_t c);
|
|
|
|
uint64_t toUint64(const std::string &s);
|
|
|
|
|
|
|
|
#endif
|