From 0d306861f0fc0c3ab80dd5b43074ea009193d803 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 11 Mar 2014 21:08:59 +0100 Subject: [PATCH] refs #140, removed MACRO DBUS_ENUM_MARSHALLING, changed to template discussed in https://dev.vatsim-germany.org/issues/140#change-864 --- src/blackmisc/audiodevice.h | 5 ++--- src/blackmisc/avheading.cpp | 1 + src/blackmisc/avheading.h | 2 -- src/blackmisc/avinformationmessage.h | 2 -- src/blackmisc/aviocomsystem.cpp | 1 + src/blackmisc/aviocomsystem.h | 2 -- src/blackmisc/aviotransponder.h | 2 -- src/blackmisc/avtrack.cpp | 1 + src/blackmisc/avtrack.h | 2 -- src/blackmisc/blackmiscfreefunctions.h | 19 ------------------- src/blackmisc/hwkeyboardkey.h | 3 --- src/blackmisc/statusmessage.h | 3 --- src/blackmisc/valueobject.h | 16 ++++++++++++++++ 13 files changed, 21 insertions(+), 38 deletions(-) diff --git a/src/blackmisc/audiodevice.h b/src/blackmisc/audiodevice.h index ada6eb259..785374cf8 100644 --- a/src/blackmisc/audiodevice.h +++ b/src/blackmisc/audiodevice.h @@ -28,7 +28,7 @@ namespace BlackMisc public: //! \brief Type - enum DeviceType + enum DeviceType : uint { InputDevice, OutputDevice, @@ -135,10 +135,9 @@ namespace BlackMisc static QString hostName(); }; - } // Voice + } // Audio } // BlackMisc -BLACK_DBUS_ENUM_MARSHALLING(BlackMisc::Audio::CAudioDevice::DeviceType) BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Audio::CAudioDevice, (o.m_type, o.m_deviceIndex, o.m_deviceName, o.m_hostName)) Q_DECLARE_METATYPE(BlackMisc::Audio::CAudioDevice) diff --git a/src/blackmisc/avheading.cpp b/src/blackmisc/avheading.cpp index afe81b2da..9a948a034 100644 --- a/src/blackmisc/avheading.cpp +++ b/src/blackmisc/avheading.cpp @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "blackmiscfreefunctions.h" #include "avheading.h" using BlackMisc::PhysicalQuantities::CAngle; diff --git a/src/blackmisc/avheading.h b/src/blackmisc/avheading.h index bd5c9bcb2..31042c75a 100644 --- a/src/blackmisc/avheading.h +++ b/src/blackmisc/avheading.h @@ -6,7 +6,6 @@ #ifndef BLACKMISC_AVHEADING_H #define BLACKMISC_AVHEADING_H -#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/pqangle.h" namespace BlackMisc @@ -93,7 +92,6 @@ namespace BlackMisc } // namespace } // namespace -BLACK_DBUS_ENUM_MARSHALLING(BlackMisc::Aviation::CHeading::ReferenceNorth) BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CHeading, (o.m_north)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CHeading) diff --git a/src/blackmisc/avinformationmessage.h b/src/blackmisc/avinformationmessage.h index bc327ab78..5fbf12cee 100644 --- a/src/blackmisc/avinformationmessage.h +++ b/src/blackmisc/avinformationmessage.h @@ -10,7 +10,6 @@ #ifndef BLACKMISC_INFORMATIONMESSAGE_H #define BLACKMISC_INFORMATIONMESSAGE_H -#include "blackmiscfreefunctions.h" #include "valueobject.h" #include #include @@ -196,7 +195,6 @@ namespace BlackMisc } // namespace } // namespace -BLACK_DBUS_ENUM_MARSHALLING(BlackMisc::Aviation::CInformationMessage::InformationType) BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CInformationMessage, (o.m_type, o.m_message, o.m_receivedTimestamp)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CInformationMessage) diff --git a/src/blackmisc/aviocomsystem.cpp b/src/blackmisc/aviocomsystem.cpp index f0b4e568b..51cf9df11 100644 --- a/src/blackmisc/aviocomsystem.cpp +++ b/src/blackmisc/aviocomsystem.cpp @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/aviocomsystem.h" using namespace BlackMisc::PhysicalQuantities; diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index 9d6d742f7..e603f7dcf 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -6,7 +6,6 @@ #ifndef BLACKMISC_AVIOCOMSYSTEM_H #define BLACKMISC_AVIOCOMSYSTEM_H #include "blackmisc/aviomodulator.h" -#include "blackmisc/blackmiscfreefunctions.h" #include namespace BlackMisc @@ -359,7 +358,6 @@ namespace BlackMisc } // namespace } // namespace -BLACK_DBUS_ENUM_MARSHALLING(BlackMisc::Aviation::CComSystem::ChannelSpacing) BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CComSystem, (o.m_channelSpacing)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CComSystem) diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index 7f68bf2f8..c5e0b3298 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -6,7 +6,6 @@ #ifndef BLACKMISC_AVIOTRANSPONDER_H #define BLACKMISC_AVIOTRANSPONDER_H #include "blackmisc/aviobase.h" -#include "blackmisc/blackmiscfreefunctions.h" #include namespace BlackMisc @@ -390,7 +389,6 @@ namespace BlackMisc } // namespace } // namespace -BLACK_DBUS_ENUM_MARSHALLING(BlackMisc::Aviation::CTransponder::TransponderMode) BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CTransponder, (o.m_transponderCode)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CTransponder) diff --git a/src/blackmisc/avtrack.cpp b/src/blackmisc/avtrack.cpp index 19ce2e965..32c0a3d29 100644 --- a/src/blackmisc/avtrack.cpp +++ b/src/blackmisc/avtrack.cpp @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "blackmiscfreefunctions.h" #include "avtrack.h" using BlackMisc::PhysicalQuantities::CAngle; diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index 98e923ae3..d55a656f7 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -6,7 +6,6 @@ #ifndef BLACKMISC_AVTRACK_H #define BLACKMISC_AVTRACK_H -#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/pqangle.h" namespace BlackMisc @@ -108,7 +107,6 @@ namespace BlackMisc } // namespace } // namespace -BLACK_DBUS_ENUM_MARSHALLING(BlackMisc::Aviation::CTrack::ReferenceNorth) BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CTrack, (o.m_north)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CTrack) diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h index 5c4d3f3b2..45f568661 100644 --- a/src/blackmisc/blackmiscfreefunctions.h +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -198,23 +198,4 @@ namespace BlackMisc } // BlackMisc -/*! - * \brief Macro to make a ENUMs DBus streamable. - * \details Put this macro outside of any namespace, in the same header as the class defining the enumeration. - * \param ENUM The fully qualified name of the enumeration. - * \hideinitializer - * \ingroup Tuples - */ -#define BLACK_DBUS_ENUM_MARSHALLING(ENUM) \ - namespace BlackMisc \ - { \ - inline const QDBusArgument &operator >>(const QDBusArgument &arg, ENUM &enumType) \ - { \ - uint e; \ - arg >> e; \ - enumType = static_cast(e); \ - return arg; \ - }; \ - } - #endif // guard diff --git a/src/blackmisc/hwkeyboardkey.h b/src/blackmisc/hwkeyboardkey.h index 3353b6796..4e482b4b8 100644 --- a/src/blackmisc/hwkeyboardkey.h +++ b/src/blackmisc/hwkeyboardkey.h @@ -10,7 +10,6 @@ #ifndef BLACKMISC_KEYBOARDKEY_H #define BLACKMISC_KEYBOARDKEY_H -#include "blackmiscfreefunctions.h" #include "valueobject.h" #include #include @@ -257,8 +256,6 @@ namespace BlackMisc } // class } // BlackMisc -BLACK_DBUS_ENUM_MARSHALLING(BlackMisc::Hardware::CKeyboardKey::Modifier) -BLACK_DBUS_ENUM_MARSHALLING(BlackMisc::Hardware::CKeyboardKey::HotkeyFunction) BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Hardware::CKeyboardKey, (o.m_qtKey, o.m_nativeScanCode, o.m_nativeVirtualKey, o.m_modifier1, o.m_modifier2, o.m_function, o.m_pressed)) Q_DECLARE_METATYPE(BlackMisc::Hardware::CKeyboardKey) diff --git a/src/blackmisc/statusmessage.h b/src/blackmisc/statusmessage.h index 5e9c03372..4c9328b73 100644 --- a/src/blackmisc/statusmessage.h +++ b/src/blackmisc/statusmessage.h @@ -1,7 +1,6 @@ #ifndef BLACKMISC_STATUSMESSAGE_H #define BLACKMISC_STATUSMESSAGE_H -#include "blackmiscfreefunctions.h" #include "valueobject.h" #include @@ -150,8 +149,6 @@ namespace BlackMisc }; } -BLACK_DBUS_ENUM_MARSHALLING(BlackMisc::CStatusMessage::StatusSeverity) -BLACK_DBUS_ENUM_MARSHALLING(BlackMisc::CStatusMessage::StatusType) BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CStatusMessage, (o.m_type, o.m_severity, o.m_message, o.m_timestamp)) Q_DECLARE_METATYPE(BlackMisc::CStatusMessage) diff --git a/src/blackmisc/valueobject.h b/src/blackmisc/valueobject.h index fd79944ab..dac085bf2 100644 --- a/src/blackmisc/valueobject.h +++ b/src/blackmisc/valueobject.h @@ -297,6 +297,22 @@ namespace BlackMisc return argument >> static_cast(valueObject); } + /*! + * Non-member non-friend operator for streaming enums to QDBusArgument. + * + * \param argument + * \param enumType + * \return + */ + template typename std::enable_if::value, QDBusArgument>::type const & + operator>>(const QDBusArgument &argument, ENUM &enumType) + { + uint e; + argument>> e; + enumType = static_cast(e); + return argument; + } + /*! * 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