mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 21:45:34 +08:00
Move Math constants into class (to be consistent with other constants), tested against minGW / gcc 4.7.2 and fixed various issues (mainly initializer lists, unused variables). BlackMisc compiles now in MinGW, but still issues (especially with qDebug() friend methods)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
/* 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/. */
|
||||
|
||||
@@ -24,6 +24,8 @@ private:
|
||||
protected:
|
||||
int m_digits; //!< digits used
|
||||
|
||||
protected:
|
||||
|
||||
/*!
|
||||
* \brief Default constructor
|
||||
*/
|
||||
@@ -33,9 +35,8 @@ protected:
|
||||
* \brief Copy constructor
|
||||
* \param otherUnit
|
||||
*/
|
||||
CModulator(const CModulator &otherUnit) :
|
||||
m_frequencyActive(otherUnit.m_frequencyActive), m_frequencyStandby(otherUnit.m_frequencyStandby),
|
||||
m_digits(otherUnit.m_digits), CAvionicsBase(otherUnit.getName()) {}
|
||||
CModulator(const CModulator &otherUnit) : CAvionicsBase(otherUnit.getName()),
|
||||
m_frequencyActive(otherUnit.m_frequencyActive), m_frequencyStandby(otherUnit.m_frequencyStandby), m_digits(otherUnit.m_digits) {}
|
||||
|
||||
/*!
|
||||
* \brief Constructor
|
||||
@@ -45,8 +46,7 @@ protected:
|
||||
* \param digits
|
||||
*/
|
||||
CModulator(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits) :
|
||||
m_frequencyActive(activeFrequency),
|
||||
m_digits(digits), m_frequencyStandby(standbyFrequency), CAvionicsBase(name) { }
|
||||
CAvionicsBase(name), m_frequencyActive(activeFrequency), m_frequencyStandby(standbyFrequency), m_digits(digits) { }
|
||||
|
||||
/*!
|
||||
* \brief String for converter
|
||||
@@ -200,8 +200,6 @@ protected:
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief Virtual destructor
|
||||
|
||||
@@ -23,7 +23,8 @@ private:
|
||||
* \param f
|
||||
* \return
|
||||
*/
|
||||
bool isValidCivilNavigationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const {
|
||||
bool isValidCivilNavigationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const
|
||||
{
|
||||
double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits);
|
||||
return fr >= 108.0 && fr <= 117.95;
|
||||
}
|
||||
@@ -32,8 +33,10 @@ private:
|
||||
* \param f
|
||||
* \return
|
||||
*/
|
||||
bool isValidMilitaryNavigationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const {
|
||||
return false;
|
||||
bool isValidMilitaryNavigationFrequency(BlackMisc::PhysicalQuantities::CFrequency f) const
|
||||
{
|
||||
double fr = f.valueRounded(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz(), this->m_digits);
|
||||
return fr >= 960.0 && fr <= 1215.0; // valid TACAN frequency
|
||||
}
|
||||
/*!
|
||||
* \brief Constructor
|
||||
@@ -45,7 +48,8 @@ private:
|
||||
*
|
||||
*/
|
||||
CNavSystem(bool validate, const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits = 3):
|
||||
CModulator(name, activeFrequency, standbyFrequency, digits) {
|
||||
CModulator(name, activeFrequency, standbyFrequency, digits)
|
||||
{
|
||||
this->validate(validate);
|
||||
}
|
||||
|
||||
@@ -54,7 +58,8 @@ protected:
|
||||
* \brief Are the set values valid / in range?
|
||||
* \return
|
||||
*/
|
||||
bool validValues() const {
|
||||
bool validValues() const
|
||||
{
|
||||
if (this->isDefaultValue()) return true; // special case
|
||||
bool v =
|
||||
(this->isValidCivilNavigationFrequency(this->getFrequencyActive()) ||
|
||||
@@ -70,7 +75,8 @@ protected:
|
||||
* \remarks Cannot be virtualsince already used in constructor
|
||||
* \return
|
||||
*/
|
||||
bool validate(bool strict = true) const {
|
||||
bool validate(bool strict = true) const
|
||||
{
|
||||
if (this->isDefaultValue()) return true;
|
||||
bool valid = this->validValues();
|
||||
if (!strict) return valid;
|
||||
@@ -96,14 +102,16 @@ public:
|
||||
* \param digits
|
||||
*/
|
||||
CNavSystem(const QString &name, const BlackMisc::PhysicalQuantities::CFrequency &activeFrequency, const BlackMisc::PhysicalQuantities::CFrequency &standbyFrequency, int digits = 3):
|
||||
CModulator(name, activeFrequency, standbyFrequency, digits) {
|
||||
CModulator(name, activeFrequency, standbyFrequency, digits)
|
||||
{
|
||||
this->validate(true);
|
||||
}
|
||||
/*!
|
||||
* \brief Set active frequency
|
||||
* \param frequencyMHz
|
||||
*/
|
||||
void setFrequencyActiveMHz(double frequencyMHz) {
|
||||
void setFrequencyActiveMHz(double frequencyMHz)
|
||||
{
|
||||
CModulator::setFrequencyActiveMHz(frequencyMHz);
|
||||
this->validate(true);
|
||||
}
|
||||
@@ -111,7 +119,8 @@ public:
|
||||
* \brief Set standby frequency
|
||||
* \param frequencyMHz
|
||||
*/
|
||||
void setFrequencyStandbyMHz(double frequencyMHz) {
|
||||
void setFrequencyStandbyMHz(double frequencyMHz)
|
||||
{
|
||||
CModulator::setFrequencyStandbyMHz(frequencyMHz);
|
||||
this->validate(true);
|
||||
}
|
||||
@@ -120,7 +129,8 @@ public:
|
||||
* \param otherSystem
|
||||
* \return
|
||||
*/
|
||||
CNavSystem &operator =(const CNavSystem &otherSystem) {
|
||||
CNavSystem &operator =(const CNavSystem &otherSystem)
|
||||
{
|
||||
CModulator::operator =(otherSystem);
|
||||
return (*this);
|
||||
}
|
||||
@@ -129,7 +139,8 @@ public:
|
||||
* \param otherSystem
|
||||
* \return
|
||||
*/
|
||||
bool operator ==(const CNavSystem &otherSystem) const {
|
||||
bool operator ==(const CNavSystem &otherSystem) const
|
||||
{
|
||||
return CModulator::operator ==(otherSystem);
|
||||
}
|
||||
/*!
|
||||
@@ -137,7 +148,8 @@ public:
|
||||
* \param otherSystem
|
||||
* \return
|
||||
*/
|
||||
bool operator !=(const CNavSystem &otherSystem) const {
|
||||
bool operator !=(const CNavSystem &otherSystem) const
|
||||
{
|
||||
return CModulator::operator !=(otherSystem);
|
||||
}
|
||||
|
||||
@@ -150,7 +162,8 @@ public:
|
||||
* \param standbyFrequencyMHz
|
||||
* \return
|
||||
*/
|
||||
static bool tryGetNavSystem(CNavSystem &navSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1) {
|
||||
static bool tryGetNavSystem(CNavSystem &navSystem, const QString &name, double activeFrequencyMHz, double standbyFrequencyMHz = -1)
|
||||
{
|
||||
navSystem = CNavSystem(false, name, BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()));
|
||||
bool s;
|
||||
if (!(s = navSystem.validate(false))) navSystem = CNavSystem(); // reset to default
|
||||
@@ -165,7 +178,8 @@ public:
|
||||
* \param standbyFrequency
|
||||
* \return
|
||||
*/
|
||||
static bool tryGetNavSystem(CNavSystem &navSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) {
|
||||
static bool tryGetNavSystem(CNavSystem &navSystem, const QString &name, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
|
||||
{
|
||||
navSystem = CNavSystem(false, name, activeFrequency, standbyFrequency);
|
||||
bool s;
|
||||
if (!(s = navSystem.validate(false))) navSystem = CNavSystem(); // reset to default
|
||||
@@ -177,7 +191,8 @@ public:
|
||||
* \param standbyFrequencyMHz
|
||||
* \return
|
||||
*/
|
||||
static CNavSystem getNav1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) {
|
||||
static CNavSystem getNav1System(double activeFrequencyMHz, double standbyFrequencyMHz = -1)
|
||||
{
|
||||
return CNavSystem(CModulator::NameNav1(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()));
|
||||
}
|
||||
/*!
|
||||
@@ -186,7 +201,8 @@ public:
|
||||
* \param standbyFrequency
|
||||
* \return
|
||||
*/
|
||||
static CNavSystem getNav1System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) {
|
||||
static CNavSystem getNav1System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
|
||||
{
|
||||
return CNavSystem(CModulator::NameNav1(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency);
|
||||
}
|
||||
/*!
|
||||
@@ -196,7 +212,8 @@ public:
|
||||
* \param standbyFrequencyMHz
|
||||
* \return
|
||||
*/
|
||||
static bool tryGetNav1System(CNavSystem &navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) {
|
||||
static bool tryGetNav1System(CNavSystem &navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1)
|
||||
{
|
||||
return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav1(), activeFrequencyMHz, standbyFrequencyMHz);
|
||||
}
|
||||
/*!
|
||||
@@ -206,7 +223,8 @@ public:
|
||||
* \param standbyFrequency
|
||||
* \return
|
||||
*/
|
||||
static bool tryGetNav1System(CNavSystem &navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) {
|
||||
static bool tryGetNav1System(CNavSystem &navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
|
||||
{
|
||||
return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav1(), activeFrequency, standbyFrequency);
|
||||
}
|
||||
/*!
|
||||
@@ -215,7 +233,8 @@ public:
|
||||
* \param standbyFrequencyMHz
|
||||
* \return
|
||||
*/
|
||||
static CNavSystem getNav2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1) {
|
||||
static CNavSystem getNav2System(double activeFrequencyMHz, double standbyFrequencyMHz = -1)
|
||||
{
|
||||
return CNavSystem(CModulator::NameNav2(), BlackMisc::PhysicalQuantities::CFrequency(activeFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()), BlackMisc::PhysicalQuantities::CFrequency(standbyFrequencyMHz < 0 ? activeFrequencyMHz : standbyFrequencyMHz, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()));
|
||||
}
|
||||
/*!
|
||||
@@ -224,7 +243,8 @@ public:
|
||||
* \param standbyFrequency
|
||||
* \return
|
||||
*/
|
||||
static CNavSystem getNav2System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) {
|
||||
static CNavSystem getNav2System(BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
|
||||
{
|
||||
return CNavSystem(CModulator::NameNav2(), activeFrequency, standbyFrequency == CModulator::FrequencyNotSet() ? activeFrequency : standbyFrequency);
|
||||
}
|
||||
/*!
|
||||
@@ -234,7 +254,8 @@ public:
|
||||
* \param standbyFrequencyMHz
|
||||
* \return
|
||||
*/
|
||||
static bool tryGetNav2System(CNavSystem &navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1) {
|
||||
static bool tryGetNav2System(CNavSystem &navSystem, double activeFrequencyMHz, double standbyFrequencyMHz = -1)
|
||||
{
|
||||
return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav2(), activeFrequencyMHz, standbyFrequencyMHz);
|
||||
}
|
||||
/*!
|
||||
@@ -244,7 +265,8 @@ public:
|
||||
* \param standbyFrequency
|
||||
* \return
|
||||
*/
|
||||
static bool tryGetNav2System(CNavSystem &navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet()) {
|
||||
static bool tryGetNav2System(CNavSystem &navSystem, BlackMisc::PhysicalQuantities::CFrequency activeFrequency, BlackMisc::PhysicalQuantities::CFrequency standbyFrequency = CModulator::FrequencyNotSet())
|
||||
{
|
||||
return CNavSystem::tryGetNavSystem(navSystem, CModulator::NameNav2(), activeFrequency, standbyFrequency);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
* \param transponderMode
|
||||
*/
|
||||
CTransponder(bool validate, const QString &name, qint32 transponderCode, TransponderMode transponderMode) :
|
||||
m_transponderCode(transponderCode), m_transponderMode(transponderMode), CAvionicsBase(name)
|
||||
CAvionicsBase(name), m_transponderCode(transponderCode), m_transponderMode(transponderMode)
|
||||
{
|
||||
this->validate(validate);
|
||||
}
|
||||
@@ -56,7 +56,7 @@ private:
|
||||
* \param transponderMode
|
||||
*/
|
||||
CTransponder(bool validate, const QString &name, const QString transponderCode, TransponderMode transponderMode) :
|
||||
m_transponderCode(0), m_transponderMode(transponderMode), CAvionicsBase(name)
|
||||
CAvionicsBase(name), m_transponderCode(0), m_transponderMode(transponderMode)
|
||||
{
|
||||
bool ok = false;
|
||||
this->m_transponderCode = transponderCode.toUInt(&ok);
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace Aviation
|
||||
*/
|
||||
CAviationVerticalPositions::CAviationVerticalPositions() :
|
||||
m_altitude(CAltitude(0, true, CLengthUnit::ft())),
|
||||
m_height(CPhysicalQuantitiesConstants::Length0ft()),
|
||||
m_elevation(CPhysicalQuantitiesConstants::Length0ft())
|
||||
m_elevation(CPhysicalQuantitiesConstants::Length0ft()),
|
||||
m_height(CPhysicalQuantitiesConstants::Length0ft())
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class CAviationVerticalPositions
|
||||
friend CLogMessage operator<<(CLogMessage log, const CAviationVerticalPositions &positions);
|
||||
|
||||
private:
|
||||
BlackMisc::PhysicalQuantities::CLength m_height; //!< height
|
||||
BlackMisc::PhysicalQuantities::CLength m_elevation; //!< elevation
|
||||
CAltitude m_altitude; //!< altitude
|
||||
BlackMisc::PhysicalQuantities::CLength m_elevation; //!< elevation
|
||||
BlackMisc::PhysicalQuantities::CLength m_height; //!< height
|
||||
|
||||
protected:
|
||||
/*!
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace BlackMisc
|
||||
*/
|
||||
template <class UsingClass> class CBaseStreamStringifier
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Stream << overload to be used in debugging messages
|
||||
* \param debug
|
||||
@@ -28,6 +27,17 @@ template <class UsingClass> class CBaseStreamStringifier
|
||||
return debug;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Operator << when there is no debug stream
|
||||
* \param nodebug
|
||||
* \param uc
|
||||
* \return
|
||||
*/
|
||||
friend QNoDebug &operator<<(QNoDebug &nodebug, const UsingClass &uc)
|
||||
{
|
||||
return nodebug;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stream operator << for QDataStream
|
||||
* \param stream
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace BlackMisc
|
||||
{
|
||||
|
||||
CComClient::CComClient(IContext &context, QObject *parent)
|
||||
: m_context(context), IComHandler(context, parent), m_tcp_socket(NULL), m_port(0)
|
||||
: IComHandler(context, parent), m_context(context), m_tcp_socket(NULL), m_port(0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -15,24 +15,24 @@ class QTcpSocket;
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
class IContext;
|
||||
class IContext;
|
||||
|
||||
class CComClient : public IComHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
/*!
|
||||
\param parent Pointer to the parent QObject
|
||||
*/
|
||||
|
||||
//! Constructor
|
||||
/*!
|
||||
\param parent Pointer to the parent QObject
|
||||
*/
|
||||
CComClient(IContext &context, QObject *parent = 0);
|
||||
|
||||
//! Destructor
|
||||
//! Destructor
|
||||
~CComClient();
|
||||
|
||||
//! This method initializes the client
|
||||
//! This method initializes the client
|
||||
virtual bool init();
|
||||
|
||||
//! Connects to the host address.
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
\param port Port number of the remote host.
|
||||
\return Returns true if connecting was successfull, otherwise false.
|
||||
*/
|
||||
void connectTo (const QString& hostName, quint16 port);
|
||||
void connectTo(const QString &hostName, quint16 port);
|
||||
|
||||
//! Returns the connection status
|
||||
/*!
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
\param data Reference to the raw byte data to be sent.
|
||||
\return Returns true if sending was successfull, otherwise false.
|
||||
*/
|
||||
bool sendMessage (const QString &messageID, const QByteArray &message);
|
||||
bool sendMessage(const QString &messageID, const QByteArray &message);
|
||||
|
||||
//! Returns a human readable description of the last error that occurred.
|
||||
QString getErrorMessage(QAbstractSocket::SocketError error);
|
||||
@@ -74,46 +74,46 @@ signals:
|
||||
void doDisconnected();
|
||||
|
||||
//! emitted when an error has occured
|
||||
void doError(QAbstractSocket::SocketError error, const QString& error_message);
|
||||
void doError(QAbstractSocket::SocketError error, const QString &error_message);
|
||||
|
||||
protected slots:
|
||||
|
||||
//! Call this slot, when connected succesfully
|
||||
void onConnected();
|
||||
|
||||
//! Call this slot, when disconnected succesfully
|
||||
|
||||
//! Call this slot, when disconnected succesfully
|
||||
void onDisconnected();
|
||||
|
||||
//! Call this slot, when an error appeared
|
||||
|
||||
//! Call this slot, when an error appeared
|
||||
void onError(QAbstractSocket::SocketError error);
|
||||
|
||||
//! Call this slot, when data has been received
|
||||
|
||||
//! Call this slot, when data has been received
|
||||
void onReceivingData();
|
||||
|
||||
private:
|
||||
IContext& m_context;
|
||||
IContext &m_context;
|
||||
|
||||
protected:
|
||||
|
||||
//! TCP Socket
|
||||
/*!
|
||||
Pointer to the tcp socket.
|
||||
*/
|
||||
QTcpSocket* m_tcp_socket;
|
||||
|
||||
//! Remote hostname
|
||||
//! TCP Socket
|
||||
/*!
|
||||
Pointer to the tcp socket.
|
||||
*/
|
||||
QTcpSocket *m_tcp_socket;
|
||||
|
||||
//! Remote hostname
|
||||
QString m_hostName;
|
||||
|
||||
//! Remote host port
|
||||
//! Remote host port
|
||||
quint16 m_port;
|
||||
|
||||
//! This variable holds the last appeared error
|
||||
//! This variable holds the last appeared error
|
||||
QString m_last_error;
|
||||
|
||||
private:
|
||||
|
||||
CComClient( const CComClient& other);
|
||||
const CComClient& operator = ( const CComClient& other);
|
||||
CComClient(const CComClient &other);
|
||||
const CComClient &operator = (const CComClient &other);
|
||||
};
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
@@ -11,49 +11,49 @@
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
CComClientBuffer::CComClientBuffer(IContext &context, uint clientID, QTcpSocket *socket, QObject *parent)
|
||||
: m_context(context), m_client_id(clientID), m_tcp_socket(socket), IComHandler(context, parent)
|
||||
CComClientBuffer::CComClientBuffer(IContext &context, uint clientID, QTcpSocket *socket, QObject *parent)
|
||||
: IComHandler(context, parent), m_context(context), m_tcp_socket(socket), m_client_id(clientID)
|
||||
{
|
||||
connect(m_tcp_socket, SIGNAL(readyRead()), this, SLOT(onReceivingData()));
|
||||
connect(m_tcp_socket, SIGNAL(disconnected()), this, SLOT(onClientDisconnected()));
|
||||
}
|
||||
CComClientBuffer::~CComClientBuffer()
|
||||
{
|
||||
m_tcp_socket->deleteLater();
|
||||
}
|
||||
|
||||
bool CComClientBuffer::sendMessage(const QString &id, const QByteArray &message)
|
||||
{
|
||||
createFrame(id, message);
|
||||
|
||||
qint64 sender_buffer_size = m_sender_buffer.size();
|
||||
|
||||
qint64 bytes = m_tcp_socket->write(m_sender_buffer);
|
||||
if (bytes < 0 || bytes != sender_buffer_size)
|
||||
{
|
||||
connect(m_tcp_socket, SIGNAL(readyRead()), this, SLOT(onReceivingData()));
|
||||
connect(m_tcp_socket, SIGNAL(disconnected()), this, SLOT(onClientDisconnected()));
|
||||
}
|
||||
CComClientBuffer::~CComClientBuffer()
|
||||
{
|
||||
m_tcp_socket->deleteLater();
|
||||
bWarning(m_context) << "Error writing to socket!";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CComClientBuffer::sendMessage(const QString& id, const QByteArray &message)
|
||||
return true;
|
||||
}
|
||||
|
||||
void CComClientBuffer::onReceivingData()
|
||||
{
|
||||
QByteArray message;
|
||||
QString messageID;
|
||||
|
||||
m_receive_buffer.append(m_tcp_socket->readAll());
|
||||
while (parseFrame(messageID, message))
|
||||
{
|
||||
createFrame(id, message);
|
||||
|
||||
qint64 sender_buffer_size = m_sender_buffer.size();
|
||||
|
||||
qint64 bytes = m_tcp_socket->write(m_sender_buffer);
|
||||
if (bytes < 0 || bytes != sender_buffer_size)
|
||||
{
|
||||
bWarning(m_context) << "Error writing to socket!";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
emit doReceivedMessage(m_client_id, messageID, message);
|
||||
}
|
||||
}
|
||||
|
||||
void CComClientBuffer::onReceivingData()
|
||||
{
|
||||
QByteArray message;
|
||||
QString messageID;
|
||||
|
||||
m_receive_buffer.append(m_tcp_socket->readAll());
|
||||
while (parseFrame(messageID, message))
|
||||
{
|
||||
emit doReceivedMessage(m_client_id, messageID, message);
|
||||
}
|
||||
}
|
||||
|
||||
void CComClientBuffer::onClientDisconnected()
|
||||
{
|
||||
bInfo(m_context) << "Client disconnected!";
|
||||
emit doDisconnected(m_client_id);
|
||||
}
|
||||
void CComClientBuffer::onClientDisconnected()
|
||||
{
|
||||
bInfo(m_context) << "Client disconnected!";
|
||||
emit doDisconnected(m_client_id);
|
||||
}
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
@@ -14,41 +14,38 @@ class QTcpSocket;
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
class IContext;
|
||||
class IContext;
|
||||
|
||||
class CComClientBuffer : public IComHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
class CComClientBuffer : public IComHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CComClientBuffer(IContext &context, uint clientID, QTcpSocket *socket, QObject *parent = 0);
|
||||
public:
|
||||
CComClientBuffer(IContext &context, uint clientID, QTcpSocket *socket, QObject *parent = 0);
|
||||
|
||||
virtual ~CComClientBuffer();
|
||||
virtual ~CComClientBuffer();
|
||||
|
||||
//! Sends a message to the remote host.
|
||||
/*!
|
||||
\param data Reference to the raw byte data to be sent.
|
||||
\return Returns true if sending was successfull, otherwise false.
|
||||
*/
|
||||
bool sendMessage (const QString &id, const QByteArray &message);
|
||||
//! Sends a message to the remote host.
|
||||
/*!
|
||||
\param data Reference to the raw byte data to be sent.
|
||||
\return Returns true if sending was successfull, otherwise false.
|
||||
*/
|
||||
bool sendMessage(const QString &id, const QByteArray &message);
|
||||
|
||||
signals:
|
||||
signals:
|
||||
|
||||
void doReceivedMessage(uint clientID, QString& messageID, QByteArray &message);
|
||||
void doDisconnected(uint clientID);
|
||||
void doReceivedMessage(uint clientID, QString &messageID, QByteArray &message);
|
||||
void doDisconnected(uint clientID);
|
||||
|
||||
protected slots:
|
||||
protected slots:
|
||||
void onReceivingData();
|
||||
void onClientDisconnected();
|
||||
|
||||
void onReceivingData();
|
||||
void onClientDisconnected();
|
||||
|
||||
protected:
|
||||
|
||||
IContext& m_context;
|
||||
QTcpSocket* m_tcp_socket;
|
||||
uint m_client_id;
|
||||
|
||||
};
|
||||
protected:
|
||||
IContext &m_context;
|
||||
QTcpSocket *m_tcp_socket;
|
||||
uint m_client_id;
|
||||
};
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace BlackMisc
|
||||
{
|
||||
|
||||
CComServer::CComServer(IContext &context, QObject *parent)
|
||||
: m_context(context), QObject(parent), m_tcp_server(NULL), m_port(0)
|
||||
: QObject(parent), m_context(context), m_tcp_server(NULL), m_port(0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
@@ -37,8 +37,8 @@ CComServer::~CComServer()
|
||||
bool CComServer::init()
|
||||
{
|
||||
m_tcp_server = new QTcpServer(this);
|
||||
Q_ASSERT (m_tcp_server);
|
||||
Q_ASSERT ( QObject::connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(onIncomingConnection()) ) );
|
||||
Q_ASSERT(m_tcp_server);
|
||||
Q_ASSERT(QObject::connect(m_tcp_server, SIGNAL(newConnection()), this, SLOT(onIncomingConnection())));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -47,10 +47,10 @@ void CComServer::Host(const QHostAddress &address, const quint16 port)
|
||||
{
|
||||
if (isHosting()) return;
|
||||
|
||||
Q_ASSERT ( ! address.isNull() );
|
||||
Q_ASSERT ( port > 0 );
|
||||
Q_ASSERT(! address.isNull());
|
||||
Q_ASSERT(port > 0);
|
||||
|
||||
if ( !m_tcp_server->listen(address, port) )
|
||||
if (!m_tcp_server->listen(address, port))
|
||||
{
|
||||
bError(m_context) << "Hosting failed";
|
||||
emit doHostClosed();
|
||||
@@ -72,7 +72,7 @@ void CComServer::close()
|
||||
m_tcp_server->close();
|
||||
}
|
||||
|
||||
void CComServer::sendToClient( const uint clientID, const QString &messageID, const QByteArray& data)
|
||||
void CComServer::sendToClient(const uint clientID, const QString &messageID, const QByteArray &data)
|
||||
{
|
||||
if (!m_client_buffers.contains(clientID))
|
||||
{
|
||||
@@ -82,7 +82,7 @@ void CComServer::sendToClient( const uint clientID, const QString &messageID, co
|
||||
m_client_buffers.value(clientID)->sendMessage(messageID, data);
|
||||
}
|
||||
|
||||
void CComServer::sendToAll(const QString &messageID, const QByteArray& data)
|
||||
void CComServer::sendToAll(const QString &messageID, const QByteArray &data)
|
||||
{
|
||||
TClientBufferHash::const_iterator it = m_client_buffers.constBegin();
|
||||
while (it != m_client_buffers.constEnd())
|
||||
@@ -92,24 +92,24 @@ void CComServer::sendToAll(const QString &messageID, const QByteArray& data)
|
||||
}
|
||||
}
|
||||
|
||||
QString CComServer::getErrorMessage( const QAbstractSocket::SocketError error )
|
||||
QString CComServer::getErrorMessage(const QAbstractSocket::SocketError error)
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
void CComServer::onIncomingConnection()
|
||||
{
|
||||
while ( m_tcp_server->hasPendingConnections() )
|
||||
while (m_tcp_server->hasPendingConnections())
|
||||
{
|
||||
QTcpSocket* socket = m_tcp_server->nextPendingConnection();
|
||||
QTcpSocket *socket = m_tcp_server->nextPendingConnection();
|
||||
uint clientID = qHash(socket);
|
||||
|
||||
// Create new ClientBuffer object. This new object gets the owner of the socket
|
||||
CComClientBuffer* clientbuf = new CComClientBuffer (m_context, clientID, socket,this);
|
||||
CComClientBuffer *clientbuf = new CComClientBuffer(m_context, clientID, socket, this);
|
||||
Q_ASSERT(clientbuf);
|
||||
|
||||
connect(clientbuf, SIGNAL(doDisconnected(uint)), this, SLOT(onClientDisconnected(uint)));
|
||||
connect(clientbuf, SIGNAL(doReceivedMessage(uint, QString&, QByteArray&)), this, SLOT(onClientMessageReceived(uint, QString&, QByteArray&)));
|
||||
connect(clientbuf, SIGNAL(doReceivedMessage(uint, QString &, QByteArray &)), this, SLOT(onClientMessageReceived(uint, QString &, QByteArray &)));
|
||||
|
||||
m_client_buffers.insert(clientID, clientbuf);
|
||||
|
||||
@@ -119,7 +119,7 @@ void CComServer::onIncomingConnection()
|
||||
|
||||
void CComServer::onClientDisconnected(uint clientID)
|
||||
{
|
||||
if ( !m_client_buffers.contains(clientID))
|
||||
if (!m_client_buffers.contains(clientID))
|
||||
{
|
||||
bWarning(m_context) << "Disconnected unknown client!";
|
||||
return;
|
||||
|
||||
@@ -93,12 +93,9 @@ namespace BlackMisc
|
||||
protected:
|
||||
|
||||
IContext& m_context;
|
||||
|
||||
QTcpServer* m_tcp_server;
|
||||
|
||||
QHostAddress m_address;
|
||||
quint16 m_port;
|
||||
|
||||
typedef QHash<uint, CComClientBuffer*> TClientBufferHash;
|
||||
TClientBufferHash m_client_buffers;
|
||||
};
|
||||
|
||||
@@ -10,229 +10,229 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
CValue::CValue() : _type(CONFIG_UNKOWN), _value(""), _int_value(0),
|
||||
_bool_value(false), _double_value(0.0)
|
||||
{
|
||||
CValue::CValue() : m_bool_value(false), m_double_value(0.0), m_int_value(0),
|
||||
m_type(CONFIG_UNKOWN), m_value("")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CValue::CValue(const QString &value) : m_bool_value(false), m_double_value(0.0), m_int_value(0),
|
||||
m_type(CONFIG_UNKOWN), m_value(value)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
void CValue::init()
|
||||
{
|
||||
bool result = false;
|
||||
qint32 int_value = 0;
|
||||
double double_value = 0.0;
|
||||
|
||||
int_value = m_value.toInt(&result);
|
||||
if (result)
|
||||
{
|
||||
m_type = CONFIG_INT;
|
||||
m_int_value = int_value;
|
||||
m_double_value = int_value;
|
||||
m_bool_value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
CValue::CValue (const QString& value) : _type(CONFIG_UNKOWN), _value(value), _int_value(0),
|
||||
_bool_value(false), _double_value(0.0)
|
||||
double_value = m_value.toDouble(&result);
|
||||
if (result)
|
||||
{
|
||||
init();
|
||||
m_type = CONFIG_DOUBLE;
|
||||
m_int_value = 0;
|
||||
m_double_value = double_value;
|
||||
m_bool_value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
void CValue::init()
|
||||
if (m_value.compare("false", Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
bool result = false;
|
||||
qint32 int_value = 0;
|
||||
double double_value = 0.0;
|
||||
|
||||
int_value = _value.toInt( &result );
|
||||
if (result)
|
||||
{
|
||||
_type = CONFIG_INT;
|
||||
_int_value = int_value;
|
||||
_double_value = int_value;
|
||||
_bool_value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
double_value = _value.toDouble( &result );
|
||||
if (result)
|
||||
{
|
||||
_type = CONFIG_DOUBLE;
|
||||
_int_value = 0;
|
||||
_double_value = double_value;
|
||||
_bool_value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( _value.compare("false", Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
_type = CONFIG_BOOL;
|
||||
_int_value = 0;
|
||||
_double_value = 0.0;
|
||||
_bool_value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( _value.compare("true", Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
_type = CONFIG_BOOL;
|
||||
_int_value = 0;
|
||||
_double_value = 0.0;
|
||||
_bool_value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_type = CONFIG_STRING;
|
||||
_int_value = 0;
|
||||
_double_value = 0.0;
|
||||
_bool_value = false;
|
||||
m_type = CONFIG_BOOL;
|
||||
m_int_value = 0;
|
||||
m_double_value = 0.0;
|
||||
m_bool_value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
qint32 CValue::asInt( bool* ok )
|
||||
if (m_value.compare("true", Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
bool result = true;
|
||||
if ( _type != CONFIG_INT )
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (ok != NULL)
|
||||
*ok = result;
|
||||
return _int_value;
|
||||
m_type = CONFIG_BOOL;
|
||||
m_int_value = 0;
|
||||
m_double_value = 0.0;
|
||||
m_bool_value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
double CValue::asDouble( bool* ok )
|
||||
{
|
||||
bool result = true;
|
||||
if ( _type != CONFIG_DOUBLE )
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
m_type = CONFIG_STRING;
|
||||
m_int_value = 0;
|
||||
m_double_value = 0.0;
|
||||
m_bool_value = false;
|
||||
}
|
||||
|
||||
if (ok != NULL)
|
||||
*ok = result;
|
||||
return _double_value;
|
||||
qint32 CValue::asInt(bool *ok)
|
||||
{
|
||||
bool result = true;
|
||||
if (m_type != CONFIG_INT)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
bool CValue::asBool( bool* ok )
|
||||
{
|
||||
bool result = true;
|
||||
if ( _type != CONFIG_BOOL )
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
if (ok != NULL)
|
||||
*ok = result;
|
||||
return m_int_value;
|
||||
}
|
||||
|
||||
if (ok != NULL)
|
||||
*ok = result;
|
||||
return _bool_value;
|
||||
double CValue::asDouble(bool *ok)
|
||||
{
|
||||
bool result = true;
|
||||
if (m_type != CONFIG_DOUBLE)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
CConfig::CConfig(IContext &context, const QString& filename, const QString& separator, bool /*isRelative*/)
|
||||
: m_context(context), m_configfile(filename), m_separator(separator)
|
||||
if (ok != NULL)
|
||||
*ok = result;
|
||||
return m_double_value;
|
||||
}
|
||||
|
||||
bool CValue::asBool(bool *ok)
|
||||
{
|
||||
bool result = true;
|
||||
if (m_type != CONFIG_BOOL)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
bool CConfig::load()
|
||||
if (ok != NULL)
|
||||
*ok = result;
|
||||
return m_bool_value;
|
||||
}
|
||||
|
||||
CConfig::CConfig(IContext &context, const QString &filename, const QString &separator, bool /*isRelative*/)
|
||||
: m_context(context), m_configfile(filename), m_separator(separator)
|
||||
{
|
||||
}
|
||||
|
||||
bool CConfig::load()
|
||||
{
|
||||
return load(m_configfile);
|
||||
}
|
||||
|
||||
bool CConfig::load(const QString &filename)
|
||||
{
|
||||
m_configfile = filename;
|
||||
|
||||
m_value_map.clear();
|
||||
|
||||
if (m_configfile.isEmpty())
|
||||
{
|
||||
return load(m_configfile);
|
||||
bError(m_context) << "Can't open emtpy config file!";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CConfig::load(const QString& filename)
|
||||
QFile input(m_configfile);
|
||||
if (!input.open(QIODevice::ReadOnly))
|
||||
{
|
||||
m_configfile = filename;
|
||||
|
||||
m_value_map.clear();
|
||||
|
||||
if (m_configfile.isEmpty())
|
||||
{
|
||||
bError(m_context) << "Can't open emtpy config file!";
|
||||
return false;
|
||||
}
|
||||
QFile input (m_configfile);
|
||||
if ( !input.open(QIODevice::ReadOnly))
|
||||
{
|
||||
bError(m_context) << "Failed to open config file !" << m_configfile;
|
||||
input.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool error = false;
|
||||
quint32 no_line = 0;
|
||||
|
||||
QTextStream instream(&input);
|
||||
|
||||
while ( !instream.atEnd() )
|
||||
{
|
||||
++no_line;
|
||||
|
||||
QString line = instream.readLine();
|
||||
|
||||
// Remove any whitespace from the start and end
|
||||
line = line.trimmed();
|
||||
|
||||
// Search for the comment operator and discard it
|
||||
int pos = line.indexOf( QChar('#') );
|
||||
if ( pos != -1 )
|
||||
line = line.left(pos).trimmed();
|
||||
|
||||
// Check if we have a empty line
|
||||
if ( line.isEmpty() )
|
||||
continue;
|
||||
|
||||
// Separate between key and value
|
||||
QStringList tags = line.split(m_separator);
|
||||
if ( tags.count() != 2)
|
||||
{
|
||||
bWarning(m_context) << "Could not parse line " << no_line << " in file " << m_configfile << "!";
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
QString key = tags[0].trimmed();
|
||||
CValue value = CValue( tags[1].trimmed() );
|
||||
|
||||
setValue (key, value);
|
||||
}
|
||||
|
||||
bError(m_context) << "Failed to open config file !" << m_configfile;
|
||||
input.close();
|
||||
return !error;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CConfig::setValue(const QString &key, const CValue &value)
|
||||
{
|
||||
if ( contains(key) )
|
||||
update(key, value);
|
||||
else
|
||||
add(key, value);
|
||||
}
|
||||
bool error = false;
|
||||
quint32 no_line = 0;
|
||||
|
||||
CValue CConfig::value(const QString &key) const
|
||||
{
|
||||
if (m_value_map.contains(key))
|
||||
return m_value_map.value(key);
|
||||
else
|
||||
return CValue();
|
||||
}
|
||||
QTextStream instream(&input);
|
||||
|
||||
bool CConfig::contains(const QString &key) const
|
||||
while (!instream.atEnd())
|
||||
{
|
||||
return m_value_map.contains(key);
|
||||
}
|
||||
++no_line;
|
||||
|
||||
void CConfig::remove(const QString &key)
|
||||
{
|
||||
m_value_map.remove(key);
|
||||
}
|
||||
QString line = instream.readLine();
|
||||
|
||||
void CConfig::add(const QString &key, const CValue &value)
|
||||
{
|
||||
// Paranoid...
|
||||
if ( contains(key) )
|
||||
// Remove any whitespace from the start and end
|
||||
line = line.trimmed();
|
||||
|
||||
// Search for the comment operator and discard it
|
||||
int pos = line.indexOf(QChar('#'));
|
||||
if (pos != -1)
|
||||
line = line.left(pos).trimmed();
|
||||
|
||||
// Check if we have a empty line
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
|
||||
// Separate between key and value
|
||||
QStringList tags = line.split(m_separator);
|
||||
if (tags.count() != 2)
|
||||
{
|
||||
update(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_value_map.insert(key, value);
|
||||
bWarning(m_context) << "Could not parse line " << no_line << " in file " << m_configfile << "!";
|
||||
error = true;
|
||||
continue;
|
||||
}
|
||||
QString key = tags[0].trimmed();
|
||||
CValue value = CValue(tags[1].trimmed());
|
||||
|
||||
setValue(key, value);
|
||||
}
|
||||
|
||||
void CConfig::update(const QString &key, const CValue &value)
|
||||
{
|
||||
m_value_map[key] = value;
|
||||
}
|
||||
input.close();
|
||||
return !error;
|
||||
}
|
||||
|
||||
void CConfig::display()
|
||||
void CConfig::setValue(const QString &key, const CValue &value)
|
||||
{
|
||||
if (contains(key))
|
||||
update(key, value);
|
||||
else
|
||||
add(key, value);
|
||||
}
|
||||
|
||||
CValue CConfig::value(const QString &key) const
|
||||
{
|
||||
if (m_value_map.contains(key))
|
||||
return m_value_map.value(key);
|
||||
else
|
||||
return CValue();
|
||||
}
|
||||
|
||||
bool CConfig::contains(const QString &key) const
|
||||
{
|
||||
return m_value_map.contains(key);
|
||||
}
|
||||
|
||||
void CConfig::remove(const QString &key)
|
||||
{
|
||||
m_value_map.remove(key);
|
||||
}
|
||||
|
||||
void CConfig::add(const QString &key, const CValue &value)
|
||||
{
|
||||
// Paranoid...
|
||||
if (contains(key))
|
||||
{
|
||||
TValueMap::const_iterator it;
|
||||
for (it = m_value_map.begin(); it != m_value_map.end(); ++it)
|
||||
{
|
||||
CValue value = it.value();
|
||||
bDebug(m_context) << "Key: " << it.key() << " - Value: " << value.asString();
|
||||
}
|
||||
update(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_value_map.insert(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
void CConfig::update(const QString &key, const CValue &value)
|
||||
{
|
||||
m_value_map[key] = value;
|
||||
}
|
||||
|
||||
void CConfig::display()
|
||||
{
|
||||
TValueMap::const_iterator it;
|
||||
for (it = m_value_map.begin(); it != m_value_map.end(); ++it)
|
||||
{
|
||||
CValue value = it.value();
|
||||
bDebug(m_context) << "Key: " << it.key() << " - Value: " << value.asString();
|
||||
}
|
||||
}
|
||||
|
||||
} //! namespace BlackMisc
|
||||
|
||||
@@ -6,162 +6,163 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
#include <QMap>
|
||||
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
class IContext;
|
||||
class IContext;
|
||||
|
||||
class CValue
|
||||
{
|
||||
public:
|
||||
class CValue
|
||||
{
|
||||
public:
|
||||
|
||||
//! Configuration type enum.
|
||||
/*! This enum lists the three different values, used in the config file. */
|
||||
typedef enum { CONFIG_STRING = 0, /*!< Type String. */
|
||||
CONFIG_INT, /*!< Type Integer. */
|
||||
CONFIG_DOUBLE, /*!< Type Double. */
|
||||
CONFIG_BOOL, /*!< Type Bool. */
|
||||
CONFIG_UNKOWN /*!< Type Unknown. */
|
||||
} TConfigType;
|
||||
//! Configuration type enum.
|
||||
/*! This enum lists the three different values, used in the config file. */
|
||||
typedef enum { CONFIG_STRING = 0, /*!< Type String. */
|
||||
CONFIG_INT, /*!< Type Integer. */
|
||||
CONFIG_DOUBLE, /*!< Type Double. */
|
||||
CONFIG_BOOL, /*!< Type Bool. */
|
||||
CONFIG_UNKOWN /*!< Type Unknown. */
|
||||
} TConfigType;
|
||||
|
||||
CValue ();
|
||||
CValue();
|
||||
|
||||
CValue (const QString& value);
|
||||
CValue(const QString &value);
|
||||
|
||||
void init();
|
||||
void init();
|
||||
|
||||
QString& asString() { return _value; }
|
||||
QString &asString() { return m_value; }
|
||||
|
||||
qint32 asInt( bool* ok = NULL );
|
||||
qint32 asInt(bool *ok = NULL);
|
||||
|
||||
bool asBool(bool* ok = NULL );
|
||||
bool asBool(bool *ok = NULL);
|
||||
|
||||
double asDouble( bool* result );
|
||||
double asDouble(bool *result);
|
||||
|
||||
inline bool isValid() {return _type != CONFIG_UNKOWN;}
|
||||
inline bool isValid() {return m_type != CONFIG_UNKOWN;}
|
||||
|
||||
inline bool isInt() { return _type == CONFIG_INT; }
|
||||
inline bool isDouble() { return _type == CONFIG_DOUBLE; }
|
||||
inline bool isBool() { return _type == CONFIG_BOOL; }
|
||||
inline bool isInt() { return m_type == CONFIG_INT; }
|
||||
inline bool isDouble() { return m_type == CONFIG_DOUBLE; }
|
||||
inline bool isBool() { return m_type == CONFIG_BOOL; }
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
QString _value;
|
||||
TConfigType _type;
|
||||
bool m_bool_value;
|
||||
double m_double_value;
|
||||
qint32 m_int_value;
|
||||
TConfigType m_type;
|
||||
QString m_value;
|
||||
|
||||
qint32 _int_value;
|
||||
double _double_value;
|
||||
bool _bool_value;
|
||||
};
|
||||
|
||||
};
|
||||
//! Configuration class.
|
||||
/*!
|
||||
This class implements the configuration part of the library.
|
||||
\warning it is not safe to use this from within
|
||||
*/
|
||||
class CConfig
|
||||
{
|
||||
public:
|
||||
|
||||
//! Configuration class.
|
||||
CConfig(IContext &context, const QString &filename, const QString &separator = "=", bool isRelative = false);
|
||||
|
||||
//! Sets the value of the specified key.
|
||||
/*!
|
||||
This class implements the configuration part of the library.
|
||||
\warning it is not safe to use this from within
|
||||
\param key Key, which value should be set.
|
||||
\param value The actual value as T.
|
||||
*/
|
||||
class CConfig
|
||||
{
|
||||
public:
|
||||
void setValue(const QString &key, const CValue &value);
|
||||
|
||||
CConfig(IContext &context, const QString& filename, const QString& separator = "=", bool isRelative = false);
|
||||
//! Returns the value from key.
|
||||
/*!
|
||||
\param key Specified key.
|
||||
\return The value to key 'key' as T&
|
||||
*/
|
||||
CValue value(const QString &key) const;
|
||||
|
||||
//! Sets the value of the specified key.
|
||||
/*!
|
||||
\param key Key, which value should be set.
|
||||
\param value The actual value as T.
|
||||
*/
|
||||
void setValue(const QString& key, const CValue& value);
|
||||
//! Function to check if the key is in the config.
|
||||
/*!
|
||||
\param key Specified key.
|
||||
\return Returns true, if key is in the config.
|
||||
*/
|
||||
void add(const QString &key, const CValue &value);
|
||||
|
||||
//! Returns the value from key.
|
||||
/*!
|
||||
\param key Specified key.
|
||||
\return The value to key 'key' as T&
|
||||
*/
|
||||
CValue value(const QString& key) const;
|
||||
//! Function to check if the key is in the config.
|
||||
/*!
|
||||
\param key Specified key.
|
||||
\return Returns true, if key is in the config.
|
||||
*/
|
||||
void update(const QString &key, const CValue &value);
|
||||
|
||||
//! Function to check if the key is in the config.
|
||||
/*!
|
||||
\param key Specified key.
|
||||
\return Returns true, if key is in the config.
|
||||
*/
|
||||
void add (const QString& key, const CValue& value);
|
||||
//! Function to check if the key is in the config.
|
||||
/*!
|
||||
\param key Specified key.
|
||||
\return Returns true, if key is in the config.
|
||||
*/
|
||||
bool contains(const QString &key) const;
|
||||
|
||||
//! Function to check if the key is in the config.
|
||||
/*!
|
||||
\param key Specified key.
|
||||
\return Returns true, if key is in the config.
|
||||
*/
|
||||
void update (const QString& key, const CValue& value);
|
||||
//! Removes the key and its value from the config.
|
||||
/*!
|
||||
\param key Key, which has to be removed.
|
||||
*/
|
||||
void remove(const QString &key);
|
||||
|
||||
//! Function to check if the key is in the config.
|
||||
/*!
|
||||
\param key Specified key.
|
||||
\return Returns true, if key is in the config.
|
||||
*/
|
||||
bool contains (const QString& key) const;
|
||||
//! Displays the configuration to the debug output.
|
||||
/*!
|
||||
More info.
|
||||
*/
|
||||
void display();
|
||||
|
||||
//! Removes the key and its value from the config.
|
||||
/*!
|
||||
\param key Key, which has to be removed.
|
||||
*/
|
||||
void remove (const QString& key);
|
||||
/*!
|
||||
* Config File section
|
||||
*/
|
||||
|
||||
//! Displays the configuration to the debug output.
|
||||
/*!
|
||||
More info.
|
||||
*/
|
||||
void display ();
|
||||
//! Returns the config filename of this config object.
|
||||
/*!
|
||||
\return filename of this config.
|
||||
*/
|
||||
const QString &configFile() const {return m_configfile; }
|
||||
|
||||
/*!
|
||||
* Config File section
|
||||
*/
|
||||
//! Loads the config file.
|
||||
/*!
|
||||
\return Returns true if loading went well.
|
||||
*/
|
||||
bool load();
|
||||
|
||||
//! Returns the config filename of this config object.
|
||||
/*!
|
||||
\return filename of this config.
|
||||
*/
|
||||
const QString& configFile() const {return m_configfile; }
|
||||
//! Loads the config file.
|
||||
/*!
|
||||
\param filename Specify a different filename.
|
||||
\return Returns true if loading went well.
|
||||
*/
|
||||
bool load(const QString &filename);
|
||||
|
||||
//! Loads the config file.
|
||||
/*!
|
||||
\return Returns true if loading went well.
|
||||
*/
|
||||
bool load ();
|
||||
//! Saves the config to file.
|
||||
/*!
|
||||
\return Returns true if loading went well.
|
||||
*/
|
||||
bool save() { return false; } // TODO
|
||||
|
||||
//! Loads the config file.
|
||||
/*!
|
||||
\param filename Specify a different filename.
|
||||
\return Returns true if loading went well.
|
||||
*/
|
||||
bool load (const QString& filename);
|
||||
//! Saves the config to file.
|
||||
/*!
|
||||
\param filename Specify a different filename.
|
||||
\return Returns true if loading went well.
|
||||
*/
|
||||
bool save(const QString &filename) { qDebug() << filename; return false; } // TODO
|
||||
|
||||
//! Saves the config to file.
|
||||
/*!
|
||||
\return Returns true if loading went well.
|
||||
*/
|
||||
bool save() {} // TODO
|
||||
protected:
|
||||
|
||||
//! Saves the config to file.
|
||||
/*!
|
||||
\param filename Specify a different filename.
|
||||
\return Returns true if loading went well.
|
||||
*/
|
||||
bool save(const QString& filename) {} // TODO
|
||||
IContext &m_context;
|
||||
QString m_configfile;
|
||||
QString m_separator;
|
||||
typedef QMap<QString, CValue> TValueMap;
|
||||
TValueMap m_value_map;
|
||||
|
||||
protected:
|
||||
|
||||
IContext &m_context;
|
||||
QString m_configfile;
|
||||
QString m_separator;
|
||||
typedef QMap<QString, CValue> TValueMap;
|
||||
TValueMap m_value_map;
|
||||
|
||||
};
|
||||
};
|
||||
} //! namespace BlackMisc
|
||||
|
||||
#endif // CONFIG_H
|
||||
|
||||
@@ -25,7 +25,7 @@ CCoordinateEcef CCoordinateTransformation::toEcef(const CCoordinateNed &ned)
|
||||
{
|
||||
CLatitude lat = ned.referencePosition().latitude();
|
||||
CLongitude lon = ned.referencePosition().longitude();
|
||||
double angleRad = - (lat.value(CAngleUnit::rad())) - BlackMisc::Math::PI / 2;
|
||||
double angleRad = - (lat.value(CAngleUnit::rad())) - CMath::PI() / 2;
|
||||
|
||||
CMatrix3x3 dcm1;
|
||||
CMatrix3x3 dcm2;
|
||||
@@ -99,7 +99,7 @@ CCoordinateNed CCoordinateTransformation::toNed(const CCoordinateEcef &ecef, con
|
||||
|
||||
CLatitude lat = referencePosition.latitude();
|
||||
CLongitude lon = referencePosition.longitude();
|
||||
double angleRad = - (lat.value(CAngleUnit::rad())) - BlackMisc::Math::PI / 2;
|
||||
double angleRad = - (lat.value(CAngleUnit::rad())) - CMath::PI() / 2;
|
||||
|
||||
CMatrix3x3 dcm1;
|
||||
CMatrix3x3 dcm2(0.0);
|
||||
|
||||
@@ -7,133 +7,133 @@
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
CDebug::CDebug()
|
||||
: m_isInitialized(false), m_errorLog(NULL), m_warningLog(NULL),
|
||||
m_infoLog(NULL), m_debugLog(NULL)
|
||||
CDebug::CDebug()
|
||||
: m_isInitialized(false), m_errorLog(NULL), m_warningLog(NULL),
|
||||
m_infoLog(NULL), m_debugLog(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CDebug::create(const char *logPath, bool logInFile, bool eraseLastLog)
|
||||
{
|
||||
if (!m_isInitialized)
|
||||
{
|
||||
setErrorLog(new CLog(IContext::getInstance(), CLog::eError));
|
||||
setWarningLog(new CLog(IContext::getInstance(), CLog::eWarning));
|
||||
setInfoLog(new CLog(IContext::getInstance(), CLog::eInfo));
|
||||
setDebugLog(new CLog(IContext::getInstance(), CLog::eDebug));
|
||||
|
||||
}
|
||||
|
||||
void CDebug::create(const char *logPath, bool logInFile, bool eraseLastLog)
|
||||
{
|
||||
if (!m_isInitialized)
|
||||
{
|
||||
setErrorLog(new CLog(IContext::getInstance(), CLog::eError));
|
||||
setWarningLog(new CLog(IContext::getInstance(), CLog::eWarning));
|
||||
setInfoLog(new CLog(IContext::getInstance(), CLog::eInfo));
|
||||
setDebugLog(new CLog(IContext::getInstance(), CLog::eDebug));
|
||||
|
||||
stdDisplayer = new CStdDisplay("DEFAULT_SD");
|
||||
|
||||
if (logInFile)
|
||||
{
|
||||
QDir fileinfo(m_logPath);
|
||||
QString fn;
|
||||
if (!m_logPath.isEmpty())
|
||||
{
|
||||
m_logPath = fileinfo.absolutePath();
|
||||
fn += m_logPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
fileDisplayer = new CFileDisplay("", true, "DEFAULT_FD");
|
||||
fileDisplayer = new CFileDisplay("", eraseLastLog, "DEFAULT_FD");
|
||||
}
|
||||
|
||||
init(true);
|
||||
m_isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
void CDebug::init(bool logInFile)
|
||||
{
|
||||
m_debugLog->attachDisplay(stdDisplayer);
|
||||
m_infoLog->attachDisplay(stdDisplayer);
|
||||
m_warningLog->attachDisplay(stdDisplayer);
|
||||
m_errorLog->attachDisplay(stdDisplayer);
|
||||
stdDisplayer = new CStdDisplay("DEFAULT_SD");
|
||||
|
||||
if (logInFile)
|
||||
{
|
||||
m_debugLog->attachDisplay(fileDisplayer);
|
||||
m_infoLog->attachDisplay(fileDisplayer);
|
||||
m_warningLog->attachDisplay(fileDisplayer);
|
||||
m_errorLog->attachDisplay(fileDisplayer);
|
||||
QDir fileinfo(m_logPath);
|
||||
QString fn;
|
||||
if (!m_logPath.isEmpty())
|
||||
{
|
||||
m_logPath = fileinfo.absolutePath();
|
||||
fn += m_logPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
fileDisplayer = new CFileDisplay("", true, "DEFAULT_FD");
|
||||
fileDisplayer = new CFileDisplay("", eraseLastLog, "DEFAULT_FD");
|
||||
}
|
||||
}
|
||||
|
||||
QString CDebug::getLogDirectory()
|
||||
{
|
||||
return m_logPath;
|
||||
init(true);
|
||||
m_isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
CLog *CDebug::getErrorLog()
|
||||
{
|
||||
return m_errorLog;
|
||||
}
|
||||
void CDebug::init(bool logInFile)
|
||||
{
|
||||
m_debugLog->attachDisplay(stdDisplayer);
|
||||
m_infoLog->attachDisplay(stdDisplayer);
|
||||
m_warningLog->attachDisplay(stdDisplayer);
|
||||
m_errorLog->attachDisplay(stdDisplayer);
|
||||
|
||||
void CDebug::setErrorLog(CLog *errorLog)
|
||||
if (logInFile)
|
||||
{
|
||||
m_errorLog = errorLog;
|
||||
m_debugLog->attachDisplay(fileDisplayer);
|
||||
m_infoLog->attachDisplay(fileDisplayer);
|
||||
m_warningLog->attachDisplay(fileDisplayer);
|
||||
m_errorLog->attachDisplay(fileDisplayer);
|
||||
}
|
||||
}
|
||||
|
||||
CLog *CDebug::getWarningLog()
|
||||
{
|
||||
return m_warningLog;
|
||||
}
|
||||
QString CDebug::getLogDirectory()
|
||||
{
|
||||
return m_logPath;
|
||||
}
|
||||
|
||||
void CDebug::setWarningLog(CLog *warningLog)
|
||||
{
|
||||
m_warningLog = warningLog;
|
||||
}
|
||||
CLog *CDebug::getErrorLog()
|
||||
{
|
||||
return m_errorLog;
|
||||
}
|
||||
|
||||
CLog *CDebug::getInfoLog()
|
||||
{
|
||||
return m_infoLog;
|
||||
}
|
||||
void CDebug::setErrorLog(CLog *errorLog)
|
||||
{
|
||||
m_errorLog = errorLog;
|
||||
}
|
||||
|
||||
void CDebug::setInfoLog(CLog *infoLog)
|
||||
{
|
||||
m_infoLog = infoLog;
|
||||
}
|
||||
CLog *CDebug::getWarningLog()
|
||||
{
|
||||
return m_warningLog;
|
||||
}
|
||||
|
||||
CLog *CDebug::getDebugLog()
|
||||
{
|
||||
return m_debugLog;
|
||||
}
|
||||
void CDebug::setWarningLog(CLog *warningLog)
|
||||
{
|
||||
m_warningLog = warningLog;
|
||||
}
|
||||
|
||||
void CDebug::setDebugLog(CLog *debugLog)
|
||||
{
|
||||
m_debugLog = debugLog;
|
||||
}
|
||||
CLog *CDebug::getInfoLog()
|
||||
{
|
||||
return m_infoLog;
|
||||
}
|
||||
|
||||
CLogMessage CDebug::blackInfo(int line, const char *fileName, const char *methodName)
|
||||
{
|
||||
create();
|
||||
m_infoLog->setLogInformation(line, fileName, methodName);
|
||||
return CLogMessage(*this, CLog::eInfo);
|
||||
}
|
||||
void CDebug::setInfoLog(CLog *infoLog)
|
||||
{
|
||||
m_infoLog = infoLog;
|
||||
}
|
||||
|
||||
CLogMessage CDebug::blackWarning(int line, const char *fileName, const char *methodName)
|
||||
{
|
||||
create();
|
||||
m_warningLog->setLogInformation(line, fileName, methodName);
|
||||
return CLogMessage(*this, CLog::eWarning);
|
||||
}
|
||||
CLog *CDebug::getDebugLog()
|
||||
{
|
||||
return m_debugLog;
|
||||
}
|
||||
|
||||
CLogMessage CDebug::blackDebug(int line, const char *fileName, const char *methodName)
|
||||
{
|
||||
create();
|
||||
m_debugLog->setLogInformation(line, fileName, methodName);
|
||||
return CLogMessage(*this, CLog::eDebug);
|
||||
}
|
||||
void CDebug::setDebugLog(CLog *debugLog)
|
||||
{
|
||||
m_debugLog = debugLog;
|
||||
}
|
||||
|
||||
CLogMessage CDebug::blackError(int line, const char *fileName, const char *methodName)
|
||||
{
|
||||
create();
|
||||
m_errorLog->setLogInformation(line, fileName, methodName);
|
||||
return CLogMessage(*this, CLog::eError);
|
||||
}
|
||||
CLogMessage CDebug::blackInfo(int line, const char *fileName, const char *methodName)
|
||||
{
|
||||
create();
|
||||
m_infoLog->setLogInformation(line, fileName, methodName);
|
||||
return CLogMessage(*this, CLog::eInfo);
|
||||
}
|
||||
|
||||
CLogMessage CDebug::blackWarning(int line, const char *fileName, const char *methodName)
|
||||
{
|
||||
create();
|
||||
m_warningLog->setLogInformation(line, fileName, methodName);
|
||||
return CLogMessage(*this, CLog::eWarning);
|
||||
}
|
||||
|
||||
CLogMessage CDebug::blackDebug(int line, const char *fileName, const char *methodName)
|
||||
{
|
||||
create();
|
||||
m_debugLog->setLogInformation(line, fileName, methodName);
|
||||
return CLogMessage(*this, CLog::eDebug);
|
||||
}
|
||||
|
||||
CLogMessage CDebug::blackError(int line, const char *fileName, const char *methodName)
|
||||
{
|
||||
create();
|
||||
m_errorLog->setLogInformation(line, fileName, methodName);
|
||||
return CLogMessage(*this, CLog::eError);
|
||||
}
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
@@ -112,9 +112,6 @@ namespace BlackMisc
|
||||
if (needSpace) { line += " : "; needSpace = false; }
|
||||
|
||||
line += message;
|
||||
|
||||
static bool consoleMode = true;
|
||||
|
||||
QTextStream out(stdout);
|
||||
out << line;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,11 @@
|
||||
|
||||
//TODO do we still need these platform includes here?
|
||||
#ifdef Q_OS_WIN
|
||||
# define NOMINMAX
|
||||
# include <process.h>
|
||||
# include <windows.h>
|
||||
# ifndef NOMINMAX
|
||||
# define NOMINMAX
|
||||
# include <process.h>
|
||||
# include <windows.h>
|
||||
# endif
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
@@ -4,50 +4,50 @@
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
CLogMessage::LogStream::LogStream(CLog::TLogType type)
|
||||
: output(&buffer, QIODevice::WriteOnly), reference(1),
|
||||
type(type), needSpace(true), enableOutput(true)
|
||||
{}
|
||||
CLogMessage::LogStream::LogStream(CLog::TLogType type)
|
||||
: output(&buffer, QIODevice::WriteOnly),
|
||||
type(type), needSpace(true), enableOutput(true), reference(1)
|
||||
{}
|
||||
|
||||
CLogMessage::CLogMessage(CDebug &debug_, CLog::TLogType type)
|
||||
: debug(debug_), logStream(new LogStream(type))
|
||||
{
|
||||
}
|
||||
CLogMessage::CLogMessage(CDebug &debug_, CLog::TLogType type)
|
||||
: logStream(new LogStream(type)), debug(debug_)
|
||||
{
|
||||
}
|
||||
|
||||
CLogMessage::CLogMessage(const CLogMessage &other)
|
||||
: debug(other.debug), logStream(other.logStream)
|
||||
{
|
||||
++logStream->reference;
|
||||
}
|
||||
CLogMessage::CLogMessage(const CLogMessage &other)
|
||||
: logStream(other.logStream), debug(other.debug)
|
||||
{
|
||||
++logStream->reference;
|
||||
}
|
||||
|
||||
CLogMessage::~CLogMessage()
|
||||
CLogMessage::~CLogMessage()
|
||||
{
|
||||
if (!--logStream->reference)
|
||||
{
|
||||
if (!--logStream->reference)
|
||||
if (logStream->enableOutput)
|
||||
{
|
||||
if (logStream->enableOutput)
|
||||
switch (logStream->type)
|
||||
{
|
||||
switch (logStream->type)
|
||||
{
|
||||
case CLog::eWarning:
|
||||
debug.getWarningLog()->printWithNewLine(logStream->buffer);
|
||||
break;
|
||||
case CLog::eWarning:
|
||||
debug.getWarningLog()->printWithNewLine(logStream->buffer);
|
||||
break;
|
||||
|
||||
case CLog::eInfo:
|
||||
debug.getInfoLog()->printWithNewLine(logStream->buffer);
|
||||
break;
|
||||
case CLog::eInfo:
|
||||
debug.getInfoLog()->printWithNewLine(logStream->buffer);
|
||||
break;
|
||||
|
||||
case CLog::eDebug:
|
||||
debug.getDebugLog()->printWithNewLine(logStream->buffer);
|
||||
break;
|
||||
case CLog::eDebug:
|
||||
debug.getDebugLog()->printWithNewLine(logStream->buffer);
|
||||
break;
|
||||
|
||||
case CLog::eError:
|
||||
default:
|
||||
debug.getErrorLog()->printWithNewLine(logStream->buffer);
|
||||
break;
|
||||
}
|
||||
case CLog::eError:
|
||||
default:
|
||||
debug.getErrorLog()->printWithNewLine(logStream->buffer);
|
||||
break;
|
||||
}
|
||||
delete logStream;
|
||||
}
|
||||
delete logStream;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Blackib
|
||||
|
||||
@@ -12,14 +12,6 @@ namespace BlackMisc
|
||||
namespace Math
|
||||
{
|
||||
|
||||
// Some namespace wide constant values
|
||||
|
||||
//! Mathematical constant Pi
|
||||
const double PI = 4.0 * qAtan(1.0);
|
||||
|
||||
//! 2 * Pi
|
||||
const double TwoPI = 2.0 * PI;
|
||||
|
||||
/*!
|
||||
* \brief Math utils
|
||||
*/
|
||||
@@ -78,6 +70,26 @@ public:
|
||||
*/
|
||||
static double roundEpsilon(double value, double epsilon);
|
||||
|
||||
/*!
|
||||
* \brief PI
|
||||
* \return
|
||||
*/
|
||||
static const double &PI()
|
||||
{
|
||||
static double pi = 4.0 * qAtan(1.0);
|
||||
return pi;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PI * 2
|
||||
* \return
|
||||
*/
|
||||
static const double &PI2()
|
||||
{
|
||||
static double pi2 = PI();
|
||||
return pi2;
|
||||
}
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief Avoid object init
|
||||
|
||||
@@ -34,7 +34,8 @@ template<class ImplMatrix, int Rows, int Columns> void CMatrixBase<ImplMatrix, R
|
||||
*/
|
||||
template<class ImplMatrix, int Rows, int Columns> void CMatrixBase<ImplMatrix, Rows, Columns>::checkRange(size_t row, size_t column) const
|
||||
{
|
||||
bool valid = (row >= 0 && column >= 0 && row < Rows && column < Columns);
|
||||
// no >=0 comparison since unsinged comparison always >=0
|
||||
bool valid = (row < Rows && column < Columns);
|
||||
Q_ASSERT_X(valid, "getElement()", "Row or column invalid");
|
||||
if (!valid) throw std::range_error("Row or column invalid");
|
||||
}
|
||||
|
||||
@@ -3,30 +3,30 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
SINGLETON_CLASS_IMPLEMENTATION(CMessageDispatcher)
|
||||
SINGLETON_CLASS_IMPLEMENTATION(CMessageDispatcher)
|
||||
|
||||
void CMessageDispatcher::append(IMessage *message)
|
||||
void CMessageDispatcher::append(IMessage *message)
|
||||
{
|
||||
m_messageQueue.enqueue(message);
|
||||
}
|
||||
|
||||
void CMessageDispatcher::dispatch()
|
||||
{
|
||||
IMessage *message = NULL;
|
||||
|
||||
if (m_messageQueue.isEmpty())
|
||||
return;
|
||||
|
||||
message = m_messageQueue.dequeue();
|
||||
|
||||
if (message != NULL)
|
||||
{
|
||||
m_messageQueue.enqueue(message);
|
||||
}
|
||||
|
||||
void CMessageDispatcher::dispatch()
|
||||
{
|
||||
IMessage* message = NULL;
|
||||
|
||||
if (m_messageQueue.isEmpty())
|
||||
return;
|
||||
|
||||
message = m_messageQueue.dequeue();
|
||||
|
||||
if (message != NULL)
|
||||
{
|
||||
CTypeInfo typeinfo = CTypeInfo(typeid(*message));
|
||||
QList<CMessageHandler*> neededHandlers = m_messageHander.values(typeinfo);
|
||||
int testsize = neededHandlers.size();
|
||||
for (int i = 0; i < neededHandlers.size(); ++i)
|
||||
neededHandlers.at(i)->handleMessage(message);
|
||||
}
|
||||
CTypeInfo typeinfo = CTypeInfo(typeid(*message));
|
||||
QList<CMessageHandler *> neededHandlers = m_messageHander.values(typeinfo);
|
||||
int handlerSize = neededHandlers.size();
|
||||
for (int i = 0; i < handlerSize; ++i)
|
||||
neededHandlers.at(i)->handleMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
@@ -17,44 +17,44 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
class IMessageCreator
|
||||
{
|
||||
public:
|
||||
IMessageCreator(const QString& messageID);
|
||||
class IMessageCreator
|
||||
{
|
||||
public:
|
||||
IMessageCreator(const QString &messageID);
|
||||
virtual IMessage *create() = 0;
|
||||
virtual ~IMessageCreator() {}
|
||||
};
|
||||
|
||||
virtual IMessage* create() = 0;
|
||||
};
|
||||
template <class T>
|
||||
class MessageCreatorImpl : public IMessageCreator
|
||||
{
|
||||
public:
|
||||
MessageCreatorImpl(const QString &messageID) : IMessageCreator(messageID) {}
|
||||
virtual IMessage *create() { return new T; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class MessageCreatorImpl : public IMessageCreator
|
||||
{
|
||||
public:
|
||||
MessageCreatorImpl(const QString& messageID) : IMessageCreator(messageID) {}
|
||||
virtual IMessage* create() { return new T; }
|
||||
};
|
||||
class CMessageFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class CMessageFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
// safe singleton declaration
|
||||
SINGLETON_CLASS_DECLARATION(CMessageFactory)
|
||||
|
||||
// safe singleton declaration
|
||||
SINGLETON_CLASS_DECLARATION(CMessageFactory)
|
||||
CMessageFactory() { }
|
||||
public:
|
||||
|
||||
CMessageFactory() { }
|
||||
public:
|
||||
virtual ~CMessageFactory();
|
||||
|
||||
virtual ~CMessageFactory();
|
||||
IMessage *create(const QString &messageID);
|
||||
|
||||
IMessage* create (const QString &messageID);
|
||||
void registerMessage(const QString &messageID, IMessageCreator *creator);
|
||||
static void registerMessages();
|
||||
|
||||
void registerMessage(const QString &messageID, IMessageCreator* creator);
|
||||
static void registerMessages();
|
||||
private:
|
||||
|
||||
private:
|
||||
|
||||
typedef QHash<QString, IMessageCreator*> TMessageCreatorHash;
|
||||
TMessageCreatorHash m_creators;
|
||||
};
|
||||
typedef QHash<QString, IMessageCreator *> TMessageCreatorHash;
|
||||
TMessageCreatorHash m_creators;
|
||||
};
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
/* 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/. */
|
||||
@@ -47,22 +47,22 @@ public:
|
||||
*/
|
||||
virtual ~CAngle() {}
|
||||
|
||||
/*!
|
||||
* \brief Convenience method PI
|
||||
* \return
|
||||
*/
|
||||
static double pi()
|
||||
{
|
||||
return double(M_PI);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Value as factor of PI (e.g. 0.5PI)
|
||||
* \return
|
||||
*/
|
||||
double piFactor() const
|
||||
{
|
||||
return BlackMisc::Math::CMath::round(this->convertedSiValueToDouble() / M_PI, 6);
|
||||
return BlackMisc::Math::CMath::round(this->convertedSiValueToDouble() / BlackMisc::Math::CMath::PI() , 6);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PI as convenience method
|
||||
* \return
|
||||
*/
|
||||
static const double &PI()
|
||||
{
|
||||
return BlackMisc::Math::CMath::PI();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -91,9 +91,9 @@ bool CMeasurementPrefix::operator <(const CMeasurementPrefix &otherMultiplier) c
|
||||
CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &unitName, const QString &type, bool isSIUnit, bool isSIBaseUnit,
|
||||
double conversionFactorToSI, const CMeasurementPrefix &multiplier, qint32 displayDigits, double epsilon,
|
||||
UnitConverter toSiConverter, UnitConverter fromSiConverter):
|
||||
m_name(name), m_unitName(unitName), m_type(type), m_isSiUnit(isSIUnit), m_isSiBaseUnit(isSIBaseUnit), m_displayDigits(displayDigits),
|
||||
m_name(name), m_unitName(unitName), m_type(type), m_isSiUnit(isSIUnit), m_isSiBaseUnit(isSIBaseUnit),
|
||||
m_conversionFactorToSIConversionUnit(conversionFactorToSI),
|
||||
m_epsilon(epsilon), m_multiplier(multiplier), m_fromSiConverter(fromSiConverter), m_toSiConverter(toSiConverter)
|
||||
m_epsilon(epsilon), m_displayDigits(displayDigits), m_multiplier(multiplier), m_fromSiConverter(fromSiConverter), m_toSiConverter(toSiConverter)
|
||||
{
|
||||
// void
|
||||
}
|
||||
@@ -103,8 +103,8 @@ CMeasurementUnit::CMeasurementUnit(const QString &name, const QString &unitName,
|
||||
*/
|
||||
CMeasurementUnit::CMeasurementUnit(const CMeasurementUnit &otherUnit):
|
||||
m_name(otherUnit.m_name), m_unitName(otherUnit.m_unitName), m_type(otherUnit.m_type), m_isSiUnit(otherUnit.m_isSiUnit),
|
||||
m_isSiBaseUnit(otherUnit.m_isSiBaseUnit), m_displayDigits(otherUnit.m_displayDigits), m_conversionFactorToSIConversionUnit(otherUnit.m_conversionFactorToSIConversionUnit),
|
||||
m_epsilon(otherUnit.m_epsilon), m_multiplier(otherUnit.m_multiplier), m_fromSiConverter(otherUnit.m_fromSiConverter), m_toSiConverter(otherUnit.m_toSiConverter)
|
||||
m_isSiBaseUnit(otherUnit.m_isSiBaseUnit), m_conversionFactorToSIConversionUnit(otherUnit.m_conversionFactorToSIConversionUnit),
|
||||
m_epsilon(otherUnit.m_epsilon), m_displayDigits(otherUnit.m_displayDigits), m_multiplier(otherUnit.m_multiplier), m_fromSiConverter(otherUnit.m_fromSiConverter), m_toSiConverter(otherUnit.m_toSiConverter)
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
@@ -233,10 +233,10 @@ private:
|
||||
bool m_isSiBaseUnit; //!< SI base unit?
|
||||
double m_conversionFactorToSIConversionUnit; //!< factor to convert to SI, set to 0 if not applicable (rare cases, e.g. temperature)
|
||||
double m_epsilon; //!< values with differences below epsilon are the equal
|
||||
qint32 m_displayDigits; //!< standard rounding for string conversions
|
||||
int m_displayDigits; //!< standard rounding for string conversions
|
||||
CMeasurementPrefix m_multiplier; //!< multiplier (kilo, Mega)
|
||||
UnitConverter m_toSiConverter; //! allows an arbitrary conversion method as per object
|
||||
UnitConverter m_fromSiConverter; //! allows an arbitrary conversion method as per object
|
||||
UnitConverter m_toSiConverter; //! allows an arbitrary conversion method as per object
|
||||
|
||||
protected:
|
||||
/*!
|
||||
@@ -479,6 +479,17 @@ public:
|
||||
*/
|
||||
double epsilonUpRounding(double value) const;
|
||||
|
||||
/*!
|
||||
* \brief Is given value <= epsilon?
|
||||
* \param checkValue
|
||||
* \return
|
||||
*/
|
||||
bool isEpsilon(double checkValue) const
|
||||
{
|
||||
if (checkValue == 0) return true;
|
||||
return abs(checkValue) <= this->m_epsilon;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// -- static
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
@@ -20,14 +20,13 @@ namespace PhysicalQuantities
|
||||
{
|
||||
/*!
|
||||
* \brief A physical quantity such as "5m", "20s", "1500ft/s"
|
||||
* \author KWB
|
||||
*/
|
||||
template <class MU, class PQ> class CPhysicalQuantity : public BlackMisc::CBaseStreamStringifier<PQ>
|
||||
{
|
||||
|
||||
private:
|
||||
qint32 m_unitValueI; //!< value backed by integer, allows sole integer arithmetic
|
||||
double m_unitValueD; //!< value backed by double
|
||||
qint32 m_unitValueI; //!< value backed by integer, allows sole integer arithmetic
|
||||
double m_convertedSiUnitValueD; //!< SI unit value
|
||||
bool m_isIntegerBaseValue; //!< flag integer? / double?
|
||||
|
||||
@@ -383,6 +382,33 @@ public:
|
||||
*/
|
||||
PQ operator -(const PQ &otherQuantity) const;
|
||||
|
||||
/*!
|
||||
* \brief Quantity value <= epsilon
|
||||
* \return
|
||||
*/
|
||||
bool isZeroEpsilon() const
|
||||
{
|
||||
if (this->m_isIntegerBaseValue) return this->m_unitValueI == 0;
|
||||
return this->m_unit.isEpsilon(this->m_unitValueD);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Value >= 0 epsilon considered
|
||||
* \return
|
||||
*/
|
||||
bool isGreaterOrEqualZeroEpsilon() const
|
||||
{
|
||||
return this->isZeroEpsilon() || this->m_unitValueD > 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Value <= 0 epsilon considered
|
||||
* \return
|
||||
*/
|
||||
bool isLessOrEqualZeroEpsilon() const
|
||||
{
|
||||
return this->isZeroEpsilon() || this->m_unitValueD < 0;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user