From c6426a075949f7e18e5758c7ecc244e2d92067b6 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 29 Apr 2013 16:00:41 +0200 Subject: [PATCH] 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) --- samples/Logging/sample_logging.pro | 15 +- .../blackmiscquantities/samplesaviation.cpp | 15 +- samples/blackmiscquantities/samplesaviation.h | 3 +- .../samplesphysicalquantities.cpp | 2 +- samples/com_client/sample_com_client.pro | 16 +- samples/com_server/sample_com_server.pro | 13 +- samples/config/sample_config.pro | 15 +- samples/interpolator/sample_interpolator.pro | 21 +- samples/logging/sample_logging.pro | 15 +- samples/plugin/sample_plugin.pro | 15 +- samples/pluginmgr/sample_pluginmgr.pro | 21 +- src/blackbox/blackbox.pro | 12 +- src/blackcore/fsd_messages.h | 218 +++++------ src/blackcore/interpolator.cpp | 2 +- src/blackcore/plane.cpp | 2 +- src/blackcore/simulator.h | 11 +- src/blackd/blackd.cpp | 97 ++--- src/blackd/blackd.pro | 22 +- src/blackmisc/aviomodulator.cpp | 2 +- src/blackmisc/aviomodulator.h | 12 +- src/blackmisc/avionavsystem.h | 66 ++-- src/blackmisc/aviotransponder.h | 4 +- src/blackmisc/avverticalpositions.cpp | 4 +- src/blackmisc/avverticalpositions.h | 4 +- src/blackmisc/basestreamstringifier.h | 12 +- src/blackmisc/com_client.cpp | 2 +- src/blackmisc/com_client.h | 58 +-- src/blackmisc/com_client_buffer.cpp | 76 ++-- src/blackmisc/com_client_buffer.h | 51 ++- src/blackmisc/com_server.cpp | 28 +- src/blackmisc/com_server.h | 3 - src/blackmisc/config.cpp | 370 +++++++++--------- src/blackmisc/config.h | 237 +++++------ src/blackmisc/coordinatetransformation.cpp | 4 +- src/blackmisc/debug.cpp | 212 +++++----- src/blackmisc/display.cpp | 3 - src/blackmisc/log.cpp | 8 +- src/blackmisc/logmessage.cpp | 66 ++-- src/blackmisc/mathematics.h | 28 +- src/blackmisc/mathmatrixbase.cpp | 3 +- src/blackmisc/message_dispatcher.cpp | 44 +-- src/blackmisc/message_factory.h | 58 +-- src/blackmisc/pqangle.h | 22 +- src/blackmisc/pqbase.cpp | 8 +- src/blackmisc/pqbase.h | 15 +- src/blackmisc/pqphysicalquantity.h | 30 +- tests/blackmisc/testaviation.cpp | 7 +- tests/blackmisc/testphysicalquantities.cpp | 2 +- 48 files changed, 1034 insertions(+), 920 deletions(-) diff --git a/samples/Logging/sample_logging.pro b/samples/Logging/sample_logging.pro index 3afe1dfe7..d22de1cdf 100644 --- a/samples/Logging/sample_logging.pro +++ b/samples/Logging/sample_logging.pro @@ -8,17 +8,18 @@ CONFIG += console CONFIG -= app_bundle DEPENDPATH += . ../../src - INCLUDEPATH += . ../../src SOURCES += *.cpp -LIBS += -L../../lib -lblackmisc +win32-msvc* { + PRE_TARGETDEPS += ../../lib/blackmisc.lib + LIBS += ../../lib/blackmisc.lib +} -win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a +!win32-msvc* { + PRE_TARGETDEPS += ../../lib/libblackmisc.a + LIBS += ../../lib/libblackmisc.a +} DESTDIR = ../../bin - - - diff --git a/samples/blackmiscquantities/samplesaviation.cpp b/samples/blackmiscquantities/samplesaviation.cpp index acba81946..77204bef9 100644 --- a/samples/blackmiscquantities/samplesaviation.cpp +++ b/samples/blackmiscquantities/samplesaviation.cpp @@ -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/. */ @@ -17,8 +17,14 @@ namespace BlackMiscTest int CSamplesAviation::samples() { // CSpeed s1(10, CSpeedUnit::kts()); + CMeasurementPrefix p1 = CMeasurementPrefix::G(); + CAngle a(10, CAngleUnit::deg()); + qDebug() << a; + CHeading h1(180, true, CAngleUnit::deg()); CHeading h2(180, false, CAngleUnit::deg()); + + qDebug() << h1; qDebug() << h1 << h2 << (h1 == h2) << (h1 != h2) << (h1 == h1); CAviationVerticalPositions vp1 = CAviationVerticalPositions::fromAltitudeAndElevationInFt(10000.0, 1111.0); @@ -36,12 +42,15 @@ int CSamplesAviation::samples() else qDebug() << "Something is wrong here"; - try { + try + { // uncomment to test assert // CFrequency f1(-1.0, CFrequencyUnit::MHz()); // c1 = CComSystem("ups", f1, f1); // qDebug() << "Why do I get here??"; - } catch (std::range_error &ex) { + } + catch (std::range_error &ex) + { qDebug() << "As expected" << ex.what(); } diff --git a/samples/blackmiscquantities/samplesaviation.h b/samples/blackmiscquantities/samplesaviation.h index 3cd0cafbf..67093c95e 100644 --- a/samples/blackmiscquantities/samplesaviation.h +++ b/samples/blackmiscquantities/samplesaviation.h @@ -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/. */ @@ -12,6 +12,7 @@ #include "blackmisc/aviocomsystem.h" #include "blackmisc/avionavsystem.h" #include "blackmisc/aviotransponder.h" +#include namespace BlackMiscTest { diff --git a/samples/blackmiscquantities/samplesphysicalquantities.cpp b/samples/blackmiscquantities/samplesphysicalquantities.cpp index 0a88b6be5..7b4eaafeb 100644 --- a/samples/blackmiscquantities/samplesphysicalquantities.cpp +++ b/samples/blackmiscquantities/samplesphysicalquantities.cpp @@ -61,7 +61,7 @@ int CSamplesPhysicalQuantities::samples() qDebug() << s2 << s3; CAngle a1(180, CAngleUnit::deg()); - CAngle a2(1.5 * CAngle::pi(), CAngleUnit::rad()); + CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad()); CAngle a3(180.5, CAngleUnit::deg()); CAngle a4(35.4336, CAngleUnit::sexagesimalDeg()); // 35.72666 a1 += a2; diff --git a/samples/com_client/sample_com_client.pro b/samples/com_client/sample_com_client.pro index 7ae763799..4b9007501 100644 --- a/samples/com_client/sample_com_client.pro +++ b/samples/com_client/sample_com_client.pro @@ -9,19 +9,19 @@ CONFIG -= app_bundle TEMPLATE = app DEPENDPATH += . ../../src - INCLUDEPATH += . ../../src SOURCES += *.cpp - HEADERS += *.h -LIBS += -L../../lib -lblackmisc +win32-msvc* { + PRE_TARGETDEPS += ../../lib/blackmisc.lib + LIBS += ../../lib/blackmisc.lib +} -win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a +!win32-msvc* { + PRE_TARGETDEPS += ../../lib/libblackmisc.a + LIBS += ../../lib/libblackmisc.a +} DESTDIR = ../../bin - - - diff --git a/samples/com_server/sample_com_server.pro b/samples/com_server/sample_com_server.pro index 968f4e4a3..21da67c03 100644 --- a/samples/com_server/sample_com_server.pro +++ b/samples/com_server/sample_com_server.pro @@ -8,17 +8,20 @@ CONFIG += console CONFIG -= app_bundle DEPENDPATH += . ../../src - INCLUDEPATH += . ../../src SOURCES += *.cpp - HEADERS += *.h -LIBS += -L../../lib -lblackmisc +win32-msvc* { + PRE_TARGETDEPS += ../../lib/blackmisc.lib + LIBS += ../../lib/blackmisc.lib +} -win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a +!win32-msvc* { + PRE_TARGETDEPS += ../../lib/libblackmisc.a + LIBS += ../../lib/libblackmisc.a +} DESTDIR = ../../bin diff --git a/samples/config/sample_config.pro b/samples/config/sample_config.pro index ed1122f63..18906e263 100644 --- a/samples/config/sample_config.pro +++ b/samples/config/sample_config.pro @@ -5,17 +5,18 @@ TARGET = sample_config TEMPLATE = app DEPENDPATH += . ../../src - INCLUDEPATH += . ../../src SOURCES += *.cpp -LIBS += -L../../lib -lblackmisc +win32-msvc* { + PRE_TARGETDEPS += ../../lib/blackmisc.lib + LIBS += ../../lib/blackmisc.lib +} -win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a +!win32-msvc* { + PRE_TARGETDEPS += ../../lib/libblackmisc.a + LIBS += ../../lib/libblackmisc.a +} DESTDIR = ../../bin - - - diff --git a/samples/interpolator/sample_interpolator.pro b/samples/interpolator/sample_interpolator.pro index c4138cbc8..13a77d8cc 100644 --- a/samples/interpolator/sample_interpolator.pro +++ b/samples/interpolator/sample_interpolator.pro @@ -6,17 +6,22 @@ CONFIG -= app_bundle TEMPLATE = app -CONFIG += console -CONFIG -= app_bundle - DEPENDPATH += . ../../src INCLUDEPATH += . ../../src SOURCES += *.cpp -LIBS += -L../../lib -lblackcore -lblackmisc -win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a +win32-msvc* { + PRE_TARGETDEPS += ../../lib/blackmisc.lib + PRE_TARGETDEPS += ../../lib/blackcore.lib + LIBS += ../../lib/blackmisc.lib + LIBS += ../../lib/blackcore.lib +} + +!win32-msvc* { + PRE_TARGETDEPS += ../../lib/libblackmisc.a + PRE_TARGETDEPS += ../../lib/libblackcore.a + LIBS += ../../lib/libblackmisc.a + LIBS += ../../lib/libblackcore.a +} DESTDIR = ../../bin diff --git a/samples/logging/sample_logging.pro b/samples/logging/sample_logging.pro index 3afe1dfe7..d22de1cdf 100644 --- a/samples/logging/sample_logging.pro +++ b/samples/logging/sample_logging.pro @@ -8,17 +8,18 @@ CONFIG += console CONFIG -= app_bundle DEPENDPATH += . ../../src - INCLUDEPATH += . ../../src SOURCES += *.cpp -LIBS += -L../../lib -lblackmisc +win32-msvc* { + PRE_TARGETDEPS += ../../lib/blackmisc.lib + LIBS += ../../lib/blackmisc.lib +} -win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a +!win32-msvc* { + PRE_TARGETDEPS += ../../lib/libblackmisc.a + LIBS += ../../lib/libblackmisc.a +} DESTDIR = ../../bin - - - diff --git a/samples/plugin/sample_plugin.pro b/samples/plugin/sample_plugin.pro index 2604ada6b..354f9b794 100644 --- a/samples/plugin/sample_plugin.pro +++ b/samples/plugin/sample_plugin.pro @@ -6,17 +6,18 @@ TEMPLATE = lib CONFIG += plugin DEPENDPATH += . ../../src - INCLUDEPATH += . ../../src SOURCES += *.cpp -LIBS += -L../../lib -lblackmisc +win32-msvc* { + PRE_TARGETDEPS += ../../lib/blackmisc.lib + LIBS += ../../lib/blackmisc.lib +} -win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a +!win32-msvc* { + PRE_TARGETDEPS += ../../lib/libblackmisc.a + LIBS += ../../lib/libblackmisc.a +} DESTDIR = ../../bin - - - diff --git a/samples/pluginmgr/sample_pluginmgr.pro b/samples/pluginmgr/sample_pluginmgr.pro index 30f50f0fa..2a8c326fe 100644 --- a/samples/pluginmgr/sample_pluginmgr.pro +++ b/samples/pluginmgr/sample_pluginmgr.pro @@ -8,19 +8,22 @@ CONFIG += console CONFIG -= app_bundle DEPENDPATH += . ../../src - INCLUDEPATH += . ../../src SOURCES += *.cpp -LIBS += -L../../lib -lblackcore -lblackmisc +win32-msvc* { + PRE_TARGETDEPS += ../../lib/blackmisc.lib + PRE_TARGETDEPS += ../../lib/blackcore.lib + LIBS += ../../lib/blackmisc.lib + LIBS += ../../lib/blackcore.lib +} -win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a +!win32-msvc* { + PRE_TARGETDEPS += ../../lib/libblackmisc.a + PRE_TARGETDEPS += ../../lib/libblackcore.a + LIBS += ../../lib/libblackmisc.a + LIBS += ../../lib/libblackcore.a +} DESTDIR = ../../bin - - - diff --git a/src/blackbox/blackbox.pro b/src/blackbox/blackbox.pro index 5f1a9f31e..58b6c3b3e 100644 --- a/src/blackbox/blackbox.pro +++ b/src/blackbox/blackbox.pro @@ -8,14 +8,18 @@ TARGET = BlackBox TEMPLATE = app SOURCES += *.cpp - HEADERS += *.h FORMS += blackbox.ui dialog_connect.ui dialog_chat.ui -LIBS += -L../../lib -lblackmisc +win32-msvc* { + PRE_TARGETDEPS += ../../lib/blackmisc.lib + LIBS += ../../lib/blackmisc.lib +} -win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a +!win32-msvc* { + PRE_TARGETDEPS += ../../lib/libblackmisc.a + LIBS += ../../lib/libblackmisc.a +} DESTDIR = ../../bin diff --git a/src/blackcore/fsd_messages.h b/src/blackcore/fsd_messages.h index d52d0fcdb..ce0af2870 100644 --- a/src/blackcore/fsd_messages.h +++ b/src/blackcore/fsd_messages.h @@ -18,139 +18,131 @@ typedef QVector QStringVector; namespace FSD { - class FSD_MSG : public BlackMisc::IMessage +class FSD_MSG : public BlackMisc::IMessage +{ +public: + FSD_MSG(QString id) : IMessage(id) { - public: - FSD_MSG(QString id) : IMessage(id) - { - } + } - void setSource(const QString &source) {m_source = source; } - void setDest(const QString &destination) {m_destination = destination; } + void setSource(const QString &source) {m_source = source; } + void setDest(const QString &destination) {m_destination = destination; } - protected: - qint32 unpack(const QString &line, QStringVector &tokens); - QString pack(const QStringVector &tokens) const; +protected: + qint32 unpack(const QString &line, QStringVector &tokens); + QString pack(const QStringVector &tokens) const; - QString m_destination; - QString m_source; - }; + QString m_destination; + QString m_source; +}; - class FSD_MSG_AddPilot : public FSD_MSG +class FSD_MSG_AddPilot : public FSD_MSG +{ +public: + FSD_MSG_AddPilot() : FSD_MSG("#AP"), m_rating(1), m_revision(VATSIM_PROTOCOL_REV) {} + void setUserID(const QString &userID) { m_userID = userID; } + void setPassword(const QString &password) { m_password = password; } + void setSimulator(const quint16 &simulator) { m_simulator = simulator; } + void setRealName(const QString &name) { m_realName = name; } + + virtual QDataStream &operator<< (QDataStream &in) { return in; } + virtual QDataStream &operator>> (QDataStream &out) const { return out; } + + virtual QTextStream &operator<< (QTextStream &in) + { return in; } + virtual QTextStream &operator>> (QTextStream &out) const { - public: - FSD_MSG_AddPilot() : FSD_MSG("#AP"), m_revision(VATSIM_PROTOCOL_REV), - m_rating(1) - { - } + QStringVector tokens; + tokens << m_source << m_destination << m_userID << m_password; + tokens << QString("%1").arg(m_rating) << QString("%1").arg(m_revision); + tokens << QString("%1").arg(m_simulator) << m_realName; + out << pack(tokens); + return out; + } - void setUserID(const QString &userID) { m_userID = userID; } - void setPassword(const QString &password) { m_password = password; } - void setSimulator(const quint16 &simulator) { m_simulator = simulator; } - void setRealName(const QString &name) { m_realName = name; } +private: - virtual QDataStream& operator<< (QDataStream& in) { return in; } - virtual QDataStream& operator>> (QDataStream& out) const { return out; } + QString m_userID; + QString m_password; + quint16 m_rating; + quint16 m_revision; + quint16 m_simulator; + QString m_realName; +}; - virtual QTextStream& operator<< ( QTextStream& in) - { return in; } - virtual QTextStream& operator>> (QTextStream& out) const - { - QStringVector tokens; - tokens << m_source << m_destination << m_userID << m_password; - tokens << QString("%1").arg(m_rating) << QString("%1").arg(m_revision); - tokens << QString("%1").arg(m_simulator) << m_realName; - out << pack(tokens); - return out; - } - - private: - - QString m_userID; - QString m_password; - quint16 m_rating; - quint16 m_revision; - quint16 m_simulator; - QString m_realName; - }; - - class FSD_MSG_TextMessage : public FSD_MSG +class FSD_MSG_TextMessage : public FSD_MSG +{ +public: + FSD_MSG_TextMessage() : FSD_MSG(QString("#TM")) {} + virtual QDataStream &operator<< (QDataStream &in) { return in; } + virtual QDataStream &operator>> (QDataStream &out) const { return out;} + virtual QTextStream &operator<< (QTextStream &in) { - public: - FSD_MSG_TextMessage() : FSD_MSG(QString("#TM")) - { - } + QString message = in.readAll(); + QStringVector tokens; - virtual QDataStream& operator<< (QDataStream& in) { return in; } - virtual QDataStream& operator>> (QDataStream& out) const { return out;} + //tokens.resize(3); + unpack(message, tokens); + m_source = tokens.at(0); + m_destination = tokens.at(1); + int size = tokens.size(); + QString m_textmessage; + for (int ii = 2; ii < size; ++ii) + m_textmessage += tokens.at(ii); + bAppInfo << m_textmessage; + return in; + } - virtual QTextStream& operator<< ( QTextStream& in) - { - QString message = in.readAll(); - QStringVector tokens; - - //tokens.resize(3); - unpack(message, tokens); - m_source = tokens.at(0); - m_destination = tokens.at(1); - int size = tokens.size(); - QString m_textmessage; - for ( int ii = 2; ii < tokens.size(); ++ii) - m_textmessage += tokens.at(ii); - bAppInfo << m_textmessage; - return in; - } - - virtual QTextStream& operator>> (QTextStream& out) const - { - QStringVector tokens; - tokens << m_source << m_destination; - out << pack(tokens); - return out; - } - }; - - class FSD_MSG_Plane_Position : public FSD_MSG + virtual QTextStream &operator>> (QTextStream &out) const { - public: + QStringVector tokens; + tokens << m_source << m_destination; + out << pack(tokens); + return out; + } +}; - FSD_MSG_Plane_Position() : FSD_MSG(QString("@")) - { - m_message_tokens.resize(10); - } +class FSD_MSG_Plane_Position : public FSD_MSG +{ +public: - inline QString SquawkMode() const { return m_message_tokens.at(0); } - inline QString Callsign() const { return m_message_tokens.at(1); } - inline QString Squawk() const { return m_message_tokens.at(2); } - inline quint16 Rating() const { return m_message_tokens.at(3).toUInt(); } - inline double Latitude() const { return m_message_tokens.at(4).toDouble(); } - inline double Longitude() const { return m_message_tokens.at(5).toDouble(); } - inline double Altitude() const { return m_message_tokens.at(6).toDouble(); } - inline qint32 Speed() const { return m_message_tokens.at(7).toInt(); } - inline quint32 PBH() const { return m_message_tokens.at(8).toUInt(); } - inline qint32 AltDiff() const { return m_message_tokens.at(9).toInt(); } + FSD_MSG_Plane_Position() : FSD_MSG(QString("@")) + { + m_message_tokens.resize(10); + } - inline void setSquawkMode( const QString &squawk_mode) { m_message_tokens.replace(0, squawk_mode); } - inline void setCallsign ( const QString &callsign) { m_message_tokens.replace(1, callsign); } - inline void setSquawk ( const QString &squawk) { m_message_tokens.replace(2, squawk); } - inline void setRating ( const quint16 rating) { m_message_tokens.replace(3, QString("%1").arg(rating)); } - inline void setLatitude ( const double latitude) { m_message_tokens.replace(4, QString("%1").arg(latitude)); } - inline void setLongitude ( const double longitude) { m_message_tokens.replace(5, QString("%1").arg(longitude)); } - inline void setAltitude ( const double altitude) { m_message_tokens.replace(6, QString("%1").arg(altitude)); } - inline void setSpeed ( const qint32 speed) { m_message_tokens.replace(7, QString("%1").arg(speed)); } - inline void setPBH ( const quint32 pbh) { m_message_tokens.replace(8, QString("%1").arg(pbh)); } - inline void setAltDiff ( const qint32 altdiff) { m_message_tokens.replace(9, QString("%1").arg(altdiff)); } + inline QString SquawkMode() const { return m_message_tokens.at(0); } + inline QString Callsign() const { return m_message_tokens.at(1); } + inline QString Squawk() const { return m_message_tokens.at(2); } + inline quint16 Rating() const { return m_message_tokens.at(3).toUInt(); } + inline double Latitude() const { return m_message_tokens.at(4).toDouble(); } + inline double Longitude() const { return m_message_tokens.at(5).toDouble(); } + inline double Altitude() const { return m_message_tokens.at(6).toDouble(); } + inline qint32 Speed() const { return m_message_tokens.at(7).toInt(); } + inline quint32 PBH() const { return m_message_tokens.at(8).toUInt(); } + inline qint32 AltDiff() const { return m_message_tokens.at(9).toInt(); } - virtual QTextStream& operator<< ( QTextStream& in); - virtual QTextStream& operator>> (QTextStream& out) const; + inline void setSquawkMode(const QString &squawk_mode) { m_message_tokens.replace(0, squawk_mode); } + inline void setCallsign(const QString &callsign) { m_message_tokens.replace(1, callsign); } + inline void setSquawk(const QString &squawk) { m_message_tokens.replace(2, squawk); } + inline void setRating(const quint16 rating) { m_message_tokens.replace(3, QString("%1").arg(rating)); } + inline void setLatitude(const double latitude) { m_message_tokens.replace(4, QString("%1").arg(latitude)); } + inline void setLongitude(const double longitude) { m_message_tokens.replace(5, QString("%1").arg(longitude)); } + inline void setAltitude(const double altitude) { m_message_tokens.replace(6, QString("%1").arg(altitude)); } + inline void setSpeed(const qint32 speed) { m_message_tokens.replace(7, QString("%1").arg(speed)); } + inline void setPBH(const quint32 pbh) { m_message_tokens.replace(8, QString("%1").arg(pbh)); } + inline void setAltDiff(const qint32 altdiff) { m_message_tokens.replace(9, QString("%1").arg(altdiff)); } - virtual QDataStream& operator<< (QDataStream& in) { return in; } - virtual QDataStream& operator>> (QDataStream& out) const { return out;} + virtual QTextStream &operator<< (QTextStream &in); + virtual QTextStream &operator>> (QTextStream &out) const; - private: - QStringVector m_message_tokens; - }; + virtual QDataStream &operator<< (QDataStream &in) { return in; } + virtual QDataStream &operator>> (QDataStream &out) const { return out;} + +private: + QStringVector m_message_tokens; +}; } // namespace FSD diff --git a/src/blackcore/interpolator.cpp b/src/blackcore/interpolator.cpp index b0ff48937..6c12e9b79 100644 --- a/src/blackcore/interpolator.cpp +++ b/src/blackcore/interpolator.cpp @@ -142,7 +142,7 @@ bool CInterpolator::stateNow(TPlaneState *state) CAngle CInterpolator::normalizeRadians(const CAngle &angle) const { double radian = angle.value(CAngleUnit::rad()); - radian = radian - BlackMisc::Math::TwoPI * floor(0.5 + radian / BlackMisc::Math::TwoPI); + radian = radian - BlackMisc::Math::CMath::PI2() * floor(0.5 + radian / BlackMisc::Math::CMath::PI2()); return CAngle(radian, CAngleUnit::rad()); } diff --git a/src/blackcore/plane.cpp b/src/blackcore/plane.cpp index c7bbf1412..cc12185b2 100644 --- a/src/blackcore/plane.cpp +++ b/src/blackcore/plane.cpp @@ -14,7 +14,7 @@ namespace BlackCore /* * Default constructor */ -CPlane::CPlane() : m_interpolator(nullptr), m_driver(nullptr) { } +CPlane::CPlane() : m_interpolator(0), m_driver(0) { } /* * Constructor diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index bbe469a23..a81dd869c 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -10,7 +10,16 @@ #include "blackmisc/coordinategeodetic.h" #include "blackmisc/mathvector3d.h" #include -#include + + +#if defined(_MSC_VER) && _MSC_VER >= 1600 +# include +# include +#else +# include +# include +#endif + #define SHARED_LIBRARY_NAME_FS9 "bb_driver_fs9" #define SHARED_LIBRARY_NAME_FSX "bb_driver_fsx" diff --git a/src/blackd/blackd.cpp b/src/blackd/blackd.cpp index 0bf4ee96c..7d3d02d33 100644 --- a/src/blackd/blackd.cpp +++ b/src/blackd/blackd.cpp @@ -29,7 +29,7 @@ BlackD::BlackD(QWidget *parent) : createTrayIcon(); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); + this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); setWindowTitle(tr("BlackD")); @@ -41,9 +41,9 @@ BlackD::BlackD(QWidget *parent) : createLogging(); - createComServer(); + createComServer(); - m_fsd_client = new CFSDClient(IContext::getInstance()); + m_fsd_client = new CFSDClient(IContext::getInstance()); bAppDebug << "BlackDaemon running..."; } @@ -63,7 +63,8 @@ void BlackD::setVisible(bool visible) void BlackD::closeEvent(QCloseEvent *event) { - if (trayIcon->isVisible()) { + if (trayIcon->isVisible()) + { QMessageBox::information(this, tr("BlackD"), tr("The program will keep running in the " "system tray. To terminate the program, " @@ -76,69 +77,73 @@ void BlackD::closeEvent(QCloseEvent *event) void BlackD::iconActivated(QSystemTrayIcon::ActivationReason reason) { - switch (reason) { + switch (reason) + { case QSystemTrayIcon::DoubleClick: setVisible(!isVisible()); + break; + default: + break; } } void BlackD::createActions() { - minimizeAction = new QAction(tr("Mi&nimize"), this); - connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); + minimizeAction = new QAction(tr("Mi&nimize"), this); + connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); - maximizeAction = new QAction(tr("Ma&ximize"), this); - connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); + maximizeAction = new QAction(tr("Ma&ximize"), this); + connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); - restoreAction = new QAction(tr("&Restore"), this); - connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); + restoreAction = new QAction(tr("&Restore"), this); + connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); - quitAction = new QAction(tr("&Quit"), this); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + quitAction = new QAction(tr("&Quit"), this); + connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); } void BlackD::createTrayIcon() { - trayIconMenu = new QMenu(this); - trayIconMenu->addAction(minimizeAction); - trayIconMenu->addAction(maximizeAction); - trayIconMenu->addAction(restoreAction); - trayIconMenu->addSeparator(); - trayIconMenu->addAction(quitAction); + trayIconMenu = new QMenu(this); + trayIconMenu->addAction(minimizeAction); + trayIconMenu->addAction(maximizeAction); + trayIconMenu->addAction(restoreAction); + trayIconMenu->addSeparator(); + trayIconMenu->addAction(quitAction); - trayIcon = new QSystemTrayIcon(this); - trayIcon->setContextMenu(trayIconMenu); + trayIcon = new QSystemTrayIcon(this); + trayIcon->setContextMenu(trayIconMenu); } void BlackD::createLogging() { - BlackMisc::IContext::getInstance().getDebug()->create(); + BlackMisc::IContext::getInstance().getDebug()->create(); m_displayer = new CQtDisplayer(ui->logginView); - BlackMisc::IContext::getInstance().getDebug()->getDebugLog()->attachDisplay (m_displayer); - BlackMisc::IContext::getInstance().getDebug()->getInfoLog()->attachDisplay (m_displayer); - BlackMisc::IContext::getInstance().getDebug()->getWarningLog()->attachDisplay (m_displayer); - BlackMisc::IContext::getInstance().getDebug()->getErrorLog()->attachDisplay (m_displayer); + BlackMisc::IContext::getInstance().getDebug()->getDebugLog()->attachDisplay(m_displayer); + BlackMisc::IContext::getInstance().getDebug()->getInfoLog()->attachDisplay(m_displayer); + BlackMisc::IContext::getInstance().getDebug()->getWarningLog()->attachDisplay(m_displayer); + BlackMisc::IContext::getInstance().getDebug()->getErrorLog()->attachDisplay(m_displayer); } void BlackD::createComServer() { - CMessageFactory::getInstance().registerMessages(); - m_comserver = new CComServer(IContext::getInstance(), this); + CMessageFactory::getInstance().registerMessages(); + m_comserver = new CComServer(IContext::getInstance(), this); - registerMessageFunction(this, &BlackD::onMSG_CONNECT_TO_VATSIM); + registerMessageFunction(this, &BlackD::onMSG_CONNECT_TO_VATSIM); - QHostAddress local = QHostAddress(QHostAddress::LocalHost); + QHostAddress local = QHostAddress(QHostAddress::LocalHost); m_comserver->Host(local, 42000); - connect(m_comserver, SIGNAL(doMessageReceived(QString &, QByteArray&)), this, SLOT(onData(QString &, QByteArray&))); + connect(m_comserver, SIGNAL(doMessageReceived(QString &, QByteArray &)), this, SLOT(onData(QString &, QByteArray &))); } void BlackD::onData(QString &messageID, QByteArray &message) { - bAppDebug << messageID; - BlackMisc::IMessage* test = BlackMisc::CMessageFactory::getInstance().create(messageID); + bAppDebug << messageID; + BlackMisc::IMessage *test = BlackMisc::CMessageFactory::getInstance().create(messageID); QDataStream stream(&message, QIODevice::ReadOnly); Q_ASSERT(test); @@ -150,19 +155,19 @@ void BlackD::onData(QString &messageID, QByteArray &message) void BlackD::onMSG_CONNECT_TO_VATSIM(const BlackMisc::MSG_CONNECT_TO_VATSIM *connect) { - bAppDebug << "Connecting to FSD server:"; - bAppDebug << connect->getHost() << ":" << connect->getPort(); + bAppDebug << "Connecting to FSD server:"; + bAppDebug << connect->getHost() << ":" << connect->getPort(); - FSD::TClientInfo clientinfo; - clientinfo.m_callsign = connect->getCallsign(); - clientinfo.m_host = connect->getHost(); - clientinfo.m_password = connect->getPassword(); - clientinfo.m_port = connect->getPort(); - clientinfo.m_realName = connect->getRealName(); - clientinfo.m_simType = FSD::SIM_UNKNOWN; - clientinfo.m_userid = connect->getUserID(); + FSD::TClientInfo clientinfo; + clientinfo.m_callsign = connect->getCallsign(); + clientinfo.m_host = connect->getHost(); + clientinfo.m_password = connect->getPassword(); + clientinfo.m_port = connect->getPort(); + clientinfo.m_realName = connect->getRealName(); + clientinfo.m_simType = FSD::SIM_UNKNOWN; + clientinfo.m_userid = connect->getUserID(); - m_fsd_client->updateClientInfo(clientinfo); + m_fsd_client->updateClientInfo(clientinfo); - m_fsd_client->connectTo(connect->getHost(), connect->getPort()); -} + m_fsd_client->connectTo(connect->getHost(), connect->getPort()); +} diff --git a/src/blackd/blackd.pro b/src/blackd/blackd.pro index 77231cdf9..640c71ede 100644 --- a/src/blackd/blackd.pro +++ b/src/blackd/blackd.pro @@ -2,28 +2,32 @@ QT += core gui xml svg network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - TARGET = blackd TEMPLATE = app -DEPENDPATH += . .. +DEPENDPATH += ../blackmisc ../blackcore INCLUDEPATH += .. SOURCES += *.cpp - HEADERS += *.h FORMS += blackd.ui - RESOURCES += blackd.qrc -LIBS += -L../../lib -lblackcore -lblackmisc +win32-msvc* { + PRE_TARGETDEPS += ../../lib/blackmisc.lib + PRE_TARGETDEPS += ../../lib/blackcore.lib + LIBS += ../../lib/blackmisc.lib + LIBS += ../../lib/blackcore.lib +} -win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ - ../../lib/blackcore.lib -else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ - ../../lib/libblackcore.a +!win32-msvc* { + PRE_TARGETDEPS += ../../lib/libblackmisc.a + PRE_TARGETDEPS += ../../lib/libblackcore.a + LIBS += ../../lib/libblackmisc.a + LIBS += ../../lib/libblackcore.a +} DESTDIR = ../../bin diff --git a/src/blackmisc/aviomodulator.cpp b/src/blackmisc/aviomodulator.cpp index 30cbcbc19..6bf3bd4b8 100644 --- a/src/blackmisc/aviomodulator.cpp +++ b/src/blackmisc/aviomodulator.cpp @@ -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/. */ diff --git a/src/blackmisc/aviomodulator.h b/src/blackmisc/aviomodulator.h index 1affaabf8..6a1bd90cd 100644 --- a/src/blackmisc/aviomodulator.h +++ b/src/blackmisc/aviomodulator.h @@ -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 diff --git a/src/blackmisc/avionavsystem.h b/src/blackmisc/avionavsystem.h index e8bdc67ce..8beef0be8 100644 --- a/src/blackmisc/avionavsystem.h +++ b/src/blackmisc/avionavsystem.h @@ -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); } }; diff --git a/src/blackmisc/aviotransponder.h b/src/blackmisc/aviotransponder.h index 106faa004..c742e5240 100644 --- a/src/blackmisc/aviotransponder.h +++ b/src/blackmisc/aviotransponder.h @@ -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); diff --git a/src/blackmisc/avverticalpositions.cpp b/src/blackmisc/avverticalpositions.cpp index c02390d4b..398113626 100644 --- a/src/blackmisc/avverticalpositions.cpp +++ b/src/blackmisc/avverticalpositions.cpp @@ -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 } diff --git a/src/blackmisc/avverticalpositions.h b/src/blackmisc/avverticalpositions.h index b094106ee..167739a57 100644 --- a/src/blackmisc/avverticalpositions.h +++ b/src/blackmisc/avverticalpositions.h @@ -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: /*! diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index 322b9e59d..714062e6f 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -14,7 +14,6 @@ namespace BlackMisc */ template class CBaseStreamStringifier { - /*! * \brief Stream << overload to be used in debugging messages * \param debug @@ -28,6 +27,17 @@ template 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 diff --git a/src/blackmisc/com_client.cpp b/src/blackmisc/com_client.cpp index 4efedff50..bfeda8e93 100644 --- a/src/blackmisc/com_client.cpp +++ b/src/blackmisc/com_client.cpp @@ -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(); } diff --git a/src/blackmisc/com_client.h b/src/blackmisc/com_client.h index 0ba9b02df..04168dc67 100644 --- a/src/blackmisc/com_client.h +++ b/src/blackmisc/com_client.h @@ -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 diff --git a/src/blackmisc/com_client_buffer.cpp b/src/blackmisc/com_client_buffer.cpp index ef2b26b8a..579936643 100644 --- a/src/blackmisc/com_client_buffer.cpp +++ b/src/blackmisc/com_client_buffer.cpp @@ -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 diff --git a/src/blackmisc/com_client_buffer.h b/src/blackmisc/com_client_buffer.h index 63c78b79d..4e6c93f85 100644 --- a/src/blackmisc/com_client_buffer.h +++ b/src/blackmisc/com_client_buffer.h @@ -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 diff --git a/src/blackmisc/com_server.cpp b/src/blackmisc/com_server.cpp index b8a9d1347..4b67198aa 100644 --- a/src/blackmisc/com_server.cpp +++ b/src/blackmisc/com_server.cpp @@ -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; diff --git a/src/blackmisc/com_server.h b/src/blackmisc/com_server.h index 81b1cb7ee..0d73de7dd 100644 --- a/src/blackmisc/com_server.h +++ b/src/blackmisc/com_server.h @@ -93,12 +93,9 @@ namespace BlackMisc protected: IContext& m_context; - QTcpServer* m_tcp_server; - QHostAddress m_address; quint16 m_port; - typedef QHash TClientBufferHash; TClientBufferHash m_client_buffers; }; diff --git a/src/blackmisc/config.cpp b/src/blackmisc/config.cpp index 408746336..f6dd5edb2 100644 --- a/src/blackmisc/config.cpp +++ b/src/blackmisc/config.cpp @@ -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 diff --git a/src/blackmisc/config.h b/src/blackmisc/config.h index 9dc0bdb1d..14c8b1b08 100644 --- a/src/blackmisc/config.h +++ b/src/blackmisc/config.h @@ -6,162 +6,163 @@ #ifndef CONFIG_H #define CONFIG_H -#include -#include #include +#include +#include +#include + 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 TValueMap; + TValueMap m_value_map; - protected: - - IContext &m_context; - QString m_configfile; - QString m_separator; - typedef QMap TValueMap; - TValueMap m_value_map; - - }; +}; } //! namespace BlackMisc #endif // CONFIG_H diff --git a/src/blackmisc/coordinatetransformation.cpp b/src/blackmisc/coordinatetransformation.cpp index b5542d39a..29a72abbb 100644 --- a/src/blackmisc/coordinatetransformation.cpp +++ b/src/blackmisc/coordinatetransformation.cpp @@ -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); diff --git a/src/blackmisc/debug.cpp b/src/blackmisc/debug.cpp index f260e46a0..01bef4277 100644 --- a/src/blackmisc/debug.cpp +++ b/src/blackmisc/debug.cpp @@ -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 diff --git a/src/blackmisc/display.cpp b/src/blackmisc/display.cpp index 003ddbdf7..843d024b2 100644 --- a/src/blackmisc/display.cpp +++ b/src/blackmisc/display.cpp @@ -112,9 +112,6 @@ namespace BlackMisc if (needSpace) { line += " : "; needSpace = false; } line += message; - - static bool consoleMode = true; - QTextStream out(stdout); out << line; } diff --git a/src/blackmisc/log.cpp b/src/blackmisc/log.cpp index 146eb9ead..bee41bf4c 100644 --- a/src/blackmisc/log.cpp +++ b/src/blackmisc/log.cpp @@ -18,9 +18,11 @@ //TODO do we still need these platform includes here? #ifdef Q_OS_WIN -# define NOMINMAX -# include -# include +# ifndef NOMINMAX +# define NOMINMAX +# include +# include +# endif #else # include #endif diff --git a/src/blackmisc/logmessage.cpp b/src/blackmisc/logmessage.cpp index 200979a5a..7740ee607 100644 --- a/src/blackmisc/logmessage.cpp +++ b/src/blackmisc/logmessage.cpp @@ -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 diff --git a/src/blackmisc/mathematics.h b/src/blackmisc/mathematics.h index 528a366da..9105bd9f0 100644 --- a/src/blackmisc/mathematics.h +++ b/src/blackmisc/mathematics.h @@ -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 diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp index bcc498aa7..9d28779ca 100644 --- a/src/blackmisc/mathmatrixbase.cpp +++ b/src/blackmisc/mathmatrixbase.cpp @@ -34,7 +34,8 @@ template void CMatrixBase void CMatrixBase::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"); } diff --git a/src/blackmisc/message_dispatcher.cpp b/src/blackmisc/message_dispatcher.cpp index 580881ccc..afeead7a1 100644 --- a/src/blackmisc/message_dispatcher.cpp +++ b/src/blackmisc/message_dispatcher.cpp @@ -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 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 neededHandlers = m_messageHander.values(typeinfo); + int handlerSize = neededHandlers.size(); + for (int i = 0; i < handlerSize; ++i) + neededHandlers.at(i)->handleMessage(message); } +} } // namespace BlackMisc diff --git a/src/blackmisc/message_factory.h b/src/blackmisc/message_factory.h index b9dc1ca05..93dbd2196 100644 --- a/src/blackmisc/message_factory.h +++ b/src/blackmisc/message_factory.h @@ -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 MessageCreatorImpl : public IMessageCreator +{ +public: + MessageCreatorImpl(const QString &messageID) : IMessageCreator(messageID) {} + virtual IMessage *create() { return new T; } +}; - template - 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 TMessageCreatorHash; - TMessageCreatorHash m_creators; - }; + typedef QHash TMessageCreatorHash; + TMessageCreatorHash m_creators; +}; } // namespace BlackMisc diff --git a/src/blackmisc/pqangle.h b/src/blackmisc/pqangle.h index c0e00155d..9ba211680 100644 --- a/src/blackmisc/pqangle.h +++ b/src/blackmisc/pqangle.h @@ -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(); } }; diff --git a/src/blackmisc/pqbase.cpp b/src/blackmisc/pqbase.cpp index a59b2697b..3e612bd3e 100644 --- a/src/blackmisc/pqbase.cpp +++ b/src/blackmisc/pqbase.cpp @@ -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 } diff --git a/src/blackmisc/pqbase.h b/src/blackmisc/pqbase.h index 327e77acf..94e1cc497 100644 --- a/src/blackmisc/pqbase.h +++ b/src/blackmisc/pqbase.h @@ -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 // -------------------------------------------------------------------- diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 7b62823cc..2314e0e48 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -20,14 +20,13 @@ namespace PhysicalQuantities { /*! * \brief A physical quantity such as "5m", "20s", "1500ft/s" - * \author KWB */ template class CPhysicalQuantity : public BlackMisc::CBaseStreamStringifier { 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 diff --git a/tests/blackmisc/testaviation.cpp b/tests/blackmisc/testaviation.cpp index af57f6a74..b03c72a06 100644 --- a/tests/blackmisc/testaviation.cpp +++ b/tests/blackmisc/testaviation.cpp @@ -8,7 +8,8 @@ using namespace BlackMisc::Aviation; using namespace BlackMisc::PhysicalQuantities; -namespace BlackMiscTest { +namespace BlackMiscTest +{ /* * Constructor @@ -26,7 +27,7 @@ void CTestAviation::headingBasics() CHeading h1(180, true, CAngleUnit::deg()); CHeading h2(180, false, CAngleUnit::deg()); CHeading h3(181, true, CAngleUnit::deg()); - CAngle a1(200,CAngleUnit::deg()); + CAngle a1(200, CAngleUnit::deg()); CHeading h4; h4 = h1; QVERIFY2(h1 != h2, "Magnetic and true heading are not the same"); @@ -49,7 +50,7 @@ void CTestAviation::verticalPosition() { CAviationVerticalPositions vp1 = CAviationVerticalPositions::fromAltitudeAndElevationInFt(10000.0, 3000.0); CAviationVerticalPositions vp2 = vp1; - QVERIFY2(vp1== vp2, "Values shall be equal"); + QVERIFY2(vp1 == vp2, "Values shall be equal"); } /* diff --git a/tests/blackmisc/testphysicalquantities.cpp b/tests/blackmisc/testphysicalquantities.cpp index 2fd7b0ba6..94cf5b5c0 100644 --- a/tests/blackmisc/testphysicalquantities.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -92,7 +92,7 @@ void CTestPhysicalQuantities::frequencyTests() void CTestPhysicalQuantities::angleTests() { CAngle a1(180, CAngleUnit::deg()); - CAngle a2(1.5 * CAngle::pi(), CAngleUnit::rad()); + CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad()); CAngle a3(35.4336, CAngleUnit::sexagesimalDeg()); // 35.72666 a2.switchUnit(CAngleUnit::deg()); QVERIFY2(a2.unitValueToInteger() == 270, qPrintable(QString("1.5Pi should be 270deg, not %1 deg").arg(a2.unitValueToInteger())));