From 4094b18c39ba97b77c16a5ca4b6456e9ac24c190 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Tue, 25 Aug 2020 23:28:18 +0100 Subject: [PATCH] Issue #77 Remove unneeded classes --- .../blackmiscquantities/samplesaviation.cpp | 11 --- src/blackmisc/aviation/aircraftlights.cpp | 7 +- src/blackmisc/aviation/aircraftlights.h | 17 +++-- src/blackmisc/compare.h | 54 --------------- src/blackmisc/nullable.cpp | 68 ------------------- src/blackmisc/nullable.h | 59 ---------------- 6 files changed, 15 insertions(+), 201 deletions(-) delete mode 100644 src/blackmisc/nullable.cpp delete mode 100644 src/blackmisc/nullable.h diff --git a/samples/blackmiscquantities/samplesaviation.cpp b/samples/blackmiscquantities/samplesaviation.cpp index b9979b3c3..5def4a772 100644 --- a/samples/blackmiscquantities/samplesaviation.cpp +++ b/samples/blackmiscquantities/samplesaviation.cpp @@ -99,17 +99,6 @@ namespace BlackSample out << frankfurt << Qt::endl; out << "-----------------------------------------------" << Qt::endl; - CMetaMemberComparator cmp; - QList> list = cmp(station1, station3); - for (const auto &member : as_const(list)) { out << member.first << (member.second ? " equal" : " NOT equal") << Qt::endl; } - out << Qt::endl; - list = cmp(station1, station3, { "controller" }); - for (const auto &member : as_const(list)) { out << member.first << (member.second ? " equal" : " NOT equal") << Qt::endl; } - out << Qt::endl; - list = cmp(station1, station3, { "controller", "homebase" }); - for (const auto &member : as_const(list)) { out << member.first << (member.second ? " equal" : " NOT equal") << Qt::endl; } - out << "-----------------------------------------------" << Qt::endl; - return 0; } } // namespace diff --git a/src/blackmisc/aviation/aircraftlights.cpp b/src/blackmisc/aviation/aircraftlights.cpp index d88f6d87d..3e4fc3d8f 100644 --- a/src/blackmisc/aviation/aircraftlights.cpp +++ b/src/blackmisc/aviation/aircraftlights.cpp @@ -100,11 +100,11 @@ namespace BlackMisc CVariant CAircraftLights::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } - if (INullable::canHandleIndex(index)) { return INullable::propertyByIndex(index); } const ColumnIndex i = index.frontCasted(); switch (i) { + case IndexIsNull: return CVariant::from(this->isNull()); case IndexBeacon: return CVariant::from(m_beaconOn); case IndexLanding: return CVariant::from(m_landingOn); case IndexLogo: return CVariant::from(m_logoOn); @@ -120,11 +120,11 @@ namespace BlackMisc void CAircraftLights::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) { if (index.isMyself()) { (*this) = variant.to(); return; } - if (INullable::canHandleIndex(index)) { INullable::setPropertyByIndex(index, variant); return; } const ColumnIndex i = index.frontCasted(); switch (i) { + case IndexIsNull: m_isNull = variant.toBool(); break; case IndexBeacon: m_beaconOn = variant.toBool(); break; case IndexLanding: m_landingOn = variant.toBool(); break; case IndexLogo: m_logoOn = variant.toBool(); break; @@ -142,6 +142,7 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); switch (i) { + case IndexIsNull: return Compare::compare(m_isNull, compareValue.isNull()); case IndexBeacon: return Compare::compare(m_beaconOn, compareValue.isBeaconOn()); case IndexLanding: return Compare::compare(m_landingOn, compareValue.isLandingOn()); case IndexLogo: return Compare::compare(m_logoOn, compareValue.isLogoOn()); @@ -152,7 +153,7 @@ namespace BlackMisc case IndexRecognition: return Compare::compare(m_recognition, compareValue.isRecognitionOn()); default: break; } - return INullable::comparePropertyByIndex(index.copyFrontRemoved(), compareValue); + return 0; } void CAircraftLights::setAllOn() diff --git a/src/blackmisc/aviation/aircraftlights.h b/src/blackmisc/aviation/aircraftlights.h index bf423a545..fe502c549 100644 --- a/src/blackmisc/aviation/aircraftlights.h +++ b/src/blackmisc/aviation/aircraftlights.h @@ -16,7 +16,6 @@ #include "blackmisc/propertyindex.h" #include "blackmisc/valueobject.h" #include "blackmisc/variant.h" -#include "blackmisc/nullable.h" #include #include @@ -28,14 +27,13 @@ namespace BlackMisc class CAircraftSituation; //! Value object encapsulating information about aircraft's lights - class BLACKMISC_EXPORT CAircraftLights : - public CValueObject, - public INullable + class BLACKMISC_EXPORT CAircraftLights : public CValueObject { public: //! Properties by index enum ColumnIndex { + IndexIsNull = CPropertyIndex::GlobalIndexINullable, IndexStrobe = CPropertyIndex::GlobalIndexCAircraftLights, IndexLanding, IndexTaxi, @@ -49,8 +47,8 @@ namespace BlackMisc //! Default constructor CAircraftLights() = default; - //! Constructor, init to null - using INullable::INullable; + //! Null constructor + CAircraftLights(std::nullptr_t) : m_isNull(true) {} //! Constructor CAircraftLights(bool strobeOn, bool landingOn, bool taxiOn, bool beaconOn, bool navOn, bool logoOn); @@ -136,7 +134,14 @@ namespace BlackMisc //! Guessed lights static CAircraftLights guessedLights(const CAircraftSituation &situation); + //! Null? + bool isNull() const { return m_isNull; } + + //! Null? + void setNull(bool null) { m_isNull = null; } + private: + bool m_isNull = false; //!< null? bool m_strobeOn = false; bool m_landingOn = false; bool m_taxiOn = false; diff --git a/src/blackmisc/compare.h b/src/blackmisc/compare.h index 5b30df373..03baf5a0e 100644 --- a/src/blackmisc/compare.h +++ b/src/blackmisc/compare.h @@ -183,60 +183,6 @@ namespace BlackMisc }; } // Mixin - - /*! - * Helps with debugging Mixin::EqualsByMetaClass. - */ - class CMetaMemberComparator - { - public: - //! Return list of pairs containing member name and bool indicating if member is equal. - template ::value, int> = 0> - QList> operator ()(const T &a, const T &b) const - { - constexpr auto meta = introspect().without(MetaFlags()); - auto result = baseEquals(static_cast *>(&a), static_cast *>(&b)); - meta.forEachMember([ & ](auto member) - { - constexpr auto flags = decltype(member.m_flags)(); - result.append(qMakePair(member.latin1Name(), membersEqual(member.in(a), member.in(b), flags & MetaFlags()))); - }); - return result; - } - - //! Recurse into one of the submembers of T, comparing members of that member. - template ::value, int> = 0> - QList> operator ()(const T &a, const T &b, QStringList memberNames) const // clazy:exclude=function-args-by-ref - { - if (memberNames.isEmpty()) { return CMetaMemberComparator()(a, b); } - constexpr auto meta = introspect().without(MetaFlags()); - auto result = baseEquals(static_cast *>(&a), static_cast *>(&b), memberNames); - const auto memberName = memberNames.takeFirst(); - meta.forEachMember([ & ](auto member) - { - const auto p = [ & ](const auto &m) { return qMakePair(memberName + '.' + m.first, m.second); }; - if (member.latin1Name() == memberName) { result.append(makeRange(CMetaMemberComparator()(member.in(a), member.in(b), memberNames)).transform(p)); } - }); - return result; - } - - //! Return empty list if T doesn't have a metaclass. - template ::value, int> = 0> - QList> operator ()(const T &, const T &) const { return {}; } - - //! Return empty list if T doesn't have a metaclass. - template ::value, int> = 0> - QList> operator ()(const T &, const T &, QStringList) const { return {}; } // clazy:exclude=function-args-by-ref - - private: - template static auto baseEquals(const T *a, const T *b) { return CMetaMemberComparator()(*a, *b); } - template static auto baseEquals(const T *a, const T *b, const QStringList &memberNames) { return CMetaMemberComparator()(*a, *b, memberNames); } - static auto baseEquals(const void *, const void *, const QStringList & = {}) { return QList>(); } - static auto baseEquals(const CEmpty *, const CEmpty *, const QStringList & = {}) { return QList>(); } - - template static bool membersEqual(const T &a, const T &b, std::true_type) { return a.compare(b, Qt::CaseInsensitive) == 0; } - template static bool membersEqual(const T &a, const T &b, std::false_type) { return a == b; } - }; } // BlackMisc #endif diff --git a/src/blackmisc/nullable.cpp b/src/blackmisc/nullable.cpp deleted file mode 100644 index a90f257f8..000000000 --- a/src/blackmisc/nullable.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright (C) 2017 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, - * or distributed except according to the terms contained in the LICENSE file. - */ - -#include "blackmisc/nullable.h" -#include "blackmisc/comparefunctions.h" -#include "blackmisc/verify.h" - -namespace BlackMisc -{ - INullable::INullable(std::nullptr_t null) : m_isNull(true) - { - Q_UNUSED(null); - } - - bool INullable::canHandleIndex(const CPropertyIndex &index) - { - if (index.isEmpty()) { return false; } - int i = index.frontCasted(); - return (i >= static_cast(IndexIsNull)) && (i <= static_cast(IndexIsNull)); - } - - CVariant INullable::propertyByIndex(const CPropertyIndex &index) const - { - if (!index.isEmpty()) - { - ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexIsNull: - return CVariant::fromValue(this->isNull()); - default: - break; - } - } - const QString m = QStringLiteral("Cannot handle index %1").arg(index.toQString()); - BLACK_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable(m)); - return CVariant::fromValue(m); - } - - void INullable::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) - { - if (!index.isEmpty()) - { - ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexIsNull: - this->setNull(variant.toBool()); - return; - default: - break; - } - } - const QString m = QStringLiteral("Cannot handle index %1").arg(index.toQString()); - BLACK_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable(m)); - } - - int INullable::comparePropertyByIndex(const CPropertyIndex &index, const INullable &compareValue) const - { - Q_UNUSED(index); - return Compare::compare(this->m_isNull, compareValue.m_isNull); - } -} // namespace diff --git a/src/blackmisc/nullable.h b/src/blackmisc/nullable.h deleted file mode 100644 index b8e26a1ed..000000000 --- a/src/blackmisc/nullable.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (C) 2017 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, - * or distributed except according to the terms contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKMISC_NULLABLE_H -#define BLACKMISC_NULLABLE_H - -#include "blackmisc/blackmiscexport.h" -#include "blackmisc/propertyindex.h" -#include "blackmisc/variant.h" - -namespace BlackMisc -{ - //! Nullable value object - class BLACKMISC_EXPORT INullable - { - public: - //! Properties by index - enum ColumnIndex - { - IndexIsNull = CPropertyIndex::GlobalIndexINullable, - }; - - //! Constructor, init to null - INullable(std::nullptr_t null); - - //! Null? - bool isNull() const { return m_isNull; } - - //! Null? - void setNull(bool null) { m_isNull = null; } - - //! Can given index be handled - static bool canHandleIndex(const BlackMisc::CPropertyIndex &index); - - protected: - //! Constructor - INullable() {} - - //! \copydoc BlackMisc::Mixin::Index::propertyByIndex - CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; - - //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex - void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant); - - //! Compare for index - int comparePropertyByIndex(const CPropertyIndex &index, const INullable &compareValue) const; - - bool m_isNull = false; //!< null? - }; -} // namespace - -#endif // guard