mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-01 06:35:41 +08:00
refs #140 to demonstrate the new tuple framework, adapted five typical value classes to use it
This commit is contained in:
committed by
Klaus Basan
parent
fcd3dc09ef
commit
7f92b5dbc9
@@ -45,12 +45,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
const auto &other = static_cast<const CAircraftIcao &>(otherBase);
|
const auto &other = static_cast<const CAircraftIcao &>(otherBase);
|
||||||
|
|
||||||
const auto lhs = std::tie(this->m_designator, this->m_color, this->m_airline, this->m_livery);
|
return compare(TupleConverter<CAircraftIcao>::toTuple(*this), TupleConverter<CAircraftIcao>::toTuple(other));
|
||||||
const auto rhs = std::tie(other.m_designator, other.m_color, other.m_airline, other.m_livery);
|
|
||||||
|
|
||||||
if (lhs < rhs) { return -1; }
|
|
||||||
if (lhs > rhs) { return 1; }
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -58,11 +53,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
void CAircraftIcao::marshallToDbus(QDBusArgument &argument) const
|
void CAircraftIcao::marshallToDbus(QDBusArgument &argument) const
|
||||||
{
|
{
|
||||||
argument << this->m_designator;
|
argument << TupleConverter<CAircraftIcao>::toTuple(*this);
|
||||||
argument << this->m_airline;
|
|
||||||
argument << this->m_livery;
|
|
||||||
argument << this->m_type;
|
|
||||||
argument << this->m_color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -70,11 +61,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
void CAircraftIcao::unmarshallFromDbus(const QDBusArgument &argument)
|
void CAircraftIcao::unmarshallFromDbus(const QDBusArgument &argument)
|
||||||
{
|
{
|
||||||
argument >> this->m_designator;
|
argument >> TupleConverter<CAircraftIcao>::toTuple(*this);
|
||||||
argument >> this->m_airline;
|
|
||||||
argument >> this->m_livery;
|
|
||||||
argument >> this->m_type;
|
|
||||||
argument >> this->m_color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -100,7 +87,7 @@ namespace BlackMisc
|
|||||||
bool CAircraftIcao::operator ==(const CAircraftIcao &other) const
|
bool CAircraftIcao::operator ==(const CAircraftIcao &other) const
|
||||||
{
|
{
|
||||||
if (this == &other) return true;
|
if (this == &other) return true;
|
||||||
return compare(*this, other) == 0;
|
return TupleConverter<CAircraftIcao>::toTuple(*this) == TupleConverter<CAircraftIcao>::toTuple(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -116,12 +103,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
uint CAircraftIcao::getValueHash() const
|
uint CAircraftIcao::getValueHash() const
|
||||||
{
|
{
|
||||||
QList<uint> hashs;
|
return qHash(TupleConverter<CAircraftIcao>::toTuple(*this));
|
||||||
hashs << qHash(this->m_designator);
|
|
||||||
hashs << qHash(this->m_airline);
|
|
||||||
hashs << qHash(this->m_type);
|
|
||||||
hashs << qHash(this->m_color);
|
|
||||||
return BlackMisc::calculateHash(hashs, "CAircraftIcao");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ namespace BlackMisc
|
|||||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BLACK_ENABLE_TUPLE_CONVERSION(CAircraftIcao)
|
||||||
QString m_designator;
|
QString m_designator;
|
||||||
QString m_type;
|
QString m_type;
|
||||||
QString m_airline;
|
QString m_airline;
|
||||||
@@ -162,6 +163,7 @@ namespace BlackMisc
|
|||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAircraftIcao, (o.m_designator, o.m_type, o.m_airline, o.m_livery, o.m_color))
|
||||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CAircraftIcao)
|
Q_DECLARE_METATYPE(BlackMisc::Aviation::CAircraftIcao)
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -50,11 +50,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
const auto &other = static_cast<const CCoordinateGeodetic &>(otherBase);
|
const auto &other = static_cast<const CCoordinateGeodetic &>(otherBase);
|
||||||
|
|
||||||
int cmp = compare(this->m_latitude, other.m_latitude);
|
return compare(TupleConverter<CCoordinateGeodetic>::toTuple(*this), TupleConverter<CCoordinateGeodetic>::toTuple(other));
|
||||||
if (cmp) { return cmp; }
|
|
||||||
cmp = compare(this->m_longitude, other.m_longitude);
|
|
||||||
if (cmp) { return cmp; }
|
|
||||||
return compare(this->m_height, other.m_height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -62,9 +58,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
void CCoordinateGeodetic::marshallToDbus(QDBusArgument &argument) const
|
void CCoordinateGeodetic::marshallToDbus(QDBusArgument &argument) const
|
||||||
{
|
{
|
||||||
argument << this->m_latitude;
|
argument << TupleConverter<CCoordinateGeodetic>::toTuple(*this);
|
||||||
argument << this->m_longitude;
|
|
||||||
argument << this->m_height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -72,9 +66,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
void CCoordinateGeodetic::unmarshallFromDbus(const QDBusArgument &argument)
|
void CCoordinateGeodetic::unmarshallFromDbus(const QDBusArgument &argument)
|
||||||
{
|
{
|
||||||
argument >> this->m_latitude;
|
argument >> TupleConverter<CCoordinateGeodetic>::toTuple(*this);
|
||||||
argument >> this->m_longitude;
|
|
||||||
argument >> this->m_height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -83,9 +75,7 @@ namespace BlackMisc
|
|||||||
bool CCoordinateGeodetic::operator ==(const CCoordinateGeodetic &other) const
|
bool CCoordinateGeodetic::operator ==(const CCoordinateGeodetic &other) const
|
||||||
{
|
{
|
||||||
if (this == &other) return true;
|
if (this == &other) return true;
|
||||||
return this->m_height == other.m_height &&
|
return TupleConverter<CCoordinateGeodetic>::toTuple(*this) == TupleConverter<CCoordinateGeodetic>::toTuple(other);
|
||||||
this->m_latitude == other.m_latitude &&
|
|
||||||
this->m_longitude == other.m_longitude;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -110,11 +100,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
uint CCoordinateGeodetic::getValueHash() const
|
uint CCoordinateGeodetic::getValueHash() const
|
||||||
{
|
{
|
||||||
QList<uint> hashs;
|
return qHash(TupleConverter<CCoordinateGeodetic>::toTuple(*this));
|
||||||
hashs << this->m_latitude.getValueHash();
|
|
||||||
hashs << this->m_longitude.getValueHash();
|
|
||||||
hashs << this->m_height.getValueHash();
|
|
||||||
return BlackMisc::calculateHash(hashs, "CCoordinateGeodetic");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ namespace BlackMisc
|
|||||||
class CCoordinateGeodetic : public CValueObject, public ICoordinateGeodetic
|
class CCoordinateGeodetic : public CValueObject, public ICoordinateGeodetic
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
BLACK_ENABLE_TUPLE_CONVERSION(CCoordinateGeodetic)
|
||||||
BlackMisc::Geo::CLatitude m_latitude; //!< Latitude
|
BlackMisc::Geo::CLatitude m_latitude; //!< Latitude
|
||||||
BlackMisc::Geo::CLongitude m_longitude; //!< Longitude
|
BlackMisc::Geo::CLongitude m_longitude; //!< Longitude
|
||||||
BlackMisc::PhysicalQuantities::CLength m_height; //!< height
|
BlackMisc::PhysicalQuantities::CLength m_height; //!< height
|
||||||
@@ -236,6 +237,7 @@ namespace BlackMisc
|
|||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Geo::CCoordinateGeodetic, (o.m_latitude, o.m_longitude, o.m_height))
|
||||||
Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateGeodetic)
|
Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateGeodetic)
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -52,12 +52,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
const auto &other = static_cast<const CVector3DBase &>(otherBase);
|
const auto &other = static_cast<const CVector3DBase &>(otherBase);
|
||||||
|
|
||||||
const auto lhs = std::tie(this->m_i, this->m_j, this->m_k);
|
return compare(TupleConverter<CVector3DBase>::toTuple(*this), TupleConverter<CVector3DBase>::toTuple(other));
|
||||||
const auto rhs = std::tie(other.m_i, other.m_j, other.m_k);
|
|
||||||
|
|
||||||
if (lhs < rhs) { return -1; }
|
|
||||||
if (lhs > rhs) { return 1; }
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -162,9 +157,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
template <class ImplVector> void CVector3DBase<ImplVector>::marshallToDbus(QDBusArgument &argument) const
|
template <class ImplVector> void CVector3DBase<ImplVector>::marshallToDbus(QDBusArgument &argument) const
|
||||||
{
|
{
|
||||||
argument << this->m_i;
|
argument << TupleConverter<CVector3DBase>::toTuple(*this);
|
||||||
argument << this->m_j;
|
|
||||||
argument << this->m_k;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -173,9 +166,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
template <class ImplVector> void CVector3DBase<ImplVector>::unmarshallFromDbus(const QDBusArgument &argument)
|
template <class ImplVector> void CVector3DBase<ImplVector>::unmarshallFromDbus(const QDBusArgument &argument)
|
||||||
{
|
{
|
||||||
argument >> this->m_i;
|
argument >> TupleConverter<CVector3DBase>::toTuple(*this);
|
||||||
argument >> this->m_j;
|
|
||||||
argument >> this->m_k;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ namespace BlackMisc
|
|||||||
template <class ImplVector> class CVector3DBase : public CValueObject
|
template <class ImplVector> class CVector3DBase : public CValueObject
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
BLACK_ENABLE_TUPLE_CONVERSION(CVector3DBase)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Easy access to derived class (CRTP template parameter)
|
* \brief Easy access to derived class (CRTP template parameter)
|
||||||
* \return
|
* \return
|
||||||
@@ -366,4 +368,6 @@ namespace BlackMisc
|
|||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
BLACK_DECLARE_TUPLE_CONVERSION_TEMPLATE(BlackMisc::Math::CVector3DBase, (o.m_i, o.m_j, o.m_k))
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -44,12 +44,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
const auto &other = static_cast<const CServer &>(otherBase);
|
const auto &other = static_cast<const CServer &>(otherBase);
|
||||||
|
|
||||||
const auto lhs = std::tie(this->m_name, this->m_description, this->m_address, this->m_port);
|
return compare(TupleConverter<CServer>::toTuple(*this), TupleConverter<CServer>::toTuple(other));
|
||||||
const auto rhs = std::tie(other.m_name, other.m_description, other.m_address, other.m_port);
|
|
||||||
|
|
||||||
if (lhs < rhs) { return -1; }
|
|
||||||
if (lhs > rhs) { return 1; }
|
|
||||||
return compare(this->m_user, other.m_user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -57,11 +52,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
void CServer::marshallToDbus(QDBusArgument &argument) const
|
void CServer::marshallToDbus(QDBusArgument &argument) const
|
||||||
{
|
{
|
||||||
argument << this->m_name;
|
argument << TupleConverter<CServer>::toTuple(*this);
|
||||||
argument << this->m_description;
|
|
||||||
argument << this->m_address;
|
|
||||||
argument << this->m_port;
|
|
||||||
argument << this->m_user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -69,11 +60,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
void CServer::unmarshallFromDbus(const QDBusArgument &argument)
|
void CServer::unmarshallFromDbus(const QDBusArgument &argument)
|
||||||
{
|
{
|
||||||
argument >> this->m_name;
|
argument >> TupleConverter<CServer>::toTuple(*this);
|
||||||
argument >> this->m_description;
|
|
||||||
argument >> this->m_address;
|
|
||||||
argument >> this->m_port;
|
|
||||||
argument >> this->m_user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -90,7 +77,7 @@ namespace BlackMisc
|
|||||||
bool CServer::operator ==(const CServer &other) const
|
bool CServer::operator ==(const CServer &other) const
|
||||||
{
|
{
|
||||||
if (this == &other) return true;
|
if (this == &other) return true;
|
||||||
return compare(*this, other) == 0;
|
return TupleConverter<CServer>::toTuple(*this) == TupleConverter<CServer>::toTuple(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -106,12 +93,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
uint CServer::getValueHash() const
|
uint CServer::getValueHash() const
|
||||||
{
|
{
|
||||||
QList<uint> hashs;
|
return qHash(TupleConverter<CServer>::toTuple(*this));
|
||||||
hashs << qHash(this->m_name);
|
|
||||||
hashs << qHash(this->m_address);
|
|
||||||
hashs << qHash(this->m_port);
|
|
||||||
hashs << qHash(this->m_user.getValueHash());
|
|
||||||
return BlackMisc::calculateHash(hashs, "CServer");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ namespace BlackMisc
|
|||||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BLACK_ENABLE_TUPLE_CONVERSION(CServer)
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QString m_description;
|
QString m_description;
|
||||||
QString m_address;
|
QString m_address;
|
||||||
@@ -181,6 +182,7 @@ namespace BlackMisc
|
|||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Network::CServer, (o.m_name, o.m_description, o.m_address, o.m_port, o.m_user))
|
||||||
Q_DECLARE_METATYPE(BlackMisc::Network::CServer)
|
Q_DECLARE_METATYPE(BlackMisc::Network::CServer)
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
@@ -49,12 +49,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
const auto &other = static_cast<const CUser &>(otherBase);
|
const auto &other = static_cast<const CUser &>(otherBase);
|
||||||
|
|
||||||
const auto lhs = std::tie(this->m_id, this->m_realname, this->m_email, this->m_password);
|
return compare(TupleConverter<CUser>::toTuple(*this), TupleConverter<CUser>::toTuple(other));
|
||||||
const auto rhs = std::tie(other.m_id, other.m_realname, other.m_email, other.m_password);
|
|
||||||
|
|
||||||
if (lhs < rhs) { return -1; }
|
|
||||||
if (lhs > rhs) { return 1; }
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -62,11 +57,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
void CUser::marshallToDbus(QDBusArgument &argument) const
|
void CUser::marshallToDbus(QDBusArgument &argument) const
|
||||||
{
|
{
|
||||||
argument << this->m_id;
|
argument << TupleConverter<CUser>::toTuple(*this);
|
||||||
argument << this->m_realname;
|
|
||||||
argument << this->m_email;
|
|
||||||
argument << this->m_password;
|
|
||||||
argument << this->m_callsign;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -74,11 +65,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
void CUser::unmarshallFromDbus(const QDBusArgument &argument)
|
void CUser::unmarshallFromDbus(const QDBusArgument &argument)
|
||||||
{
|
{
|
||||||
argument >> this->m_id;
|
argument >> TupleConverter<CUser>::toTuple(*this);
|
||||||
argument >> this->m_realname;
|
|
||||||
argument >> this->m_email;
|
|
||||||
argument >> this->m_password;
|
|
||||||
argument >> this->m_callsign;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -87,10 +74,7 @@ namespace BlackMisc
|
|||||||
bool CUser::operator ==(const CUser &other) const
|
bool CUser::operator ==(const CUser &other) const
|
||||||
{
|
{
|
||||||
if (this == &other) return true;
|
if (this == &other) return true;
|
||||||
return (this->m_id == other.m_id &&
|
return TupleConverter<CUser>::toTuple(*this) == TupleConverter<CUser>::toTuple(other);
|
||||||
this->m_realname == other.m_realname &&
|
|
||||||
this->m_email == other.m_email &&
|
|
||||||
this->m_callsign == other.m_callsign);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -134,12 +118,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
uint CUser::getValueHash() const
|
uint CUser::getValueHash() const
|
||||||
{
|
{
|
||||||
QList<uint> hashs;
|
return qHash(TupleConverter<CUser>::toTuple(*this));
|
||||||
hashs << qHash(this->m_id);
|
|
||||||
hashs << qHash(this->m_realname);
|
|
||||||
hashs << qHash(this->m_email);
|
|
||||||
hashs << qHash(this->m_callsign.getValueHash());
|
|
||||||
return BlackMisc::calculateHash(hashs, "CUser");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -14,8 +14,10 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace Network
|
namespace Network
|
||||||
{
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Value object encapsulating information of a user.
|
* Value object encapsulating information of a user.
|
||||||
*/
|
*/
|
||||||
@@ -154,14 +156,19 @@ namespace BlackMisc
|
|||||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BLACK_ENABLE_TUPLE_CONVERSION(CUser)
|
||||||
QString m_id;
|
QString m_id;
|
||||||
QString m_realname;
|
QString m_realname;
|
||||||
QString m_email;
|
QString m_email;
|
||||||
QString m_password;
|
QString m_password;
|
||||||
BlackMisc::Aviation::CCallsign m_callsign;
|
BlackMisc::Aviation::CCallsign m_callsign;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Network::CUser, (o.m_id, o.m_realname, o.m_email, o.m_password, o.m_callsign))
|
||||||
Q_DECLARE_METATYPE(BlackMisc::Network::CUser)
|
Q_DECLARE_METATYPE(BlackMisc::Network::CUser)
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user