From 34320ad3e10fa1e50bb760bb05e3d007499144ee Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 10 Mar 2014 14:48:56 +0100 Subject: [PATCH] refs #140, changed CValueObject classes to tupel concept Remarks: Changes looking like an added file result from the shift of namespace voice -> audio --- src/blackmisc/audiodevice.cpp | 140 ++++++++++++++++++ src/blackmisc/audiodevice.h | 145 +++++++++++++++++++ src/blackmisc/avaircraft.cpp | 33 +---- src/blackmisc/avaircraft.h | 4 +- src/blackmisc/avaircraftsituation.cpp | 38 +---- src/blackmisc/avaircraftsituation.h | 2 + src/blackmisc/avatcstation.cpp | 119 +++++----------- src/blackmisc/avatcstation.h | 11 +- src/blackmisc/avcallsign.cpp | 74 +++++----- src/blackmisc/avcallsign.h | 2 + src/blackmisc/avheading.cpp | 38 +++-- src/blackmisc/avheading.h | 15 +- src/blackmisc/avinformationmessage.cpp | 36 ++--- src/blackmisc/avinformationmessage.h | 4 + src/blackmisc/avioadfsystem.h | 2 +- src/blackmisc/aviobase.cpp | 34 +++++ src/blackmisc/aviobase.h | 86 ++++------- src/blackmisc/aviocomsystem.cpp | 77 ++++++---- src/blackmisc/aviocomsystem.h | 58 +++----- src/blackmisc/aviomodulator.cpp | 38 +++-- src/blackmisc/aviomodulator.h | 8 ++ src/blackmisc/avionavsystem.h | 2 +- src/blackmisc/aviotransponder.cpp | 33 +++-- src/blackmisc/aviotransponder.h | 25 ++-- src/blackmisc/avselcal.cpp | 68 ++++----- src/blackmisc/avselcal.h | 2 + src/blackmisc/avtrack.cpp | 38 +++-- src/blackmisc/avtrack.h | 58 +++----- src/blackmisc/coordinateecef.h | 38 ++--- src/blackmisc/coordinatened.cpp | 56 ++++++++ src/blackmisc/coordinatened.h | 31 ++-- src/blackmisc/geoearthangle.cpp | 7 +- src/blackmisc/geolatitude.h | 1 - src/blackmisc/hwkeyboardkey.cpp | 97 ++++++------- src/blackmisc/hwkeyboardkey.h | 8 ++ src/blackmisc/nwserver.h | 95 +++---------- src/blackmisc/nwtextmessage.cpp | 89 +++++------- src/blackmisc/nwtextmessage.h | 2 + src/blackmisc/nwuser.cpp | 16 +-- src/blackmisc/statusmessage.cpp | 93 +++++------- src/blackmisc/statusmessage.h | 5 + src/blackmisc/voiceroom.cpp | 144 +++++++++++++++++++ src/blackmisc/voiceroom.h | 189 +++++++++++++++++++++++++ 43 files changed, 1293 insertions(+), 768 deletions(-) create mode 100644 src/blackmisc/audiodevice.cpp create mode 100644 src/blackmisc/audiodevice.h create mode 100644 src/blackmisc/aviobase.cpp create mode 100644 src/blackmisc/coordinatened.cpp create mode 100644 src/blackmisc/voiceroom.cpp create mode 100644 src/blackmisc/voiceroom.h diff --git a/src/blackmisc/audiodevice.cpp b/src/blackmisc/audiodevice.cpp new file mode 100644 index 000000000..321177624 --- /dev/null +++ b/src/blackmisc/audiodevice.cpp @@ -0,0 +1,140 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +/*! + \file +*/ + +#include "audiodevice.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include +#include + +namespace BlackMisc +{ + namespace Audio + { + /* + * Constructor + */ + CAudioDevice::CAudioDevice() : + m_type(Unknown), m_deviceIndex(invalidDeviceIndex()), + m_deviceName(""), m_hostName(CAudioDevice::hostName()) + { + // void + } + + /* + * Constructor + */ + CAudioDevice::CAudioDevice(DeviceType type, const qint16 index, const QString &name) : + m_type(type), m_deviceIndex(index), + m_deviceName(name), m_hostName(CAudioDevice::hostName()) + { + // void + } + + /* + * Host name + */ + QString CAudioDevice::hostName() + { + QHostInfo hostInfo = QHostInfo::fromName(QHostInfo::localHostName()); + return hostInfo.localHostName(); + } + + /* + * Compare + */ + int CAudioDevice::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + /* + * Marshall to DBus + */ + void CAudioDevice::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall from DBus + */ + void CAudioDevice::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + + /* + * Hash + */ + uint CAudioDevice::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + + /* + * Equal? + */ + bool CAudioDevice::operator ==(const CAudioDevice &other) const + { + if (this == &other) return true; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); + } + + + /* + * Unequal? + */ + bool CAudioDevice::operator !=(const CAudioDevice &other) const + { + return !((*this) == other); + } + + /* + * As String + */ + QString CAudioDevice::convertToQString(bool /* i18n */) const + { + if (this->m_hostName.isEmpty()) return m_deviceName; + QString s(this->m_deviceName); + s.append(" ["); + s.append(this->hostName()); + s.append("]"); + return s; + } + + /* + * metaTypeId + */ + int CAudioDevice::getMetaTypeId() const + { + return qMetaTypeId(); + } + + /* + * is a + */ + bool CAudioDevice::isA(int metaTypeId) const + { + if (metaTypeId == qMetaTypeId()) { return true; } + + return this->CValueObject::isA(metaTypeId); + } + + /* + * Register + */ + void CAudioDevice::registerMetadata() + { + qRegisterMetaType(); + qDBusRegisterMetaType(); + } + + } // Voice +} // BlackMisc diff --git a/src/blackmisc/audiodevice.h b/src/blackmisc/audiodevice.h new file mode 100644 index 000000000..ada6eb259 --- /dev/null +++ b/src/blackmisc/audiodevice.h @@ -0,0 +1,145 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +#ifndef BLACKMISC_AUDIODEVICE_H +#define BLACKMISC_AUDIODEVICE_H + +/*! + \file +*/ + +#include "blackmiscfreefunctions.h" +#include "valueobject.h" +#include + +namespace BlackMisc +{ + namespace Audio + { + /*! + * Value object encapsulating information of a audio device. + * If you want to safe this object, use the name instead of the index, since the index can change after + * a restart. + */ + class CAudioDevice : public BlackMisc::CValueObject + { + public: + + //! \brief Type + enum DeviceType + { + InputDevice, + OutputDevice, + Unknown + }; + + /*! + * Default constructor. + * If m_deviceIndex is -1, default should be used. However on Windows this doesnt work. Needs + * to be checked in Vatlib. + */ + CAudioDevice(); + + //! \brief Constructor. + CAudioDevice(DeviceType type, const qint16 index, const QString &getName); + + //! \copydoc CValueObject::toQVariant + virtual QVariant toQVariant() const override + { + return QVariant::fromValue(*this); + } + + //! \brief Get the device index + qint16 getIndex() const { return m_deviceIndex; } + + //! Get the device name + const QString &getName() const { return m_deviceName; } + + //! \brief Type + DeviceType getType() const { return m_type; } + + //! \brief Valid audio device object? + bool isValid() const { return m_deviceIndex >= -1 && !m_deviceName.isEmpty(); } + + //! \brief Equal operator == + bool operator ==(const CAudioDevice &other) const; + + //! \brief Unequal operator != + bool operator !=(const CAudioDevice &other) const; + + //! \copydoc CValueObject::getValueHash + virtual uint getValueHash() const override; + + //! \brief Register metadata + static void registerMetadata(); + + //! \brief Device index for default device + static qint16 defaultDeviceIndex() {return -1;} + + //! \brief Invalid device index + static qint16 invalidDeviceIndex() {return -2;} + + //! \brief default output device + static CAudioDevice getDefaultOutputDevice() + { + return CAudioDevice(OutputDevice, defaultDeviceIndex(), "default"); + } + + //! \brief default input device + static CAudioDevice getDefaultInputDevice() + { + return CAudioDevice(InputDevice, defaultDeviceIndex(), "default"); + } + + protected: + + //! \copydoc CValueObject::convertToQString + virtual QString convertToQString(bool i18n = false) const override; + + //! \copydoc CValueObject::getMetaTypeId + virtual int getMetaTypeId() const override; + + //! \copydoc CValueObject::isA + virtual bool isA(int metaTypeId) const override; + + //! \copydoc CValueObject::compareImpl + virtual int compareImpl(const CValueObject &other) const override; + + //! \copydoc CValueObject::marshallToDbus() + virtual void marshallToDbus(QDBusArgument &argument) const override; + + //! \copydoc CValueObject::unmarshallFromDbus() + virtual void unmarshallFromDbus(const QDBusArgument &argument) override; + + private: + BLACK_ENABLE_TUPLE_CONVERSION(CAudioDevice) + //! \brief Device type, @see CAudioDevice::DeviceType + DeviceType m_type; + /*! + * deviceIndex is the number is the reference for the VVL. The device is selected by this index. + * The managing class needs to take care, that indexes are valid. + */ + qint16 m_deviceIndex; + //! \brief Device name + QString m_deviceName; + //! \brief We use a DBus based system. Hence an audio device can reside on a differen computers, this here is its name + QString m_hostName; + + private: + /*! + * \brief Own host name + * \return + */ + static QString hostName(); + }; + + } // Voice +} // 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) + +#endif // guard diff --git a/src/blackmisc/avaircraft.cpp b/src/blackmisc/avaircraft.cpp index 749e29163..2eb12360c 100644 --- a/src/blackmisc/avaircraft.cpp +++ b/src/blackmisc/avaircraft.cpp @@ -27,14 +27,7 @@ namespace BlackMisc */ void CAircraft::marshallToDbus(QDBusArgument &argument) const { - argument << this->m_callsign; - argument << this->m_pilot; - argument << this->m_situation; - argument << this->m_com1system; - argument << this->m_com2system; - argument << this->m_transponder; - argument << this->m_icao; - argument << this->m_distanceToPlane; + argument << TupleConverter::toTuple(*this); } /* @@ -42,14 +35,7 @@ namespace BlackMisc */ void CAircraft::unmarshallFromDbus(const QDBusArgument &argument) { - argument >> this->m_callsign; - argument >> this->m_pilot; - argument >> this->m_situation; - argument >> this->m_com1system; - argument >> this->m_com2system; - argument >> this->m_transponder; - argument >> this->m_icao; - argument >> this->m_distanceToPlane; + argument >> TupleConverter::toTuple(*this); } /* @@ -97,7 +83,7 @@ namespace BlackMisc bool CAircraft::operator ==(const CAircraft &other) const { if (this == &other) return true; - return compare(*this, other) == 0; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } /* @@ -113,15 +99,7 @@ namespace BlackMisc */ uint CAircraft::getValueHash() const { - QList hashs; - hashs << qHash(this->m_callsign); - hashs << qHash(this->m_pilot); - hashs << qHash(this->m_situation); - hashs << qHash(this->m_com1system); - hashs << qHash(this->m_com2system); - hashs << qHash(this->m_transponder); - hashs << qHash(this->m_icao); - return BlackMisc::calculateHash(hashs, "CAircraft"); + return qHash(TupleConverter::toTuple(*this)); } /* @@ -148,8 +126,7 @@ namespace BlackMisc int CAircraft::compareImpl(const CValueObject &otherBase) const { const auto &other = static_cast(otherBase); - - return this->getCallsign().asString().compare(other.getCallsign().asString(), Qt::CaseInsensitive); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); } /* diff --git a/src/blackmisc/avaircraft.h b/src/blackmisc/avaircraft.h index 819f0dc60..3acc16286 100644 --- a/src/blackmisc/avaircraft.h +++ b/src/blackmisc/avaircraft.h @@ -31,7 +31,7 @@ namespace BlackMisc CAircraft() : m_distanceToPlane(-1.0, BlackMisc::PhysicalQuantities::CLengthUnit::NM()) {} //! \brief Constructor. - CAircraft(const QString &callsign, const BlackMisc::Network::CUser &user, const CAircraftSituation &situation) + CAircraft(const CCallsign &callsign, const BlackMisc::Network::CUser &user, const CAircraftSituation &situation) : m_callsign(callsign), m_pilot(user), m_situation(situation), m_distanceToPlane(-1.0, BlackMisc::PhysicalQuantities::CLengthUnit::NM()) {} //! \copydoc CValueObject::toQVariant @@ -235,6 +235,7 @@ namespace BlackMisc virtual void unmarshallFromDbus(const QDBusArgument &argument) override; private: + BLACK_ENABLE_TUPLE_CONVERSION(CAircraft) CCallsign m_callsign; BlackMisc::Network::CUser m_pilot; CAircraftSituation m_situation; @@ -248,6 +249,7 @@ namespace BlackMisc } // namespace } // namespace +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAircraft, (o.m_callsign, o.m_pilot, o.m_situation, o.m_com1system, o.m_com2system, o.m_transponder, o.m_icao, o.m_distanceToPlane)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CAircraft) #endif // guard diff --git a/src/blackmisc/avaircraftsituation.cpp b/src/blackmisc/avaircraftsituation.cpp index c64502153..ae10bbd88 100644 --- a/src/blackmisc/avaircraftsituation.cpp +++ b/src/blackmisc/avaircraftsituation.cpp @@ -48,16 +48,7 @@ namespace BlackMisc { const auto &other = static_cast(otherBase); - int result; - if ((result = compare(this->m_position, other.m_position))) { return result; } - if ((result = compare(this->m_altitude, other.m_altitude))) { return result; } - if ((result = compare(this->m_heading, other.m_heading))) { return result; } - if ((result = compare(this->m_pitch, other.m_pitch))) { return result; } - if ((result = compare(this->m_bank, other.m_bank))) { return result; } - if ((result = compare(this->m_groundspeed, other.m_groundspeed))) { return result; } - if (this->m_timestamp < other.m_timestamp) { return -1; } - if (this->m_timestamp > other.m_timestamp) { return 1; } - return 0; + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); } /* @@ -65,13 +56,7 @@ namespace BlackMisc */ void CAircraftSituation::marshallToDbus(QDBusArgument &argument) const { - argument << this->m_position; - argument << this->m_altitude; - argument << this->m_heading; - argument << this->m_pitch; - argument << this->m_bank; - argument << this->m_groundspeed; - argument << this->m_timestamp; + argument << TupleConverter::toTuple(*this); } /* @@ -79,13 +64,7 @@ namespace BlackMisc */ void CAircraftSituation::unmarshallFromDbus(const QDBusArgument &argument) { - argument >> this->m_position; - argument >> this->m_altitude; - argument >> this->m_heading; - argument >> this->m_pitch; - argument >> this->m_bank; - argument >> this->m_groundspeed; - argument >> this->m_timestamp; + argument >> TupleConverter::toTuple(*this); } /* @@ -94,7 +73,7 @@ namespace BlackMisc bool CAircraftSituation::operator ==(const CAircraftSituation &other) const { if (this == &other) return true; - return compare(*this, other) == 0; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } /* @@ -110,14 +89,7 @@ namespace BlackMisc */ uint CAircraftSituation::getValueHash() const { - QList hashs; - hashs << qHash(this->m_position); - hashs << qHash(this->m_altitude); - hashs << qHash(this->m_heading); - hashs << qHash(this->m_groundspeed); - hashs << qHash(this->m_pitch); - hashs << qHash(this->m_bank); - return BlackMisc::calculateHash(hashs, "CAircraftSituation"); + return qHash(TupleConverter::toTuple(*this)); } /* diff --git a/src/blackmisc/avaircraftsituation.h b/src/blackmisc/avaircraftsituation.h index 8e41b6ff9..865f544eb 100644 --- a/src/blackmisc/avaircraftsituation.h +++ b/src/blackmisc/avaircraftsituation.h @@ -153,6 +153,7 @@ namespace BlackMisc virtual void unmarshallFromDbus(const QDBusArgument &argument) override; private: + BLACK_ENABLE_TUPLE_CONVERSION(CAircraftSituation) BlackMisc::Geo::CCoordinateGeodetic m_position; BlackMisc::Aviation::CAltitude m_altitude; BlackMisc::Aviation::CHeading m_heading; @@ -165,6 +166,7 @@ namespace BlackMisc } // namespace } // namespace +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAircraftSituation, (o.m_position, o.m_altitude, o.m_heading, o.m_pitch, o.m_bank, o.m_groundspeed)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CAircraftSituation) #endif // guard diff --git a/src/blackmisc/avatcstation.cpp b/src/blackmisc/avatcstation.cpp index 42c30bcf4..66de8b70b 100644 --- a/src/blackmisc/avatcstation.cpp +++ b/src/blackmisc/avatcstation.cpp @@ -1,12 +1,12 @@ #include "avatcstation.h" #include "aviocomsystem.h" -#include "vvoiceroom.h" +#include "voiceroom.h" #include "blackmiscfreefunctions.h" using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Geo; using namespace BlackMisc::Network; -using namespace BlackMisc::Voice; +using namespace BlackMisc::Audio; namespace BlackMisc { @@ -147,44 +147,6 @@ namespace BlackMisc (void)QT_TRANSLATE_NOOP("Network", "voiceroom"); } - /* - * Marshall to DBus - */ - void CAtcStation::marshallToDbus(QDBusArgument &argument) const - { - argument << this->m_callsign; - argument << this->m_frequency; - argument << this->m_controller; - argument << this->m_position; - argument << this->m_range; - argument << this->m_distanceToPlane; - argument << this->m_isOnline; - argument << this->m_bookedFromUtc; - argument << this->m_bookedUntilUtc; - argument << this->m_atis; - argument << this->m_metar; - argument << this->m_voiceRoom; - } - - /* - * Unmarshall from DBus - */ - void CAtcStation::unmarshallFromDbus(const QDBusArgument &argument) - { - argument >> this->m_callsign; - argument >> this->m_frequency; - argument >> this->m_controller; - argument >> this->m_position; - argument >> this->m_range; - argument >> this->m_distanceToPlane; - argument >> this->m_isOnline; - argument >> this->m_bookedFromUtc; - argument >> this->m_bookedUntilUtc; - argument >> this->m_atis; - argument >> this->m_metar; - argument >> this->m_voiceRoom; - } - /* * Register metadata */ @@ -194,25 +156,47 @@ namespace BlackMisc qDBusRegisterMetaType(); } + /* + * Compare + */ + int CAtcStation::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + /* + * Marshall to DBus + */ + void CAtcStation::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall from DBus + */ + void CAtcStation::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + /* * Equal? */ bool CAtcStation::operator ==(const CAtcStation &other) const { if (this == &other) return true; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); + } - if (other.getCallsign() != this->getCallsign() || - other.getRange() != this->getRange() || - other.getFrequency() != this->getFrequency() || - other.getPosition() != this->getPosition()) return false; - - if (other.getController() != this->getController()) return false; - if (other.getAtis() != this->getAtis()) return false; - if (other.getMetar() != this->getMetar()) return false; - if (other.getVoiceRoom() != this->getVoiceRoom()) return false; - - return this->getBookedFromUtc() == other.getBookedFromUtc() && - this->getBookedUntilUtc() == other.getBookedUntilUtc(); + /* + * Hash + */ + uint CAtcStation::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); } /* @@ -283,27 +267,6 @@ namespace BlackMisc } } - /* - * Hash - */ - uint CAtcStation::getValueHash() const - { - QList hashs; - hashs << this->m_callsign.getValueHash(); - hashs << this->m_frequency.getValueHash(); - hashs << this->m_controller.getValueHash(); - hashs << this->m_position.getValueHash(); - hashs << this->m_range.getValueHash(); - hashs << this->m_distanceToPlane.getValueHash(); - hashs << this->m_metar.getValueHash(); - hashs << this->m_atis.getValueHash(); - hashs << this->m_voiceRoom.getValueHash(); - hashs << qHash(this->m_isOnline ? 1 : 3); - hashs << qHash(this->m_bookedFromUtc); - hashs << qHash(this->m_bookedUntilUtc); - return BlackMisc::calculateHash(hashs, "CAtcStation"); - } - /* * Property by index */ @@ -447,16 +410,6 @@ namespace BlackMisc return this->CValueObject::isA(metaTypeId); } - /* - * Compare - */ - int CAtcStation::compareImpl(const CValueObject &otherBase) const - { - const auto &other = static_cast(otherBase); - - return this->getCallsign().asString().compare(other.getCallsign().asString(), Qt::CaseInsensitive); - } - /* * Property as string by index */ diff --git a/src/blackmisc/avatcstation.h b/src/blackmisc/avatcstation.h index bc61803c4..9f4a5fcd7 100644 --- a/src/blackmisc/avatcstation.h +++ b/src/blackmisc/avatcstation.h @@ -10,7 +10,7 @@ #ifndef BLACKMISC_ATCSTATION_H #define BLACKMISC_ATCSTATION_H -#include "vvoiceroom.h" +#include "voiceroom.h" #include "aviocomsystem.h" #include "avinformationmessage.h" #include "avcallsign.h" @@ -187,10 +187,10 @@ namespace BlackMisc void setOnline(bool online) { this->m_isOnline = online; } //! \brief Get voice room - const BlackMisc::Voice::CVoiceRoom &getVoiceRoom() const { return this->m_voiceRoom; } + const BlackMisc::Audio::CVoiceRoom &getVoiceRoom() const { return this->m_voiceRoom; } //! \brief Set voice room - void setVoiceRoom(const BlackMisc::Voice::CVoiceRoom &voiceRoom) { this->m_voiceRoom = voiceRoom; } + void setVoiceRoom(const BlackMisc::Audio::CVoiceRoom &voiceRoom) { this->m_voiceRoom = voiceRoom; } //! \brief Valid voice room? bool hasValidVoiceRoom() const { return this->m_voiceRoom.isValid(); } @@ -310,6 +310,7 @@ namespace BlackMisc virtual void unmarshallFromDbus(const QDBusArgument &argument) override; private: + BLACK_ENABLE_TUPLE_CONVERSION(CAtcStation) CCallsign m_callsign; BlackMisc::Network::CUser m_controller; BlackMisc::PhysicalQuantities::CFrequency m_frequency; @@ -321,12 +322,14 @@ namespace BlackMisc QDateTime m_bookedUntilUtc; CInformationMessage m_atis; CInformationMessage m_metar; - BlackMisc::Voice::CVoiceRoom m_voiceRoom; + BlackMisc::Audio::CVoiceRoom m_voiceRoom; }; } // namespace } // 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_bookedFromUtc, o.m_bookedUntilUtc, o.m_atis)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CAtcStation) #endif // guard diff --git a/src/blackmisc/avcallsign.cpp b/src/blackmisc/avcallsign.cpp index f1231755f..b37c54b88 100644 --- a/src/blackmisc/avcallsign.cpp +++ b/src/blackmisc/avcallsign.cpp @@ -12,25 +12,6 @@ namespace BlackMisc return this->m_callsign; } - /* - * Marshall to DBus - */ - void CCallsign::marshallToDbus(QDBusArgument &argument) const - { - argument << this->m_callsignAsSet; - argument << this->m_telephonyDesignator; - } - - /* - * Unmarshall from DBus - */ - void CCallsign::unmarshallFromDbus(const QDBusArgument &argument) - { - argument >> this->m_callsignAsSet; - argument >> this->m_telephonyDesignator; - this->m_callsign = CCallsign::unifyCallsign(this->m_callsignAsSet); - } - /* * Unify the callsign */ @@ -96,13 +77,40 @@ namespace BlackMisc return false; } + /* + * Compare + */ + int CCallsign::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + /* + * Marshall to DBus + */ + void CCallsign::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall from DBus + */ + void CCallsign::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + /* * Equal? */ bool CCallsign::operator ==(const CCallsign &other) const { if (this == &other) return true; - return other.asString() == this->asString(); + // intentionally not via Tupel converter, compare on string only + return this->asString().compare(other.asString(), Qt::CaseInsensitive) == 0; } /* @@ -113,6 +121,14 @@ namespace BlackMisc return !((*this) == other); } + /* + * Hash + */ + uint CCallsign::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + /* * Less than? */ @@ -121,14 +137,6 @@ namespace BlackMisc return this->m_callsign < other.m_callsign; } - /* - * Hash - */ - uint CCallsign::getValueHash() const - { - return qHash(this->m_callsign); - } - /* * metaTypeId */ @@ -147,16 +155,6 @@ namespace BlackMisc return this->CValueObject::isA(metaTypeId); } - /* - * Compare - */ - int CCallsign::compareImpl(const CValueObject &otherBase) const - { - const auto &other = static_cast(otherBase); - - return this->m_callsign.compare(other.asString(), Qt::CaseInsensitive); - } - /* * Register metadata */ diff --git a/src/blackmisc/avcallsign.h b/src/blackmisc/avcallsign.h index 5488eb24d..674983024 100644 --- a/src/blackmisc/avcallsign.h +++ b/src/blackmisc/avcallsign.h @@ -120,6 +120,7 @@ namespace BlackMisc static const QPixmap &convertToIcon(const CCallsign &callsign); private: + BLACK_ENABLE_TUPLE_CONVERSION(CCallsign) QString m_callsignAsSet; QString m_callsign; QString m_telephonyDesignator; @@ -127,6 +128,7 @@ namespace BlackMisc } // namespace } // namespace +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CCallsign, (o.m_callsign, o.m_callsignAsSet, o.m_telephonyDesignator)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CCallsign) #endif // guard diff --git a/src/blackmisc/avheading.cpp b/src/blackmisc/avheading.cpp index c122e9cda..afe81b2da 100644 --- a/src/blackmisc/avheading.cpp +++ b/src/blackmisc/avheading.cpp @@ -32,31 +32,49 @@ namespace BlackMisc } /* - * Marshall to DBus + * Marshall */ void CHeading::marshallToDbus(QDBusArgument &argument) const { - this->CAngle::marshallToDbus(argument); - argument << qint32(this->m_north); + CAngle::marshallToDbus(argument); + argument << TupleConverter::toTuple(*this); } /* - * Unmarshall from DBus + * Unmarshall */ void CHeading::unmarshallFromDbus(const QDBusArgument &argument) { - this->CAngle::unmarshallFromDbus(argument); - qint32 north; - argument >> north; - this->m_north = static_cast(north); + CAngle::unmarshallFromDbus(argument); + argument >> TupleConverter::toTuple(*this); } /* - * Equal? + * Hash */ + uint CHeading::getValueHash() const + { + QList hashs; + hashs << CAngle::getValueHash(); + hashs << qHash(TupleConverter::toTuple(*this)); + return BlackMisc::calculateHash(hashs, "CHeading"); + } + + /* + * Compare + */ + int CHeading::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + int result = compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + return result == 0 ? CAngle::compareImpl(otherBase) : result; + } + bool CHeading::operator ==(const CHeading &other) const { - return other.m_north == this->m_north && this->CAngle::operator ==(other); + if (this == &other) return true; + if (!CAngle::operator ==(other)) return false; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } /* diff --git a/src/blackmisc/avheading.h b/src/blackmisc/avheading.h index 4b9422f2a..bd5c9bcb2 100644 --- a/src/blackmisc/avheading.h +++ b/src/blackmisc/avheading.h @@ -5,6 +5,8 @@ #ifndef BLACKMISC_AVHEADING_H #define BLACKMISC_AVHEADING_H + +#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/pqangle.h" namespace BlackMisc @@ -29,18 +31,22 @@ namespace BlackMisc }; private: + BLACK_ENABLE_TUPLE_CONVERSION(CHeading) ReferenceNorth m_north; //!< magnetic or true? protected: //! \copydoc CValueObject::convertToQString virtual QString convertToQString(bool i18n = false) const override; - //! \copydoc CValueObject::marshallToDbus + //! \copydoc CValueObject::marshallFromDbus() virtual void marshallToDbus(QDBusArgument &argument) const override; - //! \copydoc CValueObject::unmarshallFromDbus + //! \copydoc CValueObject::unmarshallFromDbus() virtual void unmarshallFromDbus(const QDBusArgument &argument) override; + //! \copydoc CValueObject::compareImpl + virtual int compareImpl(const CValueObject &other) const override; + public: //! \brief Default constructor: 0 heading true CHeading() : CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_north(Magnetic) {} @@ -62,6 +68,9 @@ namespace BlackMisc return QVariant::fromValue(*this); } + //! \copydoc CValueObject::getValueHash + virtual uint getValueHash() const override; + //! \brief Equal operator == bool operator ==(const CHeading &other) const; @@ -84,6 +93,8 @@ 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) #endif // guard diff --git a/src/blackmisc/avinformationmessage.cpp b/src/blackmisc/avinformationmessage.cpp index be9a3324d..a70d3683e 100644 --- a/src/blackmisc/avinformationmessage.cpp +++ b/src/blackmisc/avinformationmessage.cpp @@ -38,9 +38,7 @@ namespace BlackMisc { const auto &other = static_cast(otherBase); - if (this->m_type < other.m_type) { return -1; } - if (this->m_type > other.m_type) { return 1; } - return this->m_message.compare(other.m_message); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); } /* @@ -48,9 +46,7 @@ namespace BlackMisc */ void CInformationMessage::marshallToDbus(QDBusArgument &argument) const { - argument << this->m_message; - argument << static_cast(this->m_type); - argument << this->m_receivedTimestamp; + argument << TupleConverter::toTuple(*this); } /* @@ -58,11 +54,7 @@ namespace BlackMisc */ void CInformationMessage::unmarshallFromDbus(const QDBusArgument &argument) { - uint type; - argument >> this->m_message; - argument >> type; - argument >> this->m_receivedTimestamp; - this->m_type = static_cast(type); + argument >> TupleConverter::toTuple(*this); } /* @@ -71,9 +63,7 @@ namespace BlackMisc bool CInformationMessage::operator ==(const CInformationMessage &other) const { if (this == &other) return true; - return this->m_message == other.m_message && - this->m_receivedTimestamp == other.m_receivedTimestamp && - this->m_type == other.m_type; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } /* @@ -84,6 +74,14 @@ namespace BlackMisc return !((*this) == other); } + /* + * Hash + */ + uint CInformationMessage::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + /* * Register metadata */ @@ -93,16 +91,6 @@ namespace BlackMisc qDBusRegisterMetaType(); } - /* - * Hash - */ - uint CInformationMessage::getValueHash() const - { - QList hashs; - hashs << qHash(this->m_message); - return BlackMisc::calculateHash(hashs, "CAtis"); - } - /* * Type as string */ diff --git a/src/blackmisc/avinformationmessage.h b/src/blackmisc/avinformationmessage.h index 66ca49254..bc327ab78 100644 --- a/src/blackmisc/avinformationmessage.h +++ b/src/blackmisc/avinformationmessage.h @@ -10,6 +10,7 @@ #ifndef BLACKMISC_INFORMATIONMESSAGE_H #define BLACKMISC_INFORMATIONMESSAGE_H +#include "blackmiscfreefunctions.h" #include "valueobject.h" #include #include @@ -187,6 +188,7 @@ namespace BlackMisc virtual void unmarshallFromDbus(const QDBusArgument &argument) override; private: + BLACK_ENABLE_TUPLE_CONVERSION(CInformationMessage) InformationType m_type; QString m_message; QDateTime m_receivedTimestamp; @@ -194,6 +196,8 @@ 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) #endif // guard diff --git a/src/blackmisc/avioadfsystem.h b/src/blackmisc/avioadfsystem.h index 6127ce1d4..4651177d6 100644 --- a/src/blackmisc/avioadfsystem.h +++ b/src/blackmisc/avioadfsystem.h @@ -280,4 +280,4 @@ namespace BlackMisc Q_DECLARE_METATYPE(BlackMisc::Aviation::CAdfSystem) -#endif // BLACKMISC_AVIOADFSYSTEM_H +#endif // guard diff --git a/src/blackmisc/aviobase.cpp b/src/blackmisc/aviobase.cpp new file mode 100644 index 000000000..73201996a --- /dev/null +++ b/src/blackmisc/aviobase.cpp @@ -0,0 +1,34 @@ +#include "aviobase.h" + +namespace BlackMisc +{ + namespace Aviation + { + bool CAvionicsBase::operator ==(const CAvionicsBase &other) const + { + if (this == &other) return true; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); + } + + int CAvionicsBase::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + void CAvionicsBase::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + void CAvionicsBase::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + + uint CAvionicsBase::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + } +} diff --git a/src/blackmisc/aviobase.h b/src/blackmisc/aviobase.h index 0d7c65625..fdd055b16 100644 --- a/src/blackmisc/aviobase.h +++ b/src/blackmisc/aviobase.h @@ -16,101 +16,71 @@ namespace BlackMisc namespace Aviation { - /*! - * \brief Base class for avionics - */ + //! \brief Base class for avionics class CAvionicsBase : public BlackMisc::CValueObject { protected: QString m_name; //!< name of the unit - /*! - * \brief Constructor - */ + //! \brief Constructor CAvionicsBase(const QString &name) : m_name(name) {} - /*! - * \brief Are the set values valid / in range - * \return - */ + //! \brief Are set values valid? virtual bool validValues() const { return true; } - /*! - * \brief Set name - * \param name - */ + //! \brief Set name void setName(const QString &name) { this->m_name = name; } - /*! - * \brief operator == - * \param other - * \return - */ - bool operator ==(const CAvionicsBase &other) const + //! \brief operator == + bool operator ==(const CAvionicsBase &other) const; + + //! \brief operator != + bool operator !=(const CAvionicsBase &other) const { - if (this == &other) return true; - return this->m_name == other.m_name; + return !(other == (*this)); } - /*! - * \copydoc CValueObject::getMetaTypeId - */ + //! \copydoc CValueObject::getMetaTypeId virtual int getMetaTypeId() const override { return 0; } - /*! - * \copydoc CValueObject::isA - */ + //! \copydoc CValueObject::isA virtual bool isA(int metaTypeId) const override { return this->CValueObject::isA(metaTypeId); } - /*! - * \copydoc CValueObject::compareImpl - */ - virtual int compareImpl(const CValueObject &other) const override - { - Q_UNUSED(other); - qFatal("not implemented"); - return 0; - } + //! \copydoc CValueObject::compareImpl(otherBase) + virtual int compareImpl(const CValueObject &otherBase) const override; - /*! - * \copydoc CValueObject::marshallToDbus() - */ - virtual void marshallToDbus(QDBusArgument &argument) const override - { - argument << this->m_name; - } + //! \copydoc CValueObject::marshallToDbus() + virtual void marshallToDbus(QDBusArgument &argument) const override; - /*! - * \copydoc CValueObject::unmarshallFromDbus() - */ - virtual void unmarshallFromDbus(const QDBusArgument &argument) override - { - argument >> this->m_name; - } + //! \copydoc CValueObject::unmarshallFromDbus() + virtual void unmarshallFromDbus(const QDBusArgument &argument) override; + + //! \copydoc CValueObject::getValueHash() + virtual uint getValueHash() const override; public: - /*! - * \brief Virtual destructor - */ + //! \brief Virtual destructor virtual ~CAvionicsBase() {} - /*! - * \brief Name - * \return - */ + //! \brief Name QString getName() const { return this->m_name; } + + private: + BLACK_ENABLE_TUPLE_CONVERSION(CAvionicsBase) }; } // namespace } // namespace +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAvionicsBase, (o.m_name)) + #endif // guard diff --git a/src/blackmisc/aviocomsystem.cpp b/src/blackmisc/aviocomsystem.cpp index d8702d26a..f0b4e568b 100644 --- a/src/blackmisc/aviocomsystem.cpp +++ b/src/blackmisc/aviocomsystem.cpp @@ -51,10 +51,61 @@ namespace BlackMisc CFrequency f(frequencyMHz, CFrequencyUnit::MHz()); if (f == this->getFrequencyStandby()) return; // save all the comparisons / rounding CComSystem::roundToChannelSpacing(f, this->m_channelSpacing); - this->CModulator::setFrequencyStandby(f); + CModulator::setFrequencyStandby(f); this->validate(true); } + /* + * Marshall + */ + void CComSystem::marshallToDbus(QDBusArgument &argument) const + { + CModulator::marshallToDbus(argument); + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall + */ + void CComSystem::unmarshallFromDbus(const QDBusArgument &argument) + { + CModulator::unmarshallFromDbus(argument); + argument >> TupleConverter::toTuple(*this); + } + + /* + * Hash + */ + uint CComSystem::getValueHash() const + { + QList hashs; + hashs << CModulator::getValueHash(); + hashs << qHash(TupleConverter::toTuple(*this)); + return BlackMisc::calculateHash(hashs, "CComSystem"); + } + + /* + * Compare + */ + int CComSystem::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + int result = compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + return result == 0 ? CModulator::compareImpl(otherBase) : result; + } + + bool CComSystem::operator ==(const CComSystem &other) const + { + if (this == &other) return true; + if (!CModulator::operator ==(other)) return false; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); + } + + bool CComSystem::operator !=(const CComSystem &other) const + { + return !((*this) == other); + } + /* * Round to channel spacing */ @@ -97,27 +148,5 @@ namespace BlackMisc default: qFatal("Wrong channel spacing"); return 0.0; // return just supressing compiler warning } } - - /* - * Marshall - */ - void CComSystem::marshallToDbus(QDBusArgument &argument) const - { - CModulator::marshallToDbus(argument); - argument << static_cast(this->m_channelSpacing); - } - - /* - * Unmarshall - */ - void CComSystem::unmarshallFromDbus(const QDBusArgument &argument) - { - CModulator::unmarshallFromDbus(argument); - uint cs; - argument >> cs; - this->m_channelSpacing = static_cast(cs); - } - - } // namespace -} +} // namespace diff --git a/src/blackmisc/aviocomsystem.h b/src/blackmisc/aviocomsystem.h index ab5095fe1..9d6d742f7 100644 --- a/src/blackmisc/aviocomsystem.h +++ b/src/blackmisc/aviocomsystem.h @@ -6,13 +6,13 @@ #ifndef BLACKMISC_AVIOCOMSYSTEM_H #define BLACKMISC_AVIOCOMSYSTEM_H #include "blackmisc/aviomodulator.h" +#include "blackmisc/blackmiscfreefunctions.h" #include namespace BlackMisc { namespace Aviation { - /*! * \brief COM system (aka "radio") */ @@ -30,6 +30,7 @@ namespace BlackMisc }; private: + BLACK_ENABLE_TUPLE_CONVERSION(CComSystem) ChannelSpacing m_channelSpacing; /*! @@ -54,9 +55,7 @@ namespace BlackMisc static double channelSpacingToFrequencyKHz(ChannelSpacing channelSpacing); protected: - /*! - * \copydoc CAvionicsBase::validValues - */ + //! \copydoc CAvionicsBase::validValues virtual bool validValues() const override; /*! @@ -68,52 +67,32 @@ namespace BlackMisc */ bool validate(bool strict = true) const; - /*! - * \copydoc CValueObject::marshallFromDbus() - */ + //! \copydoc CValueObject::marshallFromDbus() virtual void marshallToDbus(QDBusArgument &argument) const override; - /*! - * \copydoc CValueObject::unmarshallFromDbus() - */ + //! \copydoc CValueObject::unmarshallFromDbus() virtual void unmarshallFromDbus(const QDBusArgument &argument) override; + //! \copydoc CValueObject::compareImpl + virtual int compareImpl(const CValueObject &other) const override; + public: - /*! - * Default constructor - */ + //! \brief Default constructor CComSystem() : CModulator(), m_channelSpacing(ChannelSpacing25KHz) {} - /*! - * \brief Constructor - */ + //! \brief Constructor CComSystem(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency = CModulator::FrequencyNotSet(), int digits = 3): CModulator(name, activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency, digits), m_channelSpacing(ChannelSpacing25KHz) { this->validate(true); } - /*! - * \brief Copy constructor - */ - CComSystem(const CComSystem &other) : CModulator(other), m_channelSpacing(other.m_channelSpacing) {} - - /*! - * \copydoc CValueObject::toQVariant - */ + //! \copydoc CValueObject::toQVariant virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } - /*! - * \copydoc CValueObject::getValueHash - */ - virtual uint getValueHash() const override - { - return CModulator::getValueHash(); - } - /*! * \brief Set active frequency * \remarks will be rounded to channel spacing @@ -161,21 +140,18 @@ namespace BlackMisc this->setFrequencyActive(BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants::FrequencyInternationalAirDistress()); } + //! \copydoc CValueObject::getValueHash + virtual uint getValueHash() const override; + /*! * \brief operator == */ - bool operator ==(const CComSystem &other) const - { - return this->CModulator::operator ==(other); - } + bool operator ==(const CComSystem &other) const; /*! * \brief operator != */ - bool operator !=(const CComSystem &other) const - { - return this->CModulator::operator !=(other); - } + bool operator !=(const CComSystem &other) const; /*! * Try to get a COM unit with given name and frequency. Returns true in case an object @@ -383,6 +359,8 @@ 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) #endif // include guard diff --git a/src/blackmisc/aviomodulator.cpp b/src/blackmisc/aviomodulator.cpp index cc53ac5e5..29a76f489 100644 --- a/src/blackmisc/aviomodulator.cpp +++ b/src/blackmisc/aviomodulator.cpp @@ -41,9 +41,8 @@ namespace BlackMisc template bool CModulator::operator ==(const CModulator &other) const { if (this == &other) return true; - return (this->getName() == other.getName() && - this->m_frequencyActive == other.m_frequencyActive && - this->m_frequencyStandby == other.m_frequencyStandby); + if (!CAvionicsBase::operator ==(other)) return false; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } /* @@ -59,13 +58,8 @@ namespace BlackMisc */ template void CModulator::marshallToDbus(QDBusArgument &argument) const { - this->CAvionicsBase::marshallToDbus(argument); - argument << this->m_frequencyActive; - argument << this->m_frequencyStandby; - argument << this->m_digits; - argument << this->m_volumeInput; - argument << this->m_volumeOutput; - argument << this->m_enabled; + CAvionicsBase::marshallToDbus(argument); + argument << TupleConverter::toTuple(*this); } /* @@ -73,13 +67,18 @@ namespace BlackMisc */ template void CModulator::unmarshallFromDbus(const QDBusArgument &argument) { - this->CAvionicsBase::unmarshallFromDbus(argument); - argument >> this->m_frequencyActive; - argument >> this->m_frequencyStandby; - argument >> this->m_digits; - argument >> this->m_volumeInput; - argument >> this->m_volumeOutput; - argument >> this->m_enabled; + CAvionicsBase::unmarshallFromDbus(argument); + argument >> TupleConverter::toTuple(*this); + } + + /* + * Compare + */ + template int CModulator::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + int result = compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + return result == 0 ? CAvionicsBase::compareImpl(otherBase) : result; } /* @@ -88,9 +87,8 @@ namespace BlackMisc template uint CModulator::getValueHash() const { QList hashs; - hashs << this->m_frequencyActive.getValueHash(); - hashs << this->m_frequencyStandby.getValueHash(); - hashs << qHash(this->m_digits); + hashs << CAvionicsBase::getValueHash(); + hashs << qHash(TupleConverter::toTuple(*this)); return BlackMisc::calculateHash(hashs, "CModulator"); } diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index b547ce2ac..7995aa357 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -23,6 +23,7 @@ namespace BlackMisc template class CModulator : public CAvionicsBase { private: + BLACK_ENABLE_TUPLE_CONVERSION(CModulator) BlackMisc::PhysicalQuantities::CFrequency m_frequencyActive; //!< active frequency BlackMisc::PhysicalQuantities::CFrequency m_frequencyStandby; //!< standby frequency qint32 m_volumeInput; //!< volume input @@ -112,6 +113,11 @@ namespace BlackMisc */ bool operator !=(const CModulator &other) const; + /*! + * \copydoc CValueObject::compareImpl(otherBase) + */ + virtual int compareImpl(const CValueObject &otherBase) const override; + /*! * \brief COM1 * \return @@ -314,4 +320,6 @@ namespace BlackMisc } // namespace } // namespace +BLACK_DECLARE_TUPLE_CONVERSION_TEMPLATE(BlackMisc::Aviation::CModulator, (o.m_frequencyActive, o.m_frequencyStandby, o.m_volumeInput , o.m_volumeOutput, o.m_enabled)) + #endif // guard diff --git a/src/blackmisc/avionavsystem.h b/src/blackmisc/avionavsystem.h index 6cc24da2f..30be110b5 100644 --- a/src/blackmisc/avionavsystem.h +++ b/src/blackmisc/avionavsystem.h @@ -291,4 +291,4 @@ namespace BlackMisc Q_DECLARE_METATYPE(BlackMisc::Aviation::CNavSystem) -#endif // BLACKMISC_AVIONAVSYSTEM_H +#endif // guard diff --git a/src/blackmisc/aviotransponder.cpp b/src/blackmisc/aviotransponder.cpp index 45c479ece..1c0bde06e 100644 --- a/src/blackmisc/aviotransponder.cpp +++ b/src/blackmisc/aviotransponder.cpp @@ -192,39 +192,44 @@ namespace BlackMisc } /* - * Stream to DBus << + * Marshall */ void CTransponder::marshallToDbus(QDBusArgument &argument) const { - this->CAvionicsBase::marshallToDbus(argument); - argument << this->m_transponderCode; - argument << static_cast(this->m_transponderMode); + CAvionicsBase::marshallToDbus(argument); + argument << TupleConverter::toTuple(*this); } /* - * Stream from DBus >> + * Unmarshall */ void CTransponder::unmarshallFromDbus(const QDBusArgument &argument) { - this->CAvionicsBase::unmarshallFromDbus(argument); - qint32 tm; - argument >> this->m_transponderCode; - argument >> tm; - this->m_transponderMode = static_cast(tm); + CAvionicsBase::unmarshallFromDbus(argument); + argument >> TupleConverter::toTuple(*this); } /* - * Value hash + * Hash */ uint CTransponder::getValueHash() const { QList hashs; - hashs << qHash(this->m_name); - hashs << qHash(this->m_transponderCode); - hashs << qHash(this->m_transponderMode); + hashs << CAvionicsBase::getValueHash(); + hashs << qHash(TupleConverter::toTuple(*this)); return BlackMisc::calculateHash(hashs, "CTransponder"); } + /* + * Compare + */ + int CTransponder::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + int result = compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + return result == 0 ? CAvionicsBase::compareImpl(otherBase) : result; + } + /* * Register metadata of unit and quantity */ diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index a91bc5e72..7f68bf2f8 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -6,6 +6,7 @@ #ifndef BLACKMISC_AVIOTRANSPONDER_H #define BLACKMISC_AVIOTRANSPONDER_H #include "blackmisc/aviobase.h" +#include "blackmisc/blackmiscfreefunctions.h" #include namespace BlackMisc @@ -32,6 +33,7 @@ namespace BlackMisc }; private: + BLACK_ENABLE_TUPLE_CONVERSION(CTransponder) qint32 m_transponderCode; //m_code; } - /* - * Marshall to DBus - */ - void CSelcal::marshallToDbus(QDBusArgument &argument) const - { - argument << this->m_code; - } - - /* - * Unmarshall from DBus - */ - void CSelcal::unmarshallFromDbus(const QDBusArgument &argument) - { - argument >> this->m_code; - } - /* * Equals code? */ @@ -145,13 +129,46 @@ namespace BlackMisc return CSelcal::allCodePairs; } + /* + * Compare + */ + int CSelcal::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + /* + * Marshall to DBus + */ + void CSelcal::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall from DBus + */ + void CSelcal::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + + /* + * Hash + */ + uint CSelcal::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + /* * Equal? */ bool CSelcal::operator ==(const CSelcal &other) const { if (this == &other) return true; - return (this->m_code.compare(other.m_code, Qt::CaseInsensitive) == 0); + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } /* @@ -162,14 +179,6 @@ namespace BlackMisc return !((*this) == other); } - /* - * Hash - */ - uint CSelcal::getValueHash() const - { - return qHash(this->m_code); - } - /* * metaTypeId */ @@ -187,15 +196,6 @@ namespace BlackMisc return this->CValueObject::isA(metaTypeId); } - /* - * Compare - */ - int CSelcal::compareImpl(const CValueObject &otherBase) const - { - const auto &other = static_cast(otherBase); - return this->m_code.compare(other.getCode(), Qt::CaseInsensitive); - } - /* * Register metadata */ diff --git a/src/blackmisc/avselcal.h b/src/blackmisc/avselcal.h index 09acc67a5..705dcaa1b 100644 --- a/src/blackmisc/avselcal.h +++ b/src/blackmisc/avselcal.h @@ -136,6 +136,7 @@ namespace BlackMisc virtual void unmarshallFromDbus(const QDBusArgument &argument) override; private: + BLACK_ENABLE_TUPLE_CONVERSION(CSelcal) QString m_code; static QList frequencyEquivalents; static QStringList allCodePairs; @@ -143,6 +144,7 @@ namespace BlackMisc } // namespace } // namespace +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CSelcal, (o.m_code)) Q_DECLARE_METATYPE(BlackMisc::Aviation::CSelcal) #endif // guard diff --git a/src/blackmisc/avtrack.cpp b/src/blackmisc/avtrack.cpp index 4a9eaacf5..19ce2e965 100644 --- a/src/blackmisc/avtrack.cpp +++ b/src/blackmisc/avtrack.cpp @@ -31,31 +31,49 @@ namespace BlackMisc } /* - * Marshall to DBus + * Marshall */ void CTrack::marshallToDbus(QDBusArgument &argument) const { - this->CAngle::marshallToDbus(argument); - argument << qint32(this->m_north); + CAngle::marshallToDbus(argument); + argument << TupleConverter::toTuple(*this); } /* - * Unmarshall from DBus + * Unmarshall */ void CTrack::unmarshallFromDbus(const QDBusArgument &argument) { - this->CAngle::unmarshallFromDbus(argument); - qint32 north; - argument >> north; - this->m_north = static_cast(north); + CAngle::unmarshallFromDbus(argument); + argument >> TupleConverter::toTuple(*this); } /* - * Equal? + * Hash */ + uint CTrack::getValueHash() const + { + QList hashs; + hashs << CAngle::getValueHash(); + hashs << qHash(TupleConverter::toTuple(*this)); + return BlackMisc::calculateHash(hashs, "CTrack"); + } + + /* + * Compare + */ + int CTrack::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + int result = compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + return result == 0 ? CAngle::compareImpl(otherBase) : result; + } + bool CTrack::operator ==(const CTrack &other) const { - return other.m_north == this->m_north && this->CAngle::operator ==(other); + if (this == &other) return true; + if (!CAngle::operator ==(other)) return false; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } /* diff --git a/src/blackmisc/avtrack.h b/src/blackmisc/avtrack.h index 639544820..98e923ae3 100644 --- a/src/blackmisc/avtrack.h +++ b/src/blackmisc/avtrack.h @@ -5,6 +5,8 @@ #ifndef BLACKMISC_AVTRACK_H #define BLACKMISC_AVTRACK_H + +#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/pqangle.h" namespace BlackMisc @@ -30,24 +32,22 @@ namespace BlackMisc }; private: + BLACK_ENABLE_TUPLE_CONVERSION(CTrack) ReferenceNorth m_north; //!< magnetic or true? protected: - /*! - * \copydoc CValueObject::convertToQString - */ + //! \copydoc CValueObject::convertToQString virtual QString convertToQString(bool i18n = false) const override; - /*! - * \copydoc CValueObject::marshallToDbus - */ + //! \copydoc CValueObject::marshallFromDbus() virtual void marshallToDbus(QDBusArgument &argument) const override; - /*! - * \copydoc CValueObject::unmarshallFromDbus - */ + //! \copydoc CValueObject::unmarshallFromDbus() virtual void unmarshallFromDbus(const QDBusArgument &argument) override; + //! \copydoc CValueObject::compareImpl + virtual int compareImpl(const CValueObject &other) const override; + public: /*! * \brief Default constructor: 0 Track magnetic @@ -69,63 +69,47 @@ namespace BlackMisc */ CTrack(BlackMisc::PhysicalQuantities::CAngle track, ReferenceNorth north) : BlackMisc::PhysicalQuantities::CAngle(track), m_north(north) {} - /*! - * \copydoc CValueObject::toQVariant - */ + //! \copydoc CValueObject::toQVariant virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } - /*! - * \brief Equal operator == - * \param other - * \return - */ + //! \copydoc CValueObject::getValueHash + virtual uint getValueHash() const override; + + //! \brief Equal operator == bool operator ==(const CTrack &other) const; - /*! - * \brief Unequal operator == - * \param other - * \return - */ + //! \brief Unequal operator != bool operator !=(const CTrack &other) const; - /*! - * \brief Magnetic Track? - * \return - */ + //! \brief Magnetic Track? bool isMagneticTrack() const { return Magnetic == this->m_north; (void)QT_TRANSLATE_NOOP("Aviation", "magnetic"); } - /*! - * \brief True Track? - * \return - */ + //! \brief True Track? bool isTrueTrack() const { return True == this->m_north; (void)QT_TRANSLATE_NOOP("Aviation", "true"); } - /*! - * \brief Get reference north (magnetic or true) - * \return - */ + //! \brief Get reference north (magnetic or true) ReferenceNorth getReferenceNorth() const { return m_north; } - /*! - * \brief Register metadata - */ + //! \brief Register metadata static void registerMetadata(); }; } // 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) #endif // guard diff --git a/src/blackmisc/coordinateecef.h b/src/blackmisc/coordinateecef.h index d38898532..20fafc179 100644 --- a/src/blackmisc/coordinateecef.h +++ b/src/blackmisc/coordinateecef.h @@ -37,63 +37,43 @@ namespace BlackMisc */ explicit CCoordinateEcef(const BlackMisc::Math::CVector3D vector) : CVector3DBase(vector.i(), vector.j(), vector.k()) {} - /*! - * \copydoc CValueObject::toQVariant - */ + //! \copydoc CValueObject::toQVariant virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } - /*! - * \brief x - * \return - */ + //! \brief x double x() const { return this->m_i; } - /*! - * \brief y - * \return - */ + //! \brief y double y() const { return this->m_j; } - /*! - * \brief z - * \return - */ + //! \brief z double z() const { return this->m_k; } - /*! - * \brief Set x - * \param x - */ + //! \brief Set x void setX(double x) { this->m_i = x; } - /*! - * \brief Set y - * \param y - */ + //! \brief Set y void setY(double y) { this->m_j = y; } - /*! - * \brief Set z - * \param z - */ + //! \brief Set z void setZ(double z) { this->m_k = z; @@ -109,9 +89,7 @@ namespace BlackMisc } protected: - /*! - * \copydoc CValueObject::convertToQString - */ + //! \copydoc CValueObject::convertToQString virtual QString convertToQString(bool i18n = false) const override { Q_UNUSED(i18n) diff --git a/src/blackmisc/coordinatened.cpp b/src/blackmisc/coordinatened.cpp new file mode 100644 index 000000000..79de8ce6c --- /dev/null +++ b/src/blackmisc/coordinatened.cpp @@ -0,0 +1,56 @@ +#include "blackmisc/coordinatened.h" + +using namespace BlackMisc::Math; + +namespace BlackMisc +{ + namespace Geo + { + + bool CCoordinateNed::operator ==(const CCoordinateNed &other) const + { + if (this == &other) return true; + if (!CVector3DBase::operator ==(other)) return false; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); + } + + /* + * Marshall + */ + void CCoordinateNed::marshallToDbus(QDBusArgument &argument) const + { + CVector3DBase::marshallToDbus(argument); + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall + */ + void CCoordinateNed::unmarshallFromDbus(const QDBusArgument &argument) + { + CVector3DBase::unmarshallFromDbus(argument); + argument >> TupleConverter::toTuple(*this); + } + + /* + * Hash + */ + uint CCoordinateNed::getValueHash() const + { + QList hashs; + hashs << CVector3DBase::getValueHash(); + hashs << qHash(TupleConverter::toTuple(*this)); + return BlackMisc::calculateHash(hashs, "CCoordinateNed"); + } + + /* + * Compare + */ + int CCoordinateNed::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + int result = compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + return result == 0 ? CVector3DBase::compareImpl(otherBase) : result; + } + } +} diff --git a/src/blackmisc/coordinatened.h b/src/blackmisc/coordinatened.h index ea316ee88..ba81164af 100644 --- a/src/blackmisc/coordinatened.h +++ b/src/blackmisc/coordinatened.h @@ -8,6 +8,7 @@ #include "blackmisc/mathvector3d.h" #include "blackmisc/mathmatrix3x3.h" #include "blackmisc/coordinategeodetic.h" +#include "blackmisc/blackmiscfreefunctions.h" namespace BlackMisc { @@ -19,13 +20,21 @@ namespace BlackMisc class CCoordinateNed : public BlackMisc::Math::CVector3DBase { private: + BLACK_ENABLE_TUPLE_CONVERSION(CCoordinateNed) CCoordinateGeodetic m_referencePosition; //!< geodetic reference position bool m_hasReferencePosition; //!< valid reference position? protected: - /*! - * \copydoc CValueObject::convertToQString - */ + //! \copydoc CValueObject::marshallFromDbus() + virtual void marshallToDbus(QDBusArgument &argument) const override; + + //! \copydoc CValueObject::unmarshallFromDbus() + virtual void unmarshallFromDbus(const QDBusArgument &argument) override; + + //! \copydoc CValueObject::compareImpl + virtual int compareImpl(const CValueObject &other) const override; + + //! \copydoc CValueObject::convertToQString virtual QString convertToQString(bool i18n = false) const override { Q_UNUSED(i18n) @@ -82,26 +91,21 @@ namespace BlackMisc */ CCoordinateNed(const CCoordinateGeodetic &referencePosition, const BlackMisc::Math::CVector3D &vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(referencePosition), m_hasReferencePosition(true) {} - /*! - * \copydoc CValueObject::toQVariant - */ + //! \copydoc CValueObject::toQVariant virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } + //! \copydoc CValueObject::getValueHash + virtual uint getValueHash() const override; + /*! * \brief Equal operator == * \param other * \return */ - bool operator ==(const CCoordinateNed &other) const - { - if (this == &other) return true; - return this->m_hasReferencePosition == other.m_hasReferencePosition && - this->m_referencePosition == other.m_referencePosition && - this->CVector3DBase::operator== (other); - } + bool operator ==(const CCoordinateNed &other) const; /*! * \brief Unequal operator != @@ -208,6 +212,7 @@ namespace BlackMisc } // namespace } // namespace +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Geo::CCoordinateNed, (o.m_referencePosition, o.m_hasReferencePosition)) Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateNed) #endif // guard diff --git a/src/blackmisc/geoearthangle.cpp b/src/blackmisc/geoearthangle.cpp index 4c0d56b4c..3e0c3d78c 100644 --- a/src/blackmisc/geoearthangle.cpp +++ b/src/blackmisc/geoearthangle.cpp @@ -94,11 +94,8 @@ namespace BlackMisc */ template int CEarthAngle::compareImpl(const CValueObject &otherBase) const { - const auto &other = static_cast(otherBase); - - if (*this < other) { return -1; } - else if (*this > other) { return 1; } - else { return 0; } + const auto &other = static_cast(otherBase); + return CAngle::compareImpl(other); } // see here for the reason of thess forward instantiations diff --git a/src/blackmisc/geolatitude.h b/src/blackmisc/geolatitude.h index 48621efdf..f8b09c46c 100644 --- a/src/blackmisc/geolatitude.h +++ b/src/blackmisc/geolatitude.h @@ -4,7 +4,6 @@ #include #include "blackmisc/geoearthangle.h" - namespace BlackMisc { namespace Geo diff --git a/src/blackmisc/hwkeyboardkey.cpp b/src/blackmisc/hwkeyboardkey.cpp index afc9d80e4..b430165e7 100644 --- a/src/blackmisc/hwkeyboardkey.cpp +++ b/src/blackmisc/hwkeyboardkey.cpp @@ -24,16 +24,6 @@ namespace BlackMisc m_qtKey(keyCode), m_nativeScanCode(nativeScanCode), m_nativeVirtualKey(nativeVirtualKey), m_modifier1(modifier1), m_modifier2(modifier2), m_function(function), m_pressed(isPressed) {} - uint CKeyboardKey::getValueHash() const - { - QList hashs; - hashs << qHash(this->m_qtKey); - hashs << qHash(this->m_function); - hashs << qHash(static_cast(this->m_modifier1)); - hashs << qHash(static_cast(this->m_modifier2)); - return BlackMisc::calculateHash(hashs, "CKeyboardKey"); - } - void CKeyboardKey::registerMetadata() { qRegisterMetaType(); @@ -58,40 +48,6 @@ namespace BlackMisc return (metaTypeId == qMetaTypeId()); } - int CKeyboardKey::compareImpl(const CValueObject &otherBase) const - { - const auto &other = static_cast(otherBase); - QString k1(this->m_qtKey); - QString k2(other.getKey()); - return k1.compare(k2); - } - - void CKeyboardKey::marshallToDbus(QDBusArgument &argument) const - { - argument << this->m_qtKey; - argument << this->m_nativeScanCode; - argument << this->m_nativeVirtualKey; - argument << static_cast(this->m_modifier1); - argument << static_cast(this->m_modifier2); - argument << static_cast(this->m_function); - argument << this->m_pressed; - } - - void CKeyboardKey::unmarshallFromDbus(const QDBusArgument &argument) - { - argument >> this->m_qtKey; - argument >> this->m_nativeScanCode; - argument >> this->m_nativeVirtualKey; - uint c; - argument >> c; - this->m_modifier1 = static_cast(c); - argument >> c; - this->m_modifier2 = static_cast(c); - argument >> c; - this->m_function = static_cast(c); - argument >> this->m_pressed; - } - QString CKeyboardKey::modifierToString(CKeyboardKey::Modifier modifier) { switch (modifier) @@ -166,13 +122,54 @@ namespace BlackMisc return modifiers; } + /* + * Compare + */ + int CKeyboardKey::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + /* + * Marshall to DBus + */ + void CKeyboardKey::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall from DBus + */ + void CKeyboardKey::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + + /* + * Hash + */ + uint CKeyboardKey::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + + /* + * Equal? + */ bool CKeyboardKey::operator ==(const CKeyboardKey &other) const { - return (other.getKey() != this->getKey()) && - other.isPressed() == this->isPressed() && - other.getFunction() == this->getFunction() && - other.getModifier1() == this->getModifier1() && - other.getModifier2() == this->getModifier2(); + if (this == &other) return true; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); + } + + /* + * Unequal? + */ + bool CKeyboardKey::operator !=(const CKeyboardKey &other) const + { + return !((*this) == other); } bool CKeyboardKey::operator< (CKeyboardKey const &other) const @@ -345,6 +342,4 @@ namespace BlackMisc } } } // namespace Hardware - - } // BlackMisc diff --git a/src/blackmisc/hwkeyboardkey.h b/src/blackmisc/hwkeyboardkey.h index 6665f8a48..3353b6796 100644 --- a/src/blackmisc/hwkeyboardkey.h +++ b/src/blackmisc/hwkeyboardkey.h @@ -10,6 +10,7 @@ #ifndef BLACKMISC_KEYBOARDKEY_H #define BLACKMISC_KEYBOARDKEY_H +#include "blackmiscfreefunctions.h" #include "valueobject.h" #include #include @@ -96,6 +97,9 @@ namespace BlackMisc //! \brief Equal? bool operator ==(const CKeyboardKey &other) const; + //! \brief Unequal operator != + bool operator !=(const CKeyboardKey &other) const; + //! \brief < bool operator<(CKeyboardKey const &other) const; @@ -240,6 +244,7 @@ namespace BlackMisc virtual void unmarshallFromDbus(const QDBusArgument &argument) override; private: + BLACK_ENABLE_TUPLE_CONVERSION(CKeyboardKey) int m_qtKey; //!< code similar to Qt::Key quint32 m_nativeScanCode; //!< native scan code, QKeyEvent::nativeScanCode quint32 m_nativeVirtualKey; //!< virtual key code @@ -252,6 +257,9 @@ 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) #endif // guard diff --git a/src/blackmisc/nwserver.h b/src/blackmisc/nwserver.h index 2430d759b..b27a4fbe4 100644 --- a/src/blackmisc/nwserver.h +++ b/src/blackmisc/nwserver.h @@ -22,110 +22,65 @@ namespace BlackMisc class CServer : public BlackMisc::CValueObject { public: - /*! - * Default constructor. - */ + //! \brief Default constructor. CServer() : m_port(-1) {} - /*! - * Constructor. - * \param name - * \param description - * \param address - * \param port - * \param user - */ + //! \brief Constructor. CServer(const QString &name, const QString &description, const QString &address, qint32 port, const CUser &user) : m_name(name), m_description(description), m_address(address), m_port(port), m_user(user) {} - /*! - * \copydoc CValueObject::toQVariant - */ + //! \copydoc CValueObject::toQVariant virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); } - /*! - * Get address. - * \return - */ + //! Get address. const QString &getAddress() const { return m_address; } - /*! - * \brief Set address (e.g. myserver.foo.com) - */ + //! \brief Set address (e.g. myserver.foo.com) void setAddress(const QString &address) { m_address = address; } - /*! - * Get user - */ + //! Get user const CUser &getUser() const { return m_user; } - /*! - * \brief Set user - */ + //! \brief Set user void setUser(const CUser &user) { m_user = user; } - /*! - * Get name - */ + //! \brief Get name const QString &getName() const { return m_name; } - /*! - * \brief Set name - * \param name - */ + //! \brief Set name void setName(const QString &name) { m_name = name; } - /*! - * Get description - */ + //! \brief Get description const QString &getDescription() const { return m_description; } - /*! - * \brief Set description - */ + //! \brief Set description void setDescription(const QString &description) { m_description = description; } - /*! - * Get port - */ + //! \brief Get port qint32 getPort() const { return m_port; } - /*! - * \brief Set port - */ + //! \brief Set port void setPort(qint32 port) { m_port = port; } - /*! - * \brief Is valid for login? - */ + //! \brief Is valid for login? bool isValidForLogin() const; - /*! - * \brief Equal operator == - */ + //! \brief Equal operator == bool operator ==(const CServer &other) const; - /*! - * \brief Unequal operator != - */ + //! \brief Unequal operator != bool operator !=(const CServer &other) const; - /*! - * \copydoc CValueObject::getValueHash() - */ + //! \copydoc CValueObject::getValueHash() virtual uint getValueHash() const override; - /*! - * \brief Register metadata - */ + //! \brief Register metadata static void registerMetadata(); - /*! - * \brief Properties by index - */ + //! \brief Properties by index enum ColumnIndex { IndexName = 0, @@ -137,19 +92,13 @@ namespace BlackMisc IndexUserPassword }; - /*! - * \copydoc CValueObject::propertyByIndex(int) - */ + //! \copydoc CValueObject::propertyByIndex(int) QVariant propertyByIndex(int index) const override; - /*! - * \copydoc CValueObject::setPropertyByIndex(const QVariant &, int index) - */ + //! \copydoc CValueObject::setPropertyByIndex(const QVariant &, int index) void setPropertyByIndex(const QVariant &variant, int index) override; - /*! - * \copydoc CValueObject::propertyByIndexAsString() - */ + //! \copydoc CValueObject::propertyByIndexAsString() QString propertyByIndexAsString(int index, bool i18n) const; protected: diff --git a/src/blackmisc/nwtextmessage.cpp b/src/blackmisc/nwtextmessage.cpp index aa5e71b9b..88780d07c 100644 --- a/src/blackmisc/nwtextmessage.cpp +++ b/src/blackmisc/nwtextmessage.cpp @@ -47,46 +47,6 @@ namespace BlackMisc return this->CValueObject::isA(metaTypeId); } - /* - * Compare - */ - int CTextMessage::compareImpl(const CValueObject &otherBase) const - { - const auto &other = static_cast(otherBase); - - int result; - if ((result = compare(this->m_senderCallsign, other.m_senderCallsign))) { return result; } - if ((result = compare(this->m_recipientCallsign, other.m_recipientCallsign))) { return result; } - if ((result = compare(this->m_frequency, other.m_frequency))) { return result; } - if (this->m_received < other.m_received) { return -1; } - if (this->m_received > other.m_received) { return 1; } - return this->m_message.compare(other.m_message); - } - - /* - * Marshall to DBus - */ - void CTextMessage::marshallToDbus(QDBusArgument &argument) const - { - argument << this->m_senderCallsign; - argument << this->m_recipientCallsign; - argument << this->m_message; - argument << this->m_frequency; - argument << this->m_received; - } - - /* - * Unmarshall from DBus - */ - void CTextMessage::unmarshallFromDbus(const QDBusArgument &argument) - { - argument >> this->m_senderCallsign; - argument >> this->m_recipientCallsign; - argument >> this->m_message; - argument >> this->m_frequency; - argument >> this->m_received; - } - /* * Private message? */ @@ -229,13 +189,46 @@ namespace BlackMisc return candidate.right(4); } + /* + * Compare + */ + int CTextMessage::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + /* + * Marshall to DBus + */ + void CTextMessage::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall from DBus + */ + void CTextMessage::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + + /* + * Hash + */ + uint CTextMessage::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + /* * Equal? */ bool CTextMessage::operator ==(const CTextMessage &other) const { if (this == &other) return true; - return compare(*this, other); + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } /* @@ -246,20 +239,6 @@ namespace BlackMisc return !((*this) == other); } - /* - * Hash - */ - uint CTextMessage::getValueHash() const - { - QList hashs; - hashs << qHash(this->m_senderCallsign.getValueHash()); - hashs << qHash(this->m_recipientCallsign.getValueHash()); - hashs << qHash(this->m_frequency.getValueHash()); - hashs << qHash(this->m_message); - hashs << qHash(this->m_received); - return BlackMisc::calculateHash(hashs, "CTextMessage"); - } - /* * Register metadata */ diff --git a/src/blackmisc/nwtextmessage.h b/src/blackmisc/nwtextmessage.h index 798692098..987a5a367 100644 --- a/src/blackmisc/nwtextmessage.h +++ b/src/blackmisc/nwtextmessage.h @@ -235,6 +235,7 @@ namespace BlackMisc virtual void unmarshallFromDbus(const QDBusArgument &argument) override; private: + BLACK_ENABLE_TUPLE_CONVERSION(CTextMessage) QString m_message; QDateTime m_received; BlackMisc::Aviation::CCallsign m_senderCallsign; @@ -244,6 +245,7 @@ namespace BlackMisc } // namespace } // namespace +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Network::CTextMessage, (o.m_message, o.m_received, o.m_senderCallsign, o.m_recipientCallsign, o.m_frequency)) Q_DECLARE_METATYPE(BlackMisc::Network::CTextMessage) #endif // guard diff --git a/src/blackmisc/nwuser.cpp b/src/blackmisc/nwuser.cpp index d0186a96b..7a0fa74ce 100644 --- a/src/blackmisc/nwuser.cpp +++ b/src/blackmisc/nwuser.cpp @@ -77,6 +77,14 @@ namespace BlackMisc return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } + /* + * Unequal? + */ + bool CUser::operator !=(const CUser &other) const + { + return !((*this) == other); + } + /* * Exchange data */ @@ -105,14 +113,6 @@ namespace BlackMisc this->setCallsign(otherUser.getCallsign()); } - /* - * Unequal? - */ - bool CUser::operator !=(const CUser &other) const - { - return !((*this) == other); - } - /* * Hash */ diff --git a/src/blackmisc/statusmessage.cpp b/src/blackmisc/statusmessage.cpp index 1a1d8a66f..9b338e88a 100644 --- a/src/blackmisc/statusmessage.cpp +++ b/src/blackmisc/statusmessage.cpp @@ -47,22 +47,9 @@ namespace BlackMisc bool CStatusMessage::isA(int metaTypeId) const { if (metaTypeId == qMetaTypeId()) { return true; } - return this->CValueObject::isA(metaTypeId); } - /* - * Compare - */ - int CStatusMessage::compareImpl(const CValueObject &otherBase) const - { - const auto &other = static_cast(otherBase); - - if (this->m_type < other.m_type) { return -1; } - if (this->m_type > other.m_type) { return 1; } - return this->m_message.compare(other.m_message); - } - /* * Metadata */ @@ -105,19 +92,6 @@ namespace BlackMisc } } - /* - * Hash - */ - uint CStatusMessage::getValueHash() const - { - QList hashs; - hashs << qHash(static_cast(this->m_type)); - hashs << qHash(static_cast(this->m_severity)); - hashs << qHash(this->m_message); - hashs << qHash(this->m_timestamp); - return BlackMisc::calculateHash(hashs, "CStatusMessage"); - } - /* * Type */ @@ -202,14 +176,45 @@ namespace BlackMisc } /* - * Equal + * Compare + */ + int CStatusMessage::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + /* + * Marshall to DBus + */ + void CStatusMessage::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall from DBus + */ + void CStatusMessage::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + + /* + * Hash + */ + uint CStatusMessage::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + + /* + * Equal? */ bool CStatusMessage::operator ==(const CStatusMessage &other) const { - return this->m_severity == other.m_severity && - this->m_type == other.m_type && - this->m_timestamp == other.m_timestamp && - this->m_message == other.m_message; + if (this == &other) return true; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } /* @@ -220,32 +225,6 @@ namespace BlackMisc return !(other == (*this)); } - /* - * To DBus - */ - void CStatusMessage::marshallToDbus(QDBusArgument &arg) const - { - arg << this->m_message; - arg << static_cast(this->m_type); - arg << static_cast(this->m_severity); - arg << this->m_timestamp; - } - - /* - * From DBus - */ - void CStatusMessage::unmarshallFromDbus(const QDBusArgument &arg) - { - qint32 type; - qint32 severity; - arg >> this->m_message; - arg >> type; - arg >> severity; - arg >> m_timestamp; - this->m_type = static_cast(type); - this->m_severity = static_cast(severity); - } - /* * Property by index */ diff --git a/src/blackmisc/statusmessage.h b/src/blackmisc/statusmessage.h index 3c71d6191..5e9c03372 100644 --- a/src/blackmisc/statusmessage.h +++ b/src/blackmisc/statusmessage.h @@ -1,6 +1,7 @@ #ifndef BLACKMISC_STATUSMESSAGE_H #define BLACKMISC_STATUSMESSAGE_H +#include "blackmiscfreefunctions.h" #include "valueobject.h" #include @@ -52,6 +53,7 @@ namespace BlackMisc }; private: + BLACK_ENABLE_TUPLE_CONVERSION(CStatusMessage) StatusType m_type; StatusSeverity m_severity; QString m_message; @@ -148,6 +150,9 @@ 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) #endif // guard diff --git a/src/blackmisc/voiceroom.cpp b/src/blackmisc/voiceroom.cpp new file mode 100644 index 000000000..a71a04d36 --- /dev/null +++ b/src/blackmisc/voiceroom.cpp @@ -0,0 +1,144 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +/*! + \file +*/ + +#include "voiceroom.h" +#include "blackmisc/blackmiscfreefunctions.h" +#include +#include +#include + +namespace BlackMisc +{ + namespace Audio + { + CVoiceRoom::CVoiceRoom(const QString &serverUrl, bool connected) : + m_connected(connected), m_audioPlaying(false) + { + if (serverUrl.contains("/")) + { + QString url = serverUrl.trimmed().toLower(); + url.replace(CVoiceRoom::protocolComplete(), ""); + url.replace(CVoiceRoom::protocol(), ""); + QStringList splitParts = serverUrl.split("/"); + m_hostname = splitParts.at(0); + m_channel = splitParts.at(1); + } + } + + /* + * Compare + */ + int CVoiceRoom::compareImpl(const CValueObject &otherBase) const + { + const auto &other = static_cast(otherBase); + return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); + } + + /* + * Marshall to DBus + */ + void CVoiceRoom::marshallToDbus(QDBusArgument &argument) const + { + argument << TupleConverter::toTuple(*this); + } + + /* + * Unmarshall from DBus + */ + void CVoiceRoom::unmarshallFromDbus(const QDBusArgument &argument) + { + argument >> TupleConverter::toTuple(*this); + } + + /* + * Hash + */ + uint CVoiceRoom::getValueHash() const + { + return qHash(TupleConverter::toTuple(*this)); + } + + /* + * Equal? + */ + bool CVoiceRoom::operator ==(const CVoiceRoom &other) const + { + if (this == &other) return true; + return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); + } + + /* + * Unequal? + */ + bool CVoiceRoom::operator !=(const CVoiceRoom &other) const + { + return !((*this) == other); + } + + /* + * Metadata + */ + void CVoiceRoom::registerMetadata() + { + qRegisterMetaType(); + qDBusRegisterMetaType(); + } + + /* + * To string + */ + QString CVoiceRoom::convertToQString(bool /* i18n */) const + { + if (!this->isValid()) return "Invalid"; + QString s = this->getVoiceRoomUrl(false); + s.append(this ->isConnected() ? " connected" : " unconnected"); + if (this->m_audioPlaying) s.append(" playing"); + return s; + } + + /* + * metaTypeId + */ + int CVoiceRoom::getMetaTypeId() const + { + return qMetaTypeId(); + } + + /* + * is a + */ + bool CVoiceRoom::isA(int metaTypeId) const + { + if (metaTypeId == qMetaTypeId()) { return true; } + + return CValueObject::isA(metaTypeId); + } + + /* + * Server URL + */ + QString CVoiceRoom::getVoiceRoomUrl(bool noProtocol) const + { + if (!this->isValid()) return ""; + QString url(noProtocol ? "" : CVoiceRoom::protocolComplete()); + url.append(this->m_hostname); + url.append("/"); + url.append(this->m_channel); + return url; + } + + /* + * ATIS voice channel + */ + bool CVoiceRoom::isAtis() const + { + return (this->m_channel.contains("ATIS", Qt::CaseInsensitive)); + } + } // Voice +} // BlackMisc diff --git a/src/blackmisc/voiceroom.h b/src/blackmisc/voiceroom.h new file mode 100644 index 000000000..05178b305 --- /dev/null +++ b/src/blackmisc/voiceroom.h @@ -0,0 +1,189 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +/*! + \file +*/ + +#include "valueobject.h" +#include + +#ifndef BLACKMISC_VOICEROOM_H +#define BLACKMISC_VOICEROOM_H + +namespace BlackMisc +{ + namespace Audio + { + /*! + * Value object encapsulating information of a voice room + */ + class CVoiceRoom : public BlackMisc::CValueObject + { + public: + + /*! + * Default constructor. + */ + CVoiceRoom() : + m_connected(false), m_audioPlaying(false) {} + + /*! + * Constructor. + * \param hostname + * \param channel + */ + CVoiceRoom(const QString &hostname, const QString &channel) : + m_hostname(hostname), m_channel(channel), m_connected(false), m_audioPlaying(false) {} + + /*! + * Constructor. + * \param serverUrl + * \param connected + */ + CVoiceRoom(const QString &serverUrl, bool connected = false); + + /*! + * \copydoc CValueObject::toQVariant + */ + virtual QVariant toQVariant() const override + { + return QVariant::fromValue(*this); + } + + /*! + * Get the host name + * \return + */ + const QString &getHostName() const { return m_hostname; } + + /*! + * Get the voice room + */ + const QString &getChannel() const { return m_channel; } + + /*! + * \brief Set the host name + */ + void setHostName(const QString &hostName) { m_hostname = hostName; } + + /*! + * \brief Set the voice channel + */ + void setChannel(const QString &channel) { m_channel = channel; } + + /*! + * \brief Server URL + * \param noProtocol either with (pseudo) protocol prefix or without + * \return + */ + QString getVoiceRoomUrl(bool noProtocol = true) const; + + /*! + * \brief Valid voice room object? + * \return + */ + bool isValid() const { return !this->m_hostname.isEmpty() && !this->m_channel.isEmpty(); } + + /*! + * \brief Is connected + * \return + */ + bool isConnected() const { return this->isValid() && this->m_connected; } + + /*! + * \brief Set connected status + * \param isConnected + */ + void setConnected(bool isConnected) { this->m_connected = isConnected; } + + /*! + * \brief Is audio playing in this room? + * \return + */ + bool isAudioPlaying() const { return this->m_audioPlaying; } + + /*! + * \brief Set audio playing + * \param playing + */ + void setAudioPlaying(bool playing) { this->m_audioPlaying = playing; } + + /*! + * \brief Is ATIS voice channel + * \return + */ + bool isAtis() const; + + /*! + * \brief Equal operator == + * \param other + * @return + */ + bool operator ==(const CVoiceRoom &other) const; + + /*! + * \brief Unequal operator == + * \param other + * @return + */ + bool operator !=(const CVoiceRoom &other) const; + + /*! + * \copydoc CValueObject::getValueHash + */ + virtual uint getValueHash() const override; + + /*! + * \brief Register metadata + */ + static void registerMetadata(); + + /*! + * \brief Protocol prefix + * \return + */ + static const QString &protocol() { static QString p("vvl"); return p; } + + /*! + * \brief Protocol + * \return with protocol prefix or without + */ + static const QString &protocolComplete() { static QString p("vvl://"); return p; } + + protected: + + //! \copydoc CValueObject::convertToQString + virtual QString convertToQString(bool i18n = false) const override; + + //! \copydoc CValueObject::getMetaTypeId + virtual int getMetaTypeId() const override; + + //! \copydoc CValueObject::isA + virtual bool isA(int metaTypeId) const override; + + //! \copydoc CValueObject::compareImpl + virtual int compareImpl(const CValueObject &other) const override; + + //! \copydoc CValueObject::marshallToDbus + virtual void marshallToDbus(QDBusArgument &argument) const override; + + //! \copydoc CValueObject::unmarshallFromDbus + virtual void unmarshallFromDbus(const QDBusArgument &argument) override; + + private: + BLACK_ENABLE_TUPLE_CONVERSION(CVoiceRoom) + QString m_hostname; + QString m_channel; + bool m_connected; + bool m_audioPlaying; + }; + } // Voice +} // BlackMisc + +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Audio::CVoiceRoom, (o.m_hostname, o.m_channel, o.m_connected, o.m_audioPlaying)) +Q_DECLARE_METATYPE(BlackMisc::Audio::CVoiceRoom) + +#endif // guard