lolautoaccept/include/json.h

41 lines
747 B
C++

#pragma once
// helper functions for the QJsonObjects
#include <QJsonObject>
#include <QJsonValue>
template<typename T>
T convert(const QJsonValue& val) {
return val.toObject();
}
template<>
int convert(const QJsonValue& val);
template<>
uint32_t convert(const QJsonValue& val);
template<>
int64_t convert(const QJsonValue& val);
template<>
uint64_t convert(const QJsonValue& val);
template<>
QString convert(const QJsonValue& val);
template<>
bool convert(const QJsonValue& val);
template<>
QString convert(const QJsonValue& val);
template<typename T>
T getValue(const QJsonObject& obj, const char* key, const T& def = {}) {
auto it = obj.constFind(key);
if(it != obj.constEnd()) {
return convert<T>(it.value());
}
return def;
}