refs #140 to demonstrate the new tuple framework, adapted five typical value classes to use it

This commit is contained in:
Mathew Sutcliffe
2014-02-12 23:02:43 +00:00
committed by Klaus Basan
parent fcd3dc09ef
commit 7f92b5dbc9
10 changed files with 40 additions and 103 deletions

View File

@@ -45,12 +45,7 @@ namespace BlackMisc
{
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);
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;
return compare(TupleConverter<CAircraftIcao>::toTuple(*this), TupleConverter<CAircraftIcao>::toTuple(other));
}
/*
@@ -58,11 +53,7 @@ namespace BlackMisc
*/
void CAircraftIcao::marshallToDbus(QDBusArgument &argument) const
{
argument << this->m_designator;
argument << this->m_airline;
argument << this->m_livery;
argument << this->m_type;
argument << this->m_color;
argument << TupleConverter<CAircraftIcao>::toTuple(*this);
}
/*
@@ -70,11 +61,7 @@ namespace BlackMisc
*/
void CAircraftIcao::unmarshallFromDbus(const QDBusArgument &argument)
{
argument >> this->m_designator;
argument >> this->m_airline;
argument >> this->m_livery;
argument >> this->m_type;
argument >> this->m_color;
argument >> TupleConverter<CAircraftIcao>::toTuple(*this);
}
/*
@@ -100,7 +87,7 @@ namespace BlackMisc
bool CAircraftIcao::operator ==(const CAircraftIcao &other) const
{
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
{
QList<uint> hashs;
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");
return qHash(TupleConverter<CAircraftIcao>::toTuple(*this));
}
/*

View File

@@ -153,6 +153,7 @@ namespace BlackMisc
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CAircraftIcao)
QString m_designator;
QString m_type;
QString m_airline;
@@ -162,6 +163,7 @@ namespace BlackMisc
} // 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)
#endif // guard

View File

@@ -50,11 +50,7 @@ namespace BlackMisc
{
const auto &other = static_cast<const CCoordinateGeodetic &>(otherBase);
int cmp = compare(this->m_latitude, other.m_latitude);
if (cmp) { return cmp; }
cmp = compare(this->m_longitude, other.m_longitude);
if (cmp) { return cmp; }
return compare(this->m_height, other.m_height);
return compare(TupleConverter<CCoordinateGeodetic>::toTuple(*this), TupleConverter<CCoordinateGeodetic>::toTuple(other));
}
/*
@@ -62,9 +58,7 @@ namespace BlackMisc
*/
void CCoordinateGeodetic::marshallToDbus(QDBusArgument &argument) const
{
argument << this->m_latitude;
argument << this->m_longitude;
argument << this->m_height;
argument << TupleConverter<CCoordinateGeodetic>::toTuple(*this);
}
/*
@@ -72,9 +66,7 @@ namespace BlackMisc
*/
void CCoordinateGeodetic::unmarshallFromDbus(const QDBusArgument &argument)
{
argument >> this->m_latitude;
argument >> this->m_longitude;
argument >> this->m_height;
argument >> TupleConverter<CCoordinateGeodetic>::toTuple(*this);
}
/*
@@ -83,9 +75,7 @@ namespace BlackMisc
bool CCoordinateGeodetic::operator ==(const CCoordinateGeodetic &other) const
{
if (this == &other) return true;
return this->m_height == other.m_height &&
this->m_latitude == other.m_latitude &&
this->m_longitude == other.m_longitude;
return TupleConverter<CCoordinateGeodetic>::toTuple(*this) == TupleConverter<CCoordinateGeodetic>::toTuple(other);
}
/*
@@ -110,11 +100,7 @@ namespace BlackMisc
*/
uint CCoordinateGeodetic::getValueHash() const
{
QList<uint> hashs;
hashs << this->m_latitude.getValueHash();
hashs << this->m_longitude.getValueHash();
hashs << this->m_height.getValueHash();
return BlackMisc::calculateHash(hashs, "CCoordinateGeodetic");
return qHash(TupleConverter<CCoordinateGeodetic>::toTuple(*this));
}
/*

View File

@@ -70,6 +70,7 @@ namespace BlackMisc
class CCoordinateGeodetic : public CValueObject, public ICoordinateGeodetic
{
private:
BLACK_ENABLE_TUPLE_CONVERSION(CCoordinateGeodetic)
BlackMisc::Geo::CLatitude m_latitude; //!< Latitude
BlackMisc::Geo::CLongitude m_longitude; //!< Longitude
BlackMisc::PhysicalQuantities::CLength m_height; //!< height
@@ -236,6 +237,7 @@ namespace BlackMisc
} // namespace
} // namespace
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Geo::CCoordinateGeodetic, (o.m_latitude, o.m_longitude, o.m_height))
Q_DECLARE_METATYPE(BlackMisc::Geo::CCoordinateGeodetic)
#endif // guard

View File

@@ -52,12 +52,7 @@ namespace BlackMisc
{
const auto &other = static_cast<const CVector3DBase &>(otherBase);
const auto lhs = std::tie(this->m_i, this->m_j, this->m_k);
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;
return compare(TupleConverter<CVector3DBase>::toTuple(*this), TupleConverter<CVector3DBase>::toTuple(other));
}
/*
@@ -162,9 +157,7 @@ namespace BlackMisc
*/
template <class ImplVector> void CVector3DBase<ImplVector>::marshallToDbus(QDBusArgument &argument) const
{
argument << this->m_i;
argument << this->m_j;
argument << this->m_k;
argument << TupleConverter<CVector3DBase>::toTuple(*this);
}
/*!
@@ -173,9 +166,7 @@ namespace BlackMisc
*/
template <class ImplVector> void CVector3DBase<ImplVector>::unmarshallFromDbus(const QDBusArgument &argument)
{
argument >> this->m_i;
argument >> this->m_j;
argument >> this->m_k;
argument >> TupleConverter<CVector3DBase>::toTuple(*this);
}
/*!

View File

@@ -23,6 +23,8 @@ namespace BlackMisc
template <class ImplVector> class CVector3DBase : public CValueObject
{
private:
BLACK_ENABLE_TUPLE_CONVERSION(CVector3DBase)
/*!
* \brief Easy access to derived class (CRTP template parameter)
* \return
@@ -366,4 +368,6 @@ namespace BlackMisc
} // namespace
} // namespace
BLACK_DECLARE_TUPLE_CONVERSION_TEMPLATE(BlackMisc::Math::CVector3DBase, (o.m_i, o.m_j, o.m_k))
#endif // guard

View File

@@ -44,12 +44,7 @@ namespace BlackMisc
{
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);
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);
return compare(TupleConverter<CServer>::toTuple(*this), TupleConverter<CServer>::toTuple(other));
}
/*
@@ -57,11 +52,7 @@ namespace BlackMisc
*/
void CServer::marshallToDbus(QDBusArgument &argument) const
{
argument << this->m_name;
argument << this->m_description;
argument << this->m_address;
argument << this->m_port;
argument << this->m_user;
argument << TupleConverter<CServer>::toTuple(*this);
}
/*
@@ -69,11 +60,7 @@ namespace BlackMisc
*/
void CServer::unmarshallFromDbus(const QDBusArgument &argument)
{
argument >> this->m_name;
argument >> this->m_description;
argument >> this->m_address;
argument >> this->m_port;
argument >> this->m_user;
argument >> TupleConverter<CServer>::toTuple(*this);
}
/*
@@ -90,7 +77,7 @@ namespace BlackMisc
bool CServer::operator ==(const CServer &other) const
{
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
{
QList<uint> hashs;
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");
return qHash(TupleConverter<CServer>::toTuple(*this));
}
/*

View File

@@ -172,6 +172,7 @@ namespace BlackMisc
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CServer)
QString m_name;
QString m_description;
QString m_address;
@@ -181,6 +182,7 @@ namespace BlackMisc
} // 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)
#endif // guard

View File

@@ -49,12 +49,7 @@ namespace BlackMisc
{
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);
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;
return compare(TupleConverter<CUser>::toTuple(*this), TupleConverter<CUser>::toTuple(other));
}
/*
@@ -62,11 +57,7 @@ namespace BlackMisc
*/
void CUser::marshallToDbus(QDBusArgument &argument) const
{
argument << this->m_id;
argument << this->m_realname;
argument << this->m_email;
argument << this->m_password;
argument << this->m_callsign;
argument << TupleConverter<CUser>::toTuple(*this);
}
/*
@@ -74,11 +65,7 @@ namespace BlackMisc
*/
void CUser::unmarshallFromDbus(const QDBusArgument &argument)
{
argument >> this->m_id;
argument >> this->m_realname;
argument >> this->m_email;
argument >> this->m_password;
argument >> this->m_callsign;
argument >> TupleConverter<CUser>::toTuple(*this);
}
/*
@@ -87,10 +74,7 @@ namespace BlackMisc
bool CUser::operator ==(const CUser &other) const
{
if (this == &other) return true;
return (this->m_id == other.m_id &&
this->m_realname == other.m_realname &&
this->m_email == other.m_email &&
this->m_callsign == other.m_callsign);
return TupleConverter<CUser>::toTuple(*this) == TupleConverter<CUser>::toTuple(other);
}
/*
@@ -134,12 +118,7 @@ namespace BlackMisc
*/
uint CUser::getValueHash() const
{
QList<uint> hashs;
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");
return qHash(TupleConverter<CUser>::toTuple(*this));
}
/*

View File

@@ -14,8 +14,10 @@
namespace BlackMisc
{
namespace Network
{
/*!
* Value object encapsulating information of a user.
*/
@@ -154,14 +156,19 @@ namespace BlackMisc
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CUser)
QString m_id;
QString m_realname;
QString m_email;
QString m_password;
BlackMisc::Aviation::CCallsign m_callsign;
};
} // 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)
#endif // guard