lolautoaccept/include/json.h

41 lines
747 B
C
Raw Permalink Normal View History

2022-04-24 01:27:46 +02:00
#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);
2022-07-09 01:01:51 +02:00
template<>
uint32_t convert(const QJsonValue& val);
2022-06-27 23:18:27 +02:00
template<>
int64_t convert(const QJsonValue& val);
2022-07-09 01:01:51 +02:00
template<>
uint64_t convert(const QJsonValue& val);
2022-04-24 01:27:46 +02:00
template<>
2023-05-31 22:22:23 +02:00
QString convert(const QJsonValue& val);
2022-04-24 01:27:46 +02:00
template<>
bool convert(const QJsonValue& val);
2022-07-03 19:05:22 +02:00
template<>
QString convert(const QJsonValue& val);
2022-04-24 01:27:46 +02:00
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;
}