mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 23:45:35 +08:00
refs #245 removed nested tie workarounds for tuples with >10 members
This commit is contained in:
@@ -339,7 +339,7 @@ namespace BlackMisc
|
||||
} // namespace
|
||||
|
||||
// o.m_metar, o.m_voiceRoom
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAtcStation, (o.m_callsign, o.m_controller, o.m_frequency, o.m_position, o.m_range, o.m_isOnline, o.m_distanceToPlane, o.m_atis, o.m_bookedFromUtc, tie(o.m_bookedUntilUtc, o.m_metar, o.m_voiceRoom)))
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAtcStation, (o.m_callsign, o.m_controller, o.m_frequency, o.m_position, o.m_range, o.m_isOnline, o.m_distanceToPlane, o.m_atis, o.m_bookedFromUtc, o.m_bookedUntilUtc, o.m_metar, o.m_voiceRoom))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CAtcStation)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -239,6 +239,6 @@ namespace BlackMisc
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CFlightPlan)
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CFlightPlan, (o.m_equipmentIcao, o.m_originAirportIcao, o.m_destinationAirportIcao, o.m_alternateAirportIcao,
|
||||
o.m_takeoffTimePlanned, o.m_takeoffTimeActual, o.m_enrouteTime, o.m_fuelTime, o.m_cruiseAltitude, tie(o.m_cruiseTrueAirspeed, o.m_flightRules, o.m_route, o.m_remarks, o.m_lastSentOrLoaded)))
|
||||
o.m_takeoffTimePlanned, o.m_takeoffTimeActual, o.m_enrouteTime, o.m_fuelTime, o.m_cruiseAltitude, o.m_cruiseTrueAirspeed, o.m_flightRules, o.m_route, o.m_remarks, o.m_lastSentOrLoaded))
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -164,11 +164,7 @@ namespace BlackMisc
|
||||
using ::qHash;
|
||||
|
||||
/*!
|
||||
* \brief Works like std::tie but with special handling for any argument which are tuples.
|
||||
* \details Returns a tuple of references to its arguments which can be used in the same way as
|
||||
* std::tie, except for arguments which are themselves tuples. Arguments which are tuples
|
||||
* are copied into the result tuple by value. This enables nesting of calls to tie within
|
||||
* other calls to tie, to workaround implementations which have a maximum tuple size.
|
||||
* \brief Works like std::tie, and allows us to hook in our own customizations.
|
||||
*/
|
||||
template <class... Ts>
|
||||
auto tie(Ts &&... args) -> decltype(std::make_tuple(Private::tieHelper(args)...))
|
||||
|
||||
@@ -30,15 +30,6 @@ namespace BlackMisc
|
||||
namespace Private
|
||||
{
|
||||
|
||||
// Helper trait to detect whether a class is a tuple.
|
||||
//! \private
|
||||
//! @{
|
||||
template <class T>
|
||||
struct IsTuple : public std::false_type {};
|
||||
template <class... Ts>
|
||||
struct IsTuple<std::tuple<Ts...>> : public std::true_type {};
|
||||
//! @}
|
||||
|
||||
// Using SFINAE to help detect missing BLACK_ENABLE_TUPLE_CONVERSION macro in static_assert
|
||||
//! \private
|
||||
std::false_type hasEnabledTupleConversionHelper(...);
|
||||
@@ -78,53 +69,18 @@ namespace BlackMisc
|
||||
int compareHelper(const Tu &a, const Tu &b)
|
||||
{
|
||||
typedef typename std::decay<typename std::tuple_element<N, Tu>::type>::type Element;
|
||||
typedef std::integral_constant<bool, std::is_base_of<CValueObject, Element>::value || IsTuple<Element>::value> isCValueObjectTag;
|
||||
|
||||
return compareHelper(std::get<N>(a), std::get<N>(b), isCValueObjectTag());
|
||||
return compareHelper(std::get<N>(a), std::get<N>(b), typename std::is_base_of<CValueObject, Element>::type());
|
||||
}
|
||||
//! @}
|
||||
|
||||
// Helper which returns a copy of its argument if it's a tuple,
|
||||
// otherwise returns a reference to its argument.
|
||||
// Helper which will allow us to hook in our own customizations into BlackMisc::tie
|
||||
//! \private
|
||||
//! @{
|
||||
template <class T>
|
||||
auto tieHelper(T &obj, std::false_type isTupleTag) -> std::reference_wrapper<T>
|
||||
std::reference_wrapper<T> tieHelper(T &obj)
|
||||
{
|
||||
Q_UNUSED(isTupleTag);
|
||||
return obj;
|
||||
}
|
||||
template <class T>
|
||||
auto tieHelper(T &obj, std::true_type isTupleTag) -> T
|
||||
{
|
||||
Q_UNUSED(isTupleTag);
|
||||
return obj;
|
||||
}
|
||||
template <class T>
|
||||
auto tieHelper(T &obj) -> decltype(tieHelper(obj, IsTuple<T>()))
|
||||
{
|
||||
return tieHelper(obj, IsTuple<T>());
|
||||
}
|
||||
//! @}
|
||||
|
||||
// Helper which (de)serializes its argument to/from JSON,
|
||||
// whether it is a simple value or a nested tuple.
|
||||
// Defined later because it uses TupleHelper;
|
||||
// forward-declared because TupleHelper uses it.
|
||||
//! \private
|
||||
//! @{
|
||||
template <class T>
|
||||
static void serializeJsonHelper(QJsonObject &json, const QStringList &members, const T &obj, int index, std::false_type isNestedTag);
|
||||
template <class T>
|
||||
static void serializeJsonHelper(QJsonObject &json, const QStringList &members, const T &obj, int index, std::true_type isNestedTag);
|
||||
template <class T>
|
||||
static void serializeJsonHelper(QJsonObject &json, const QStringList &members, const T &obj, int index);
|
||||
template <class T>
|
||||
static void deserializeJsonHelper(const QJsonObject &json, const QStringList &members, T &obj, int index, std::false_type isNestedTag);
|
||||
template <class T>
|
||||
static void deserializeJsonHelper(const QJsonObject &json, const QStringList &members, T &obj, int index, std::true_type isNestedTag);
|
||||
template <class T>
|
||||
static void deserializeJsonHelper(const QJsonObject &json, const QStringList &members, T &obj, int index);
|
||||
//! @}
|
||||
|
||||
// Applying operations to all elements in a tuple, using recursion
|
||||
@@ -168,14 +124,14 @@ namespace BlackMisc
|
||||
static void serializeJson(QJsonObject &json, const QStringList &members, const Tu &tu)
|
||||
{
|
||||
TupleHelper < N - 1 >::serializeJson(json, members, tu);
|
||||
serializeJsonHelper(json, members, std::get < N - 1 > (tu), N - 1);
|
||||
json << std::make_pair(members.at(N - 1), std::get < N - 1 >(tu));
|
||||
}
|
||||
|
||||
template <class Tu>
|
||||
static void deserializeJson(const QJsonObject &json, const QStringList &members, Tu &tu)
|
||||
{
|
||||
TupleHelper < N - 1 >::deserializeJson(json, members, tu);
|
||||
deserializeJsonHelper(json, members, std::get < N - 1 > (tu), N - 1);
|
||||
json.value(members.at(N - 1)) >> std::get < N - 1 >(tu);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -199,42 +155,6 @@ namespace BlackMisc
|
||||
static void deserializeJson(const QJsonObject &, const QStringList &, Tu &) {}
|
||||
};
|
||||
|
||||
// definitions of helpers declared earlier
|
||||
template <class T>
|
||||
static void serializeJsonHelper(QJsonObject &json, const QStringList &members, const T &obj, int index, std::false_type isNestedTag)
|
||||
{
|
||||
Q_UNUSED(isNestedTag);
|
||||
json << std::make_pair(members.at(index), obj);
|
||||
}
|
||||
template <class T>
|
||||
static void serializeJsonHelper(QJsonObject &json, const QStringList &members, const T &obj, int index, std::true_type isNestedTag)
|
||||
{
|
||||
Q_UNUSED(isNestedTag);
|
||||
TupleHelper<std::tuple_size<T>::value>::serializeJson(json, members.mid(index), obj);
|
||||
}
|
||||
template <class T>
|
||||
static void serializeJsonHelper(QJsonObject &json, const QStringList &members, const T &obj, int index)
|
||||
{
|
||||
serializeJsonHelper(json, members, obj, index, IsTuple<T>());
|
||||
}
|
||||
template <class T>
|
||||
static void deserializeJsonHelper(const QJsonObject &json, const QStringList &members, T &obj, int index, std::false_type isNestedTag)
|
||||
{
|
||||
Q_UNUSED(isNestedTag);
|
||||
json.value(members.at(index)) >> obj;
|
||||
}
|
||||
template <class T>
|
||||
static void deserializeJsonHelper(const QJsonObject &json, const QStringList &members, T &obj, int index, std::true_type isNestedTag)
|
||||
{
|
||||
Q_UNUSED(isNestedTag);
|
||||
TupleHelper<std::tuple_size<T>::value>::deserializeJson(json, members.mid(index), obj);
|
||||
}
|
||||
template <class T>
|
||||
static void deserializeJsonHelper(const QJsonObject &json, const QStringList &members, T &obj, int index)
|
||||
{
|
||||
deserializeJsonHelper(json, members, obj, index, IsTuple<T>());
|
||||
}
|
||||
|
||||
} // namespace Private
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace BlackSim
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackSim::FsCommon::CAircraftMapping, (o.m_mappingId, o.m_proposalId, o.m_fsAircraftKey, o.m_aircraftDesignator, o.m_airlineDesignator, o.m_aircraftCombinedType, o.m_wakeTurbulenceCategory, o.m_aircraftColor, o.m_lastChanged, tie(o.m_simulatorInfo, o.m_changed)))
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackSim::FsCommon::CAircraftMapping, (o.m_mappingId, o.m_proposalId, o.m_fsAircraftKey, o.m_aircraftDesignator, o.m_airlineDesignator, o.m_aircraftCombinedType, o.m_wakeTurbulenceCategory, o.m_aircraftColor, o.m_lastChanged, o.m_simulatorInfo, o.m_changed))
|
||||
Q_DECLARE_METATYPE(BlackSim::FsCommon::CAircraftMapping)
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user