mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
removing/simplifying uses of enable_if for JSON streaming operators
This commit is contained in:
@@ -7,6 +7,115 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const QJsonValue &operator >>(const QJsonValue &json, int &value)
|
||||||
|
{
|
||||||
|
value = json.toInt();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValue &operator >>(const QJsonValue &json, qlonglong &value)
|
||||||
|
{
|
||||||
|
value = static_cast<qlonglong>(json.toInt());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValue &operator >>(const QJsonValue &json, qulonglong &value)
|
||||||
|
{
|
||||||
|
value = static_cast<qulonglong>(json.toInt());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValue &operator >>(const QJsonValue &json, uint &value)
|
||||||
|
{
|
||||||
|
value = static_cast<uint>(json.toInt());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValue &operator >>(const QJsonValue &json, qint16 &value)
|
||||||
|
{
|
||||||
|
value = static_cast<qint16>(json.toInt());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValue &operator >>(const QJsonValue &json, QString &value)
|
||||||
|
{
|
||||||
|
value = json.toString();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValue &operator >>(const QJsonValue &json, double &value)
|
||||||
|
{
|
||||||
|
value = json.toDouble();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValue &operator >>(const QJsonValue &json, bool &value)
|
||||||
|
{
|
||||||
|
value = json.toBool();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValue &operator >>(const QJsonValue &json, QDateTime &value)
|
||||||
|
{
|
||||||
|
value = QDateTime::fromString(json.toString());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, int &value)
|
||||||
|
{
|
||||||
|
value = json.toInt();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, qlonglong &value)
|
||||||
|
{
|
||||||
|
value = static_cast<qlonglong>(json.toInt());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, qulonglong &value)
|
||||||
|
{
|
||||||
|
value = static_cast<qulonglong>(json.toInt());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, uint &value)
|
||||||
|
{
|
||||||
|
value = static_cast<uint>(json.toInt());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, qint16 &value)
|
||||||
|
{
|
||||||
|
value = static_cast<qint16>(json.toInt());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, QString &value)
|
||||||
|
{
|
||||||
|
value = json.toString();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, double &value)
|
||||||
|
{
|
||||||
|
value = json.toDouble();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, bool &value)
|
||||||
|
{
|
||||||
|
value = json.toBool();
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, QDateTime &value)
|
||||||
|
{
|
||||||
|
value = QDateTime::fromString(json.toString());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray &operator<<(QJsonArray &json, const int value)
|
QJsonArray &operator<<(QJsonArray &json, const int value)
|
||||||
{
|
{
|
||||||
json.append(QJsonValue(value));
|
json.append(QJsonValue(value));
|
||||||
|
|||||||
@@ -25,71 +25,27 @@
|
|||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
//! \name Streaming operators for QJsonValue (to value)
|
//! \name Streaming operators for QJsonValue (to value)
|
||||||
//! \remarks JSONVALUE: QJsonValue / QJsonValueRef
|
//! \ingroup JSON
|
||||||
|
//! @{
|
||||||
template<class JSONVALUE> typename
|
const QJsonValue &operator >>(const QJsonValue &json, int &value);
|
||||||
std::enable_if < std::is_same<JSONVALUE, QJsonValue>::value || std::is_same<JSONVALUE, QJsonValueRef>::value, JSONVALUE >::type
|
const QJsonValue &operator >>(const QJsonValue &json, qlonglong &value);
|
||||||
const &operator>>(const JSONVALUE &json, int &value)
|
const QJsonValue &operator >>(const QJsonValue &json, qulonglong &value);
|
||||||
{
|
const QJsonValue &operator >>(const QJsonValue &json, uint &value);
|
||||||
value = json.toInt();
|
const QJsonValue &operator >>(const QJsonValue &json, qint16 &value);
|
||||||
return json;
|
const QJsonValue &operator >>(const QJsonValue &json, QString &value);
|
||||||
}
|
const QJsonValue &operator >>(const QJsonValue &json, double &value);
|
||||||
template<class JSONVALUE> typename
|
const QJsonValue &operator >>(const QJsonValue &json, bool &value);
|
||||||
std::enable_if < std::is_same<JSONVALUE, QJsonValue>::value || std::is_same<JSONVALUE, QJsonValueRef>::value, JSONVALUE >::type
|
const QJsonValue &operator >>(const QJsonValue &json, QDateTime &value);
|
||||||
const &operator>>(const JSONVALUE &json, qlonglong &value)
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, int &value);
|
||||||
{
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, qlonglong &value);
|
||||||
value = static_cast<qlonglong>(json.toInt());
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, qulonglong &value);
|
||||||
return json;
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, uint &value);
|
||||||
}
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, qint16 &value);
|
||||||
template<class JSONVALUE> typename
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, QString &value);
|
||||||
std::enable_if < std::is_same<JSONVALUE, QJsonValue>::value || std::is_same<JSONVALUE, QJsonValueRef>::value, JSONVALUE >::type
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, double &value);
|
||||||
const &operator>>(const JSONVALUE &json, qulonglong &value)
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, bool &value);
|
||||||
{
|
const QJsonValueRef &operator >>(const QJsonValueRef &json, QDateTime &value);
|
||||||
value = static_cast<qulonglong>(json.toInt());
|
//! @}
|
||||||
return json;
|
|
||||||
}
|
|
||||||
template<class JSONVALUE> typename
|
|
||||||
std::enable_if < std::is_same<JSONVALUE, QJsonValue>::value || std::is_same<JSONVALUE, QJsonValueRef>::value, JSONVALUE >::type
|
|
||||||
const &operator>>(const JSONVALUE &json, uint &value)
|
|
||||||
{
|
|
||||||
value = static_cast<uint>(json.toInt());
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
template<class JSONVALUE> typename
|
|
||||||
std::enable_if < std::is_same<JSONVALUE, QJsonValue>::value || std::is_same<JSONVALUE, QJsonValueRef>::value, JSONVALUE >::type
|
|
||||||
const &operator>>(const JSONVALUE &json, qint16 &value)
|
|
||||||
{
|
|
||||||
value = static_cast<qint16>(json.toInt());
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
template<class JSONVALUE> typename
|
|
||||||
std::enable_if < std::is_same<JSONVALUE, QJsonValue>::value || std::is_same<JSONVALUE, QJsonValueRef>::value, JSONVALUE >::type
|
|
||||||
const &operator>>(const JSONVALUE &json, QString &value)
|
|
||||||
{
|
|
||||||
value = json.toString();
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
template<class JSONVALUE> typename
|
|
||||||
std::enable_if < std::is_same<JSONVALUE, QJsonValue>::value || std::is_same<JSONVALUE, QJsonValueRef>::value, JSONVALUE >::type
|
|
||||||
const &operator>>(const JSONVALUE &json, double &value)
|
|
||||||
{
|
|
||||||
value = json.toDouble();
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
template<class JSONVALUE> typename
|
|
||||||
std::enable_if < std::is_same<JSONVALUE, QJsonValue>::value || std::is_same<JSONVALUE, QJsonValueRef>::value, JSONVALUE >::type
|
|
||||||
const &operator>>(const JSONVALUE &json, bool &value)
|
|
||||||
{
|
|
||||||
value = json.toBool();
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
template<class JSONVALUE> typename
|
|
||||||
std::enable_if < std::is_same<JSONVALUE, QJsonValue>::value || std::is_same<JSONVALUE, QJsonValueRef>::value, JSONVALUE >::type
|
|
||||||
const &operator>>(const JSONVALUE &json, QDateTime &value)
|
|
||||||
{
|
|
||||||
value = QDateTime::fromString(json.toString());
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \brief Specialized JSON serialization for enum
|
//! \brief Specialized JSON serialization for enum
|
||||||
//! \remarks needs to be in global namespace
|
//! \remarks needs to be in global namespace
|
||||||
@@ -104,9 +60,19 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! \brief Specialized JSON deserialization for enum
|
//! \brief Specialized JSON deserialization for enum
|
||||||
//! \ingroup JSON
|
//! \ingroup JSON
|
||||||
template<class JSONVALUE, class ENUM> typename
|
template<class ENUM> typename
|
||||||
std::enable_if < std::is_enum<ENUM>::value &&(std::is_same<JSONVALUE, QJsonValue>::value || std::is_same<JSONVALUE, QJsonValueRef>::value), JSONVALUE >::type
|
std::enable_if<std::is_enum<ENUM>::value, QJsonValue>::type
|
||||||
const &operator>>(const JSONVALUE &json, ENUM &value)
|
const &operator>>(const QJsonValue &json, ENUM &value)
|
||||||
|
{
|
||||||
|
value = static_cast<ENUM>(json.toInt());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \brief Specialized JSON deserialization for enum
|
||||||
|
//! \ingroup JSON
|
||||||
|
template<class ENUM> typename
|
||||||
|
std::enable_if<std::is_enum<ENUM>::value, QJsonValueRef>::type
|
||||||
|
const &operator>>(const QJsonValueRef &json, ENUM &value)
|
||||||
{
|
{
|
||||||
value = static_cast<ENUM>(json.toInt());
|
value = static_cast<ENUM>(json.toInt());
|
||||||
return json;
|
return json;
|
||||||
|
|||||||
Reference in New Issue
Block a user