1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-11-16 03:59:11 +01:00
doorlockd-mirror/doorlockd/lib/util.h
Ralf Ramsauer 49a5b88f6c Big rewrite of several things
- Data type Token changed from uint64_t to std::string
- Added new class "Request" that describes a JSON TCP request
- Classes may now throw Responses for proper error handling
- Removed JSON parsing from Logic
- proper Error handling everywhere
- Many small fixes
- removed unnecessary includes
- removed using namespace std everywhere
2015-10-01 22:09:55 +02:00

26 lines
560 B
C++

#ifndef UTIL_H
#define UTIL_H
#include <algorithm>
#include <exception>
#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())
{
throw std::runtime_error("Json key \"" + key + "\" not existing");
}
return getJson<T>(root, key);
}
std::string toHexString(uint64_t c);
#endif