refs #74, refs#140 renamed CSimulator to CSimulatorInfo and tupelized class

CSimulatorInfo discussed https://dev.vatsim-germany.org/issues/74#note-6
This commit is contained in:
Klaus Basan
2014-03-11 01:19:57 +01:00
parent 94d80f6d20
commit 4db12d888e
3 changed files with 87 additions and 80 deletions

View File

@@ -1,61 +0,0 @@
#include "simulator.h"
#include "blackmisc/blackmiscfreefunctions.h"
namespace BlackSim
{
CSimulator::CSimulator(const QString &shortname, const QString &fullname) : m_fullname(fullname), m_shortname(shortname)
{ }
CSimulator::CSimulator() : m_fullname("Unknown"), m_shortname("Unknown")
{}
uint CSimulator::getValueHash() const
{
QList<uint> hashs;
hashs << qHash(this->m_fullname);
hashs << qHash(this->m_shortname);
return BlackMisc::calculateHash(hashs, "CSimulator");
}
QString CSimulator::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
return QString(this->m_shortname).append(" (").append(this->m_fullname).append(")");
}
int CSimulator::getMetaTypeId() const
{
return qMetaTypeId<CSimulator>();
}
int CSimulator::compareImpl(const BlackMisc::CValueObject &other) const
{
const CSimulator &otherObj = static_cast<const CSimulator &>(other);
int result;
if ((result = this->m_shortname.compare(otherObj.m_shortname, Qt::CaseInsensitive))) return result;
return this->m_shortname.compare(otherObj.m_shortname, Qt::CaseInsensitive);
}
void CSimulator::marshallToDbus(QDBusArgument &argument) const
{
argument << this->m_fullname;
argument << this->m_shortname;
}
void CSimulator::unmarshallFromDbus(const QDBusArgument &argument)
{
argument >> this->m_fullname;
argument >> this->m_shortname;
}
/*
* Register metadata
*/
void CSimulator::registerMetadata()
{
qRegisterMetaType<CSimulator>();
qDBusRegisterMetaType<CSimulator>();
}
}

View File

@@ -0,0 +1,63 @@
#include "simulatorinfo.h"
#include "blackmisc/blackmiscfreefunctions.h"
using namespace BlackMisc;
namespace BlackSim
{
CSimulatorInfo::CSimulatorInfo(const QString &shortname, const QString &fullname) : m_fullname(fullname), m_shortname(shortname)
{ }
CSimulatorInfo::CSimulatorInfo() : m_fullname("Unknown"), m_shortname("Unknown")
{}
uint CSimulatorInfo::getValueHash() const
{
return qHash(TupleConverter<CSimulatorInfo>::toTuple(*this));
}
QString CSimulatorInfo::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
return QString(this->m_shortname).append(" (").append(this->m_fullname).append(")");
}
int CSimulatorInfo::getMetaTypeId() const
{
return qMetaTypeId<CSimulatorInfo>();
}
bool CSimulatorInfo::operator ==(const CSimulatorInfo &other) const
{
if (this == &other) return true;
return TupleConverter<CSimulatorInfo>::toTuple(*this) == TupleConverter<CSimulatorInfo>::toTuple(other);
}
bool CSimulatorInfo::operator !=(const CSimulatorInfo &other) const
{
return !((*this) == other);
}
int CSimulatorInfo::compareImpl(const BlackMisc::CValueObject &otherBase) const
{
const auto &other = static_cast<const CSimulatorInfo &>(otherBase);
return compare(TupleConverter<CSimulatorInfo>::toTuple(*this), TupleConverter<CSimulatorInfo>::toTuple(other));
}
void CSimulatorInfo::marshallToDbus(QDBusArgument &argument) const
{
argument << TupleConverter<CSimulatorInfo>::toTuple(*this);
}
void CSimulatorInfo::unmarshallFromDbus(const QDBusArgument &argument)
{
argument >> TupleConverter<CSimulatorInfo>::toTuple(*this);
}
void CSimulatorInfo::registerMetadata()
{
qRegisterMetaType<CSimulatorInfo>();
qDBusRegisterMetaType<CSimulatorInfo>();
}
}

View File

@@ -1,22 +1,20 @@
#ifndef BLACKSIM_SIMULATOR_H
#define BLACKSIM_SIMULATOR_H
#ifndef BLACKSIM_SIMULATORINFO_H
#define BLACKSIM_SIMULATORINFO_H
#include "blackmisc/valueobject.h"
namespace BlackSim
{
/*!
* \brief Describing a simulator
*/
class CSimulator : public BlackMisc::CValueObject
//! \brief Describing a simulator
class CSimulatorInfo : public BlackMisc::CValueObject
{
public:
//! \brief Default constructor
CSimulator();
CSimulatorInfo();
//! \brief Constructor
CSimulator(const QString &shortname, const QString &fullname);
CSimulatorInfo(const QString &shortname, const QString &fullname);
//! \brief Unspecified simulator
bool isUnspecified() const { return this->m_shortname.isEmpty() || this->m_shortname.startsWith("Unspecified", Qt::CaseInsensitive); }
@@ -27,35 +25,40 @@ namespace BlackSim
return QVariant::fromValue(*this);
}
//! \brief Equal operator ==
bool operator ==(const CSimulatorInfo &other) const;
//! \brief Unequal operator !=
bool operator !=(const CSimulatorInfo &other) const;
//! \copydoc CValueObject::getValueHash()
virtual uint getValueHash() const override;
//! \brief Simulator is FS9 - Microsoft Flight Simulator 2004
static const CSimulator &FS9()
static const CSimulatorInfo &FS9()
{
static CSimulator sim("FS9", "Microsoft Flight Simulator 2004");
static CSimulatorInfo sim("FS9", "Microsoft Flight Simulator 2004");
return sim;
}
//! \brief Simulator is FSX Microsoft Flight Simulator X (2006)
static const CSimulator &FSX()
static const CSimulatorInfo &FSX()
{
static CSimulator sim("FSX", "Microsoft Flight Simulator X (2006)");
static CSimulatorInfo sim("FSX", "Microsoft Flight Simulator X (2006)");
return sim;
}
//! \brief Simulator is XPlane 10
static const CSimulator &XP10()
static const CSimulatorInfo &XP10()
{
static CSimulator sim("XP10", "XPlane 10 (2011)");
static CSimulatorInfo sim("XP10", "XPlane 10 (2011)");
return sim;
}
//! \brief Simulator is unspecified
static const CSimulator &UnspecifiedSim()
static const CSimulatorInfo &UnspecifiedSim()
{
static CSimulator sim("Unspecified", "Unspecified");
static CSimulatorInfo sim("Unspecified", "Unspecified");
return sim;
}
@@ -70,7 +73,7 @@ namespace BlackSim
virtual int getMetaTypeId() const override;
//! \copydoc CValueObject::compareImpl
virtual int compareImpl(const CValueObject &other) const override;
virtual int compareImpl(const CValueObject &otherBase) const override;
//! \copydoc CValueObject::marshallToDbus()
virtual void marshallToDbus(QDBusArgument &argument) const override;
@@ -79,11 +82,13 @@ namespace BlackSim
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CSimulatorInfo)
QString m_fullname;
QString m_shortname;
};
}
Q_DECLARE_METATYPE(BlackSim::CSimulator)
BLACK_DECLARE_TUPLE_CONVERSION(BlackSim::CSimulatorInfo, (o.m_fullname, o.m_shortname))
Q_DECLARE_METATYPE(BlackSim::CSimulatorInfo)
#endif // guard