From 92c9b81683421c3f519ffabeaadbe8ba718763b4 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 29 Apr 2013 16:39:09 +0100 Subject: [PATCH 1/6] combined case-sensitive folders Logging and logging, now we just have logging --- samples/Logging/main.cpp | 20 ----------------- samples/Logging/sample_logging.pro | 25 --------------------- samples/{Logging => logging}/CMakeLists.txt | 0 3 files changed, 45 deletions(-) delete mode 100644 samples/Logging/main.cpp delete mode 100644 samples/Logging/sample_logging.pro rename samples/{Logging => logging}/CMakeLists.txt (100%) diff --git a/samples/Logging/main.cpp b/samples/Logging/main.cpp deleted file mode 100644 index 1ad1a607a..000000000 --- a/samples/Logging/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include "blackmisc/debug.h" -#include "blackmisc/context.h" -#include -#include - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - BlackMisc::CApplicationContext myApplicationContext; - - BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug()); - - bAppInfo << "This is a Info log message"; - bAppWarning << "This is a bWarning log message"; - bAppError << "This is a bError log message"; - bAppDebug << "This is a bDebug log message"; - - return a.exec(); -} diff --git a/samples/Logging/sample_logging.pro b/samples/Logging/sample_logging.pro deleted file mode 100644 index d22de1cdf..000000000 --- a/samples/Logging/sample_logging.pro +++ /dev/null @@ -1,25 +0,0 @@ -QT += core -QT -= gui - -TARGET = sample_logging -TEMPLATE = app - -CONFIG += console -CONFIG -= app_bundle - -DEPENDPATH += . ../../src -INCLUDEPATH += . ../../src - -SOURCES += *.cpp - -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} - -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} - -DESTDIR = ../../bin diff --git a/samples/Logging/CMakeLists.txt b/samples/logging/CMakeLists.txt similarity index 100% rename from samples/Logging/CMakeLists.txt rename to samples/logging/CMakeLists.txt From 3c2b894c93697aa86fb49abe2e225710443cabcd Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 29 Apr 2013 23:14:42 +0100 Subject: [PATCH 2/6] fixed qmake files to support GNU make _and_ MSVC (discussed in #34) --- .../sample_quantities_avionics.pro | 13 ++++------- .../blackmiscvectorgeo/sample_vector_geo.pro | 22 +++++-------------- samples/com_client/sample_com_client.pro | 14 +++++------- samples/com_server/sample_com_server.pro | 11 +++------- samples/config/sample_config.pro | 14 +++++------- samples/interpolator/sample_interpolator.pro | 21 ++++++++---------- samples/logging/sample_logging.pro | 14 +++++------- samples/plugin/sample_plugin.pro | 14 +++++------- samples/pluginmgr/sample_pluginmgr.pro | 20 +++++++---------- src/blackbox/blackbox.pro | 11 +++------- src/blackd/blackd.pro | 21 ++++++------------ tests/blackcore/test_blackcore.pro | 19 +++++----------- tests/blackmisc/test_blackmisc.pro | 13 ++++------- 13 files changed, 73 insertions(+), 134 deletions(-) diff --git a/samples/blackmiscquantities/sample_quantities_avionics.pro b/samples/blackmiscquantities/sample_quantities_avionics.pro index 59cf6ab98..2e9e95d87 100644 --- a/samples/blackmiscquantities/sample_quantities_avionics.pro +++ b/samples/blackmiscquantities/sample_quantities_avionics.pro @@ -7,18 +7,13 @@ TEMPLATE = app CONFIG += console CONFIG -= app_bundle -DEPENDPATH += . ../../src/blackmisc +DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} +LIBS += -L../../lib -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin diff --git a/samples/blackmiscvectorgeo/sample_vector_geo.pro b/samples/blackmiscvectorgeo/sample_vector_geo.pro index 94e455f70..a44bebc4a 100644 --- a/samples/blackmiscvectorgeo/sample_vector_geo.pro +++ b/samples/blackmiscvectorgeo/sample_vector_geo.pro @@ -9,24 +9,12 @@ TEMPLATE = app DEPENDPATH += . ../../src INCLUDEPATH += . ../../src -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} +LIBS += -L../../lib -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin -SOURCES += main.cpp \ - samplesvectormatrix.cpp \ - samplesgeo.cpp \ - samplesgeodetictoecef.cpp - -HEADERS += \ - samplesvectormatrix.h \ - samplesgeo.h \ - samplesgeodetictoecef.h +SOURCES += *.cpp +HEADERS += *.h diff --git a/samples/com_client/sample_com_client.pro b/samples/com_client/sample_com_client.pro index 4b9007501..61b68e378 100644 --- a/samples/com_client/sample_com_client.pro +++ b/samples/com_client/sample_com_client.pro @@ -14,14 +14,12 @@ INCLUDEPATH += . ../../src SOURCES += *.cpp HEADERS += *.h -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} +LIBS += -L../../lib -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin + + + diff --git a/samples/com_server/sample_com_server.pro b/samples/com_server/sample_com_server.pro index 21da67c03..e6d61c03d 100644 --- a/samples/com_server/sample_com_server.pro +++ b/samples/com_server/sample_com_server.pro @@ -13,15 +13,10 @@ INCLUDEPATH += . ../../src SOURCES += *.cpp HEADERS += *.h -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} +LIBS += -L../../lib -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin diff --git a/samples/config/sample_config.pro b/samples/config/sample_config.pro index 18906e263..801d9f071 100644 --- a/samples/config/sample_config.pro +++ b/samples/config/sample_config.pro @@ -9,14 +9,12 @@ INCLUDEPATH += . ../../src SOURCES += *.cpp -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} +LIBS += -L../../lib -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin + + + diff --git a/samples/interpolator/sample_interpolator.pro b/samples/interpolator/sample_interpolator.pro index 13a77d8cc..aa2fea407 100644 --- a/samples/interpolator/sample_interpolator.pro +++ b/samples/interpolator/sample_interpolator.pro @@ -6,22 +6,19 @@ CONFIG -= app_bundle TEMPLATE = app +CONFIG += console +CONFIG -= app_bundle + DEPENDPATH += . ../../src INCLUDEPATH += . ../../src + SOURCES += *.cpp -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - PRE_TARGETDEPS += ../../lib/blackcore.lib - LIBS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackcore.lib -} +LIBS += -L../../lib -lblackcore -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - PRE_TARGETDEPS += ../../lib/libblackcore.a - LIBS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackcore.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ + ../../lib/blackcore.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ + ../../lib/libblackcore.a DESTDIR = ../../bin diff --git a/samples/logging/sample_logging.pro b/samples/logging/sample_logging.pro index d22de1cdf..b262a6322 100644 --- a/samples/logging/sample_logging.pro +++ b/samples/logging/sample_logging.pro @@ -12,14 +12,12 @@ INCLUDEPATH += . ../../src SOURCES += *.cpp -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} +LIBS += -L../../lib -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin + + + diff --git a/samples/plugin/sample_plugin.pro b/samples/plugin/sample_plugin.pro index 354f9b794..c01de703c 100644 --- a/samples/plugin/sample_plugin.pro +++ b/samples/plugin/sample_plugin.pro @@ -10,14 +10,12 @@ INCLUDEPATH += . ../../src SOURCES += *.cpp -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} +LIBS += -L../../lib -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin + + + diff --git a/samples/pluginmgr/sample_pluginmgr.pro b/samples/pluginmgr/sample_pluginmgr.pro index 2a8c326fe..11700db9a 100644 --- a/samples/pluginmgr/sample_pluginmgr.pro +++ b/samples/pluginmgr/sample_pluginmgr.pro @@ -12,18 +12,14 @@ INCLUDEPATH += . ../../src SOURCES += *.cpp -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - PRE_TARGETDEPS += ../../lib/blackcore.lib - LIBS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackcore.lib -} +LIBS += -L../../lib -lblackcore -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - PRE_TARGETDEPS += ../../lib/libblackcore.a - LIBS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackcore.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ + ../../lib/blackcore.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ + ../../lib/libblackcore.a DESTDIR = ../../bin + + + diff --git a/src/blackbox/blackbox.pro b/src/blackbox/blackbox.pro index 58b6c3b3e..79dad5973 100644 --- a/src/blackbox/blackbox.pro +++ b/src/blackbox/blackbox.pro @@ -12,14 +12,9 @@ HEADERS += *.h FORMS += blackbox.ui dialog_connect.ui dialog_chat.ui -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} +LIBS += -L../../lib -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin diff --git a/src/blackd/blackd.pro b/src/blackd/blackd.pro index 640c71ede..7ac44a843 100644 --- a/src/blackd/blackd.pro +++ b/src/blackd/blackd.pro @@ -2,11 +2,11 @@ QT += core gui xml svg network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + TARGET = blackd TEMPLATE = app -DEPENDPATH += ../blackmisc ../blackcore - +DEPENDPATH += . .. INCLUDEPATH += .. SOURCES += *.cpp @@ -15,19 +15,12 @@ HEADERS += *.h FORMS += blackd.ui RESOURCES += blackd.qrc -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - PRE_TARGETDEPS += ../../lib/blackcore.lib - LIBS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackcore.lib -} +LIBS += -L../../lib -lblackcore -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - PRE_TARGETDEPS += ../../lib/libblackcore.a - LIBS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackcore.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ + ../../lib/blackcore.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ + ../../lib/libblackcore.a DESTDIR = ../../bin diff --git a/tests/blackcore/test_blackcore.pro b/tests/blackcore/test_blackcore.pro index aaf0bfcff..d4076c16a 100644 --- a/tests/blackcore/test_blackcore.pro +++ b/tests/blackcore/test_blackcore.pro @@ -6,24 +6,17 @@ TEMPLATE = app CONFIG += console CONFIG -= app_bundle -DEPENDPATH += . ../../src/blackmisc +DEPENDPATH += . ../../src INCLUDEPATH += . ../../src HEADERS += *.h SOURCES += *.cpp -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - PRE_TARGETDEPS += ../../lib/blackcore.lib - LIBS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackcore.lib -} +LIBS += -L../../lib -lblackcore -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - PRE_TARGETDEPS += ../../lib/libblackcore.a - LIBS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackcore.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \ + ../../lib/blackcore.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \ + ../../lib/libblackcore.a DESTDIR = ../../bin diff --git a/tests/blackmisc/test_blackmisc.pro b/tests/blackmisc/test_blackmisc.pro index 68427a185..dbbab21ba 100644 --- a/tests/blackmisc/test_blackmisc.pro +++ b/tests/blackmisc/test_blackmisc.pro @@ -6,20 +6,15 @@ TEMPLATE = app CONFIG += console CONFIG -= app_bundle -DEPENDPATH += . ../../src/blackmisc +DEPENDPATH += . ../../src INCLUDEPATH += . ../../src HEADERS += *.h SOURCES += *.cpp -win32-msvc* { - PRE_TARGETDEPS += ../../lib/blackmisc.lib - LIBS += ../../lib/blackmisc.lib -} +LIBS += -L../../lib -lblackmisc -!win32-msvc* { - PRE_TARGETDEPS += ../../lib/libblackmisc.a - LIBS += ../../lib/libblackmisc.a -} +win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib +else: PRE_TARGETDEPS += ../../lib/libblackmisc.a DESTDIR = ../../bin From 715e6e8340c1f34dc604eedbaaa1525bd58d0a7d Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 29 Apr 2013 23:28:41 +0100 Subject: [PATCH 3/6] fixed CMath::PI2() --- src/blackmisc/mathematics.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blackmisc/mathematics.h b/src/blackmisc/mathematics.h index 9105bd9f0..01fc9ebb7 100644 --- a/src/blackmisc/mathematics.h +++ b/src/blackmisc/mathematics.h @@ -86,7 +86,7 @@ public: */ static const double &PI2() { - static double pi2 = PI(); + static double pi2 = 2.0 * PI(); return pi2; } From 177efba563346445a05928d8989109e2409a02e3 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 29 Apr 2013 23:32:13 +0100 Subject: [PATCH 4/6] including qmath.h instead of math.h fixes problem with M_PI in MSVC --- src/blackmisc/pqunits.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/blackmisc/pqunits.h b/src/blackmisc/pqunits.h index a08328008..736ef86b8 100644 --- a/src/blackmisc/pqunits.h +++ b/src/blackmisc/pqunits.h @@ -5,8 +5,9 @@ #ifndef BLACKMISC_PQUNITS_H #define BLACKMISC_PQUNITS_H + #include "blackmisc/pqbase.h" -#include +#include // // Used with the template for quantities. This is the reason for From ba70a150e06e9b29f958a4e0e8c9c07250488f69 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 29 Apr 2013 23:45:30 +0100 Subject: [PATCH 5/6] fix for g++ 4.5.2: this is the correct way to overload @operator<<@ for QDebug and CLogMessage because they are flyweight objects --- src/blackmisc/basestreamstringifier.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/blackmisc/basestreamstringifier.h b/src/blackmisc/basestreamstringifier.h index 714062e6f..55e748afa 100644 --- a/src/blackmisc/basestreamstringifier.h +++ b/src/blackmisc/basestreamstringifier.h @@ -20,7 +20,7 @@ template class CBaseStreamStringifier * \param uc * \return */ - friend QDebug &operator<<(QDebug &debug, const UsingClass &uc) + friend QDebug operator<<(QDebug debug, const UsingClass &uc) { const CBaseStreamStringifier &s = uc; debug << s.stringForStreaming(); @@ -33,7 +33,7 @@ template class CBaseStreamStringifier * \param uc * \return */ - friend QNoDebug &operator<<(QNoDebug &nodebug, const UsingClass &uc) + friend QNoDebug operator<<(QNoDebug nodebug, const UsingClass &uc) { return nodebug; } @@ -57,7 +57,7 @@ template class CBaseStreamStringifier * \param uc * \return */ - friend CLogMessage &operator<<(CLogMessage &log, const UsingClass &uc) + friend CLogMessage operator<<(CLogMessage log, const UsingClass &uc) { const CBaseStreamStringifier &s = uc; log << s.stringForStreaming(); From a05b85135cc5f21f4840c8b7b597b8f4758203bf Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 30 Apr 2013 00:09:32 +0100 Subject: [PATCH 6/6] replaced "clone" with "derived" in CRTP (more usual, more flexible, more clear in its intent, and avoids copying the object twice on compilers that don't optimise return by value) --- src/blackmisc/mathmatrixbase.cpp | 2 +- src/blackmisc/mathmatrixbase.h | 31 ++++++++++++++++++---------- src/blackmisc/mathvector3dbase.h | 28 ++++++++++++++++--------- src/blackmisc/pqphysicalquantity.cpp | 8 +++---- src/blackmisc/pqphysicalquantity.h | 15 +++++++++++--- 5 files changed, 55 insertions(+), 29 deletions(-) diff --git a/src/blackmisc/mathmatrixbase.cpp b/src/blackmisc/mathmatrixbase.cpp index 9d28779ca..99a1dadd3 100644 --- a/src/blackmisc/mathmatrixbase.cpp +++ b/src/blackmisc/mathmatrixbase.cpp @@ -97,7 +97,7 @@ template ImplMatrix &CMatrixBasem_matrix(r, c) = CMath::roundEpsilon(this->m_matrix(r, c), 1E-10); } } - return static_cast(*this); + return *derived(); } /* diff --git a/src/blackmisc/mathmatrixbase.h b/src/blackmisc/mathmatrixbase.h index 2841a3385..8b3b6152b 100644 --- a/src/blackmisc/mathmatrixbase.h +++ b/src/blackmisc/mathmatrixbase.h @@ -32,12 +32,21 @@ protected: QString stringForConverter() const; /*! - * \brief Clone as conrete implementation + * \brief Easy access to derived class (CRTP template parameter) * \return */ - ImplMatrix clone() const + ImplMatrix const* derived() const { - return static_cast(*this); + return static_cast(this); + } + + /*! + * \brief Easy access to derived class (CRTP template parameter) + * \return + */ + ImplMatrix* derived() + { + return static_cast(this); } public: @@ -118,7 +127,7 @@ public: */ ImplMatrix operator *(double factor) const { - ImplMatrix m = this->clone(); + ImplMatrix m = *derived(); m *= factor; return m; } @@ -159,7 +168,7 @@ public: */ ImplMatrix operator /(double factor) const { - ImplMatrix m = this->clone(); + ImplMatrix m = *derived(); m /= factor; return m; } @@ -182,7 +191,7 @@ public: */ ImplMatrix operator +(const ImplMatrix &otherMatrix) const { - ImplMatrix m = this->clone(); + ImplMatrix m = *derived(); m += otherMatrix; return m; } @@ -205,7 +214,7 @@ public: */ ImplMatrix operator -(const ImplMatrix &otherMatrix) const { - ImplMatrix m = this->clone(); + ImplMatrix m = *derived(); m -= otherMatrix; return m; } @@ -225,8 +234,8 @@ public: */ bool isIdentityEpsilon() const { - ImplMatrix m = this->clone().round(); - return m.isIdentity(); + ImplMatrix m = *derived(); + return m.round().isIdentity(); } /*! @@ -260,8 +269,8 @@ public: */ bool isZeroEpsilon() const { - ImplMatrix m = this->clone().round(); - return m.isZero(); + ImplMatrix m = *derived(); + return m.round().isZero(); } /*! diff --git a/src/blackmisc/mathvector3dbase.h b/src/blackmisc/mathvector3dbase.h index 8183c325e..1fe7d6133 100644 --- a/src/blackmisc/mathvector3dbase.h +++ b/src/blackmisc/mathvector3dbase.h @@ -62,14 +62,22 @@ protected: virtual QString stringForConverter() const; /*! - * \brief Clone as concrete implementation + * \brief Easy access to derived class (CRTP template parameter) * \return */ - ImplVector clone() const + ImplVector const* derived() const { - return static_cast(*this); + return static_cast(this); } + /*! + * \brief Easy access to derived class (CRTP template parameter) + * \return + */ + ImplVector* derived() + { + return static_cast(this); + } public: @@ -198,7 +206,7 @@ public: */ ImplVector operator +(const ImplVector &otherVector) const { - ImplVector v = this->clone(); + ImplVector v = *derived(); v += otherVector; return v; } @@ -223,7 +231,7 @@ public: */ ImplVector operator -(const ImplVector &otherVector) const { - ImplVector v = this->clone(); + ImplVector v = *derived(); v -= otherVector; return v; } @@ -248,7 +256,7 @@ public: */ ImplVector operator *(const ImplVector &otherVector) const { - ImplVector v = this->clone(); + ImplVector v = *derived(); v *= otherVector; return v; } @@ -273,7 +281,7 @@ public: */ ImplVector operator *(double factor) const { - ImplVector v = this->clone(); + ImplVector v = *derived(); v *= factor; return v; } @@ -309,7 +317,7 @@ public: */ ImplVector operator /(double divisor) const { - ImplVector v = this->clone(); + ImplVector v = *derived(); v /= divisor; return v; } @@ -334,7 +342,7 @@ public: */ ImplVector operator /(const ImplVector &otherVector) const { - ImplVector v = this->clone(); + ImplVector v = *derived(); v /= otherVector; return v; } @@ -413,7 +421,7 @@ public: this->m_i = BlackMisc::Math::CMath::roundEpsilon(this->m_i, epsilon); this->m_j = BlackMisc::Math::CMath::roundEpsilon(this->m_j, epsilon); this->m_k = BlackMisc::Math::CMath::roundEpsilon(this->m_k, epsilon); - return static_cast(*this); + return *derived(); } }; diff --git a/src/blackmisc/pqphysicalquantity.cpp b/src/blackmisc/pqphysicalquantity.cpp index ff65846f8..937d782ef 100644 --- a/src/blackmisc/pqphysicalquantity.cpp +++ b/src/blackmisc/pqphysicalquantity.cpp @@ -190,7 +190,7 @@ template CPhysicalQuantity &CPhysicalQuantity PQ CPhysicalQuantity::operator -(const PQ &otherQuantity) const { - PQ minus = this->clone(); + PQ minus = *derived(); minus -= otherQuantity; return minus; } @@ -209,7 +209,7 @@ template CPhysicalQuantity &CPhysicalQuantity PQ CPhysicalQuantity::operator *(double multiply) const { - PQ times = this->clone(); + PQ times = *derived(); times *= multiply; return times; } @@ -228,7 +228,7 @@ template CPhysicalQuantity &CPhysicalQuantity PQ CPhysicalQuantity::operator /(double divide) const { - PQ div = this->clone(); + PQ div = *derived(); div /= divide; return div; } @@ -281,7 +281,7 @@ template PQ &CPhysicalQuantity::switchUnit(const MU this->m_unit = newUnit; this->setUnitValue(cf); } - return static_cast(*this); + return *derived(); } /* diff --git a/src/blackmisc/pqphysicalquantity.h b/src/blackmisc/pqphysicalquantity.h index 2314e0e48..053fcf829 100644 --- a/src/blackmisc/pqphysicalquantity.h +++ b/src/blackmisc/pqphysicalquantity.h @@ -60,12 +60,21 @@ protected: } /*! - * \brief Polymorphic clone as concrete class + * \brief Easy access to derived class (CRTP template parameter) * \return */ - PQ clone() const + PQ const* derived() const { - return static_cast(*this); + return static_cast(this); + } + + /*! + * \brief Easy access to derived class (CRTP template parameter) + * \return + */ + PQ* derived() + { + return static_cast(this); } /*!