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<T>
defined by Qt, by being a better match in overload resolution.
This commit is contained in:
Mathew Sutcliffe
2013-08-26 21:15:59 +01:00
parent ea4d0dedbb
commit 7117545fd6
4 changed files with 28 additions and 84 deletions

View File

@@ -19,34 +19,6 @@ namespace Aviation
*/
template <class AVIO> 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<T> &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

View File

@@ -16,34 +16,6 @@ namespace Geo
*/
template <class LATorLON> 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<T> &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

View File

@@ -21,34 +21,6 @@ class CMatrix3x1;
*/
template <class ImplVector> 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<T> &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)

View File

@@ -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<T> in QtDBus/qdbusargument.h
* which matches more types than it can actually handle.
* \param argument
* \param uc
*/
template <class T> typename std::enable_if<std::is_base_of<CStreamable, T>::value, QDBusArgument>::type const&
operator>>(const QDBusArgument &argument, T &uc)
{
return argument >> static_cast<CStreamable&>(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<T> in QtDBus/qdbusargument.h
* which matches more types than it can actually handle.
* \param argument
* \param uc
*/
template <class T> typename std::enable_if<std::is_base_of<CStreamable, T>::value, QDBusArgument>::type&
operator<<(QDBusArgument &argument, T &uc)
{
return argument << static_cast<CStreamable const&>(uc);
}
} // namespace
#endif // guard