From 7117545fd6a33c86abf0adf8a3c817cb6bbb787b Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 26 Aug 2013 21:15:59 +0100 Subject: [PATCH] Operator function templates, using std::enable_if to match only classes derived from CStreamable, for streaming to/from QtDBusArgument, avoiding the unrelated operator function template for streaming Container defined by Qt, by being a better match in overload resolution. --- src/blackmisc/aviomodulator.h | 28 ---------------------------- src/blackmisc/geoearthangle.h | 28 ---------------------------- src/blackmisc/mathvector3dbase.h | 28 ---------------------------- src/blackmisc/streamable.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 84 deletions(-) diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index f8280bf18..3a39ee661 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -19,34 +19,6 @@ namespace Aviation */ template class CModulator : public CAvionicsBase { - /*! - * \brief Unmarshalling operator >>, DBus to object - * \param argument - * \param uc - * \return - */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, AVIO &uc) - { - // If I do not have the method here, DBus metasystem tries to stream against - // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) - // Once someone solves this, this methods should go and the - // CStreamable signature should be used - CStreamable &sf = uc; - return argument >> sf; - } - - /*! - * \brief Marshalling operator <<, object to DBus - * \param argument - * \param pq - * \return - */ - friend QDBusArgument &operator<<(QDBusArgument &argument, const AVIO &uc) - { - const CStreamable &sf = uc; - return argument << sf; - } - private: BlackMisc::PhysicalQuantities::CFrequency m_frequencyActive; //!< active frequency BlackMisc::PhysicalQuantities::CFrequency m_frequencyStandby; //!< standby frequency diff --git a/src/blackmisc/geoearthangle.h b/src/blackmisc/geoearthangle.h index 8cb2835ed..7491af0de 100644 --- a/src/blackmisc/geoearthangle.h +++ b/src/blackmisc/geoearthangle.h @@ -16,34 +16,6 @@ namespace Geo */ template class CEarthAngle : public BlackMisc::PhysicalQuantities::CAngle { - /*! - * \brief Unmarshalling operator >>, DBus to object - * \param argument - * \param uc - * \return - */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, LATorLON &uc) - { - // If I do not have the method here, DBus metasystem tries to stream against - // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) - // Once someone solves this, this methods should go and the - // CStreamable signature should be used - CStreamable &sf = uc; - return argument >> sf; - } - - /*! - * \brief Marshalling operator <<, object to DBus - * \param argument - * \param pq - * \return - */ - friend QDBusArgument &operator<<(QDBusArgument &argument, const LATorLON &uc) - { - const CStreamable &sf = uc; - return argument << sf; - } - protected: /*! * \brief Default constructor diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index 0d40cf8df..bd0bec9d7 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -21,34 +21,6 @@ class CMatrix3x1; */ template class CVector3DBase : public CStreamable { - /*! - * \brief Unmarshalling operator >>, DBus to object - * \param argument - * \param uc - * \return - */ - friend const QDBusArgument &operator>>(const QDBusArgument &argument, ImplVector &uc) - { - // If I do not have the method here, DBus metasystem tries to stream against - // a container: inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container &list) - // Once someone solves this, this methods should go and the - // CStreamable signature should be used - CStreamable &sf = uc; - return argument >> sf; - } - - /*! - * \brief Marshalling operator <<, object to DBus - * \param argument - * \param pq - * \return - */ - friend QDBusArgument &operator<<(QDBusArgument &argument, const ImplVector &uc) - { - const CStreamable &sf = uc; - return argument << sf; - } - private: /*! * \brief Easy access to derived class (CRTP template parameter) diff --git a/src/blackmisc/streamable.h b/src/blackmisc/streamable.h index 8ad890010..76f3881d6 100644 --- a/src/blackmisc/streamable.h +++ b/src/blackmisc/streamable.h @@ -168,6 +168,34 @@ protected: virtual void unmarshallFromDbus(const QDBusArgument &) = 0; }; +/*! + * Non-member non-friend operator for streaming T objects to QDBusArgument. + * Needed because we can't rely on the friend operator in some cases due to + * an unrelated template for streaming Container in QtDBus/qdbusargument.h + * which matches more types than it can actually handle. + * \param argument + * \param uc + */ +template typename std::enable_if::value, QDBusArgument>::type const& +operator>>(const QDBusArgument &argument, T &uc) +{ + return argument >> static_cast(uc); +} + +/*! + * Non-member non-friend operator for streaming T objects from QDBusArgument. + * Needed because we can't rely on the friend operator in some cases due to + * an unrelated template for streaming Container in QtDBus/qdbusargument.h + * which matches more types than it can actually handle. + * \param argument + * \param uc + */ +template typename std::enable_if::value, QDBusArgument>::type& +operator<<(QDBusArgument &argument, T &uc) +{ + return argument << static_cast(uc); +} + } // namespace #endif // guard