mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
Issue #77 Remove unneeded classes
This commit is contained in:
@@ -99,17 +99,6 @@ namespace BlackSample
|
||||
out << frankfurt << Qt::endl;
|
||||
out << "-----------------------------------------------" << Qt::endl;
|
||||
|
||||
CMetaMemberComparator cmp;
|
||||
QList<QPair<QString, bool>> 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
|
||||
|
||||
@@ -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<ColumnIndex>();
|
||||
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<CAircraftLights>(); return; }
|
||||
if (INullable::canHandleIndex(index)) { INullable::setPropertyByIndex(index, variant); return; }
|
||||
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
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<ColumnIndex>();
|
||||
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()
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/nullable.h"
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
@@ -28,14 +27,13 @@ namespace BlackMisc
|
||||
class CAircraftSituation;
|
||||
|
||||
//! Value object encapsulating information about aircraft's lights
|
||||
class BLACKMISC_EXPORT CAircraftLights :
|
||||
public CValueObject<CAircraftLights>,
|
||||
public INullable
|
||||
class BLACKMISC_EXPORT CAircraftLights : public CValueObject<CAircraftLights>
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -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 <typename T, std::enable_if_t<THasMetaClass<T>::value, int> = 0>
|
||||
QList<QPair<QString, bool>> operator ()(const T &a, const T &b) const
|
||||
{
|
||||
constexpr auto meta = introspect<T>().without(MetaFlags<DisabledForComparison>());
|
||||
auto result = baseEquals(static_cast<const TBaseOfT<T> *>(&a), static_cast<const TBaseOfT<T> *>(&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<CaseInsensitiveComparison>())));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
//! Recurse into one of the submembers of T, comparing members of that member.
|
||||
template <typename T, std::enable_if_t<THasMetaClass<T>::value, int> = 0>
|
||||
QList<QPair<QString, bool>> 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<T>().without(MetaFlags<DisabledForComparison>());
|
||||
auto result = baseEquals(static_cast<const TBaseOfT<T> *>(&a), static_cast<const TBaseOfT<T> *>(&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 <typename T, std::enable_if_t<!THasMetaClass<T>::value, int> = 0>
|
||||
QList<QPair<QString, bool>> operator ()(const T &, const T &) const { return {}; }
|
||||
|
||||
//! Return empty list if T doesn't have a metaclass.
|
||||
template <typename T, std::enable_if_t<!THasMetaClass<T>::value, int> = 0>
|
||||
QList<QPair<QString, bool>> operator ()(const T &, const T &, QStringList) const { return {}; } // clazy:exclude=function-args-by-ref
|
||||
|
||||
private:
|
||||
template <typename T> static auto baseEquals(const T *a, const T *b) { return CMetaMemberComparator()(*a, *b); }
|
||||
template <typename T> 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<QPair<QString, bool>>(); }
|
||||
static auto baseEquals(const CEmpty *, const CEmpty *, const QStringList & = {}) { return QList<QPair<QString, bool>>(); }
|
||||
|
||||
template <typename T> static bool membersEqual(const T &a, const T &b, std::true_type) { return a.compare(b, Qt::CaseInsensitive) == 0; }
|
||||
template <typename T> static bool membersEqual(const T &a, const T &b, std::false_type) { return a == b; }
|
||||
};
|
||||
} // BlackMisc
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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<int>();
|
||||
return (i >= static_cast<int>(IndexIsNull)) && (i <= static_cast<int>(IndexIsNull));
|
||||
}
|
||||
|
||||
CVariant INullable::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (!index.isEmpty())
|
||||
{
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
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<ColumnIndex>();
|
||||
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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user