Skip to content

Commit

Permalink
fix gcc build error
Browse files Browse the repository at this point in the history
  • Loading branch information
jat001 authored and sorayuki committed Nov 1, 2021
1 parent a9e4981 commit 3e82fd2
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,44 +43,14 @@ struct QJsonUtil {
template<class T>
struct JsonType;

template<>
struct JsonType<double> {
bool Check(JsonIt& it) { return it->isDouble(); }
double Get(JsonIt& it) { return it->toDouble(); }
};

template<>
struct JsonType<int> {
bool Check(JsonIt& it) { return it->isDouble(); }
int Get(JsonIt& it) { return static_cast<int>(std::round(it->toDouble())); }
};

template<>
struct JsonType<QString> {
bool Check(JsonIt& it) { return it->isString(); }
QString Get(JsonIt& it) { return it->toString(); }
};

template<>
struct JsonType<std::string> {
bool Check(JsonIt& it) { return it->isString(); }
std::string Get(JsonIt& it) { return tostdu8(it->toString()); }
};

template<>
struct JsonType<bool> {
bool Check(JsonIt& it) { return it->isBool(); }
bool Get(JsonIt& it) { return it->toBool(); }
};

template<class Val>
static Val Get(QJsonObject& json, const char* key, Val def) {
auto it = json.find(key);
if (it != json.end() && JsonType<Val>().Check(it))
return JsonType<Val>().Get(it);
else
return def;
}
};

template<class Val>
static std::optional<Val> Get(QJsonObject& json, const char* key) {
Expand All @@ -89,7 +59,7 @@ struct QJsonUtil {
return JsonType<Val>().Get(it);
else
return std::optional<Val>{};
}
};

template<class Fun>
static bool IfGet(QJsonObject& json, const char* key, const Fun& f) {
Expand All @@ -101,5 +71,35 @@ struct QJsonUtil {
} else {
return false;
}
}
};
};
};

template<>
struct QJsonUtil::JsonType<double> {
bool Check(JsonIt& it) { return it->isDouble(); }
double Get(JsonIt& it) { return it->toDouble(); }
};

template<>
struct QJsonUtil::JsonType<int> {
bool Check(JsonIt& it) { return it->isDouble(); }
int Get(JsonIt& it) { return static_cast<int>(std::round(it->toDouble())); }
};

template<>
struct QJsonUtil::JsonType<QString> {
bool Check(JsonIt& it) { return it->isString(); }
QString Get(JsonIt& it) { return it->toString(); }
};

template<>
struct QJsonUtil::JsonType<std::string> {
bool Check(JsonIt& it) { return it->isString(); }
std::string Get(JsonIt& it) { return tostdu8(it->toString()); }
};

template<>
struct QJsonUtil::JsonType<bool> {
bool Check(JsonIt& it) { return it->isBool(); }
bool Get(JsonIt& it) { return it->toBool(); }
};

0 comments on commit 3e82fd2

Please sign in to comment.