Files
pilotclient/src/blackmisc/aviobase.h
Mathew Sutcliffe db4c05dd9f refs #84 removed the CValueObject::compare method and added a friend function BlackMisc::compare to replace it.
The new compare is implemented using "multimethods" described in the book Advanced C++ Programming Styles and Idioms by James Coplien.

First, the isA method is used to determine which of the values being compared is the most general. (For example, CLength is more general than CAltitude.)
Then the compareImpl method is called on the most general value, with the other value as an argument.
If there is not a direct inheritance relation between the two values (or they are the same class) then the comparison is invalid and a assert is triggered.
2014-01-17 01:38:27 +00:00

119 lines
3.0 KiB
C++

/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BLACKMISC_AVIOBASE_H
#define BLACKMISC_AVIOBASE_H
// QtGlobal is required for asserts
#include "blackmisc/valueobject.h"
#include "blackmisc/pqconstants.h"
#include <QtGlobal>
namespace BlackMisc
{
namespace Aviation
{
/*!
* \brief Base class for avionics
*/
class CAvionicsBase : public BlackMisc::CValueObject
{
protected:
QString m_name; //!< name of the unit
/*!
* \brief Constructor
*/
CAvionicsBase(const QString &name) : m_name(name) {}
/*!
* \brief Are the set values valid / in range
* \return
*/
virtual bool validValues()
{
return true;
}
/*!
* \brief Set name
* \param name
*/
void setName(const QString &name)
{
this->m_name = name;
}
/*!
* \brief operator ==
* \param other
* \return
*/
bool operator ==(const CAvionicsBase &other) const
{
if (this == &other) return true;
return this->m_name == other.m_name;
}
/*!
* \copydoc CValueObject::getMetaTypeId
*/
virtual int getMetaTypeId() const { return 0; }
/*!
* \copydoc CValueObject::isA
*/
virtual bool isA(int metaTypeId) const { return this->CValueObject::isA(metaTypeId); }
/*!
* \copydoc CValueObject::compareImpl
*/
virtual int compareImpl(const CValueObject &other) const
{
Q_UNUSED(other);
qFatal("not implemented");
return 0;
}
/*!
* \brief Stream to DBus <<
* \param argument
*/
virtual void marshallToDbus(QDBusArgument &argument) const
{
argument << this->m_name;
}
/*!
* \brief Stream from DBus >>
* \param argument
*/
virtual void unmarshallFromDbus(const QDBusArgument &argument)
{
argument >> this->m_name;
}
public:
/*!
* \brief Virtual destructor
*/
virtual ~CAvionicsBase() {}
/*!
* \brief Name
* \return
*/
QString getName() const
{
return this->m_name;
}
};
} // namespace
} // namespace
#endif // guard