bigsnitch/includes.h
2020-09-10 21:26:41 +02:00

45 lines
1.3 KiB
C++

#pragma once
#include <include/api.h>
#include <zmq.hpp>
#include <nlohmann/json.hpp>
#include <sqlite3.h>
#include <filesystem>
#include <QDebug>
#include <iostream>
#include <algorithm>
#include <string>
using json = nlohmann::json;
//major minor patch
#define LITTLESNITCH_VERSION 100
template<typename T, typename K>
bool json_get(json j, T& value, K key) noexcept {
try {
j[key].get_to(value);
return true;
} catch (nlohmann::detail::type_error& err) {
qDebug() << "key " << key << " error " << err.what();
} catch (nlohmann::detail::out_of_range& err) {
qDebug() << "key " << key << " error " << err.what();
} catch (nlohmann::detail::other_error& err) {
qDebug() << "key " << key << " error " << err.what();
}
return false;
}
template<typename T, typename K, typename... Ks>
bool json_get(json j, T& value, K key, Ks... keys) noexcept {
try {
return json_get(j[key], value, keys...);
} catch (nlohmann::detail::type_error& err) {
qDebug() << "key " << key << " error " << err.what();
} catch (nlohmann::detail::out_of_range& err) {
qDebug() << "key " << key << " error " << err.what();
} catch (nlohmann::detail::other_error& err) {
qDebug() << "key " << key << " error " << err.what();
}
return false;
}