From 349da3633b0d06bc82ad2e48ba1a45376d894f22 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Mon, 12 Aug 2019 22:39:14 +0100 Subject: [PATCH] Ref T709 Prevent instantiation of CXSwiftBusSettingsQtFree, to avoid slicing. - Constructors and destructor are protected. - Therefore destructor doesn't need to be virtual. - objectUpdated is pure virtual, so the class is abstract. - Both derived classes are declared final. --- src/blackmisc/simulation/settings/xswiftbussettings.h | 4 ++-- .../simulation/settings/xswiftbussettingsqtfree.cpp | 5 ----- .../simulation/settings/xswiftbussettingsqtfree.h | 9 +++++---- src/xswiftbus/settings.h | 7 ++++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/blackmisc/simulation/settings/xswiftbussettings.h b/src/blackmisc/simulation/settings/xswiftbussettings.h index ea8e7135c..e1faf97ea 100644 --- a/src/blackmisc/simulation/settings/xswiftbussettings.h +++ b/src/blackmisc/simulation/settings/xswiftbussettings.h @@ -27,7 +27,7 @@ namespace BlackMisc namespace Settings { //! XSwiftBus settings - class BLACKMISC_EXPORT CXSwiftBusSettings : + class BLACKMISC_EXPORT CXSwiftBusSettings final : public CValueObject, public CXSwiftBusSettingsQtFree, public ITimestampBased @@ -88,7 +88,7 @@ namespace BlackMisc protected: //! \copydoc CXSwiftBusSettingsQtFree::objectUpdated - virtual void objectUpdated() override; + virtual void objectUpdated() override final; private: BLACK_METACLASS( diff --git a/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.cpp b/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.cpp index a4e9b20b5..60c434975 100644 --- a/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.cpp +++ b/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.cpp @@ -147,11 +147,6 @@ namespace BlackMisc const milliseconds ms = duration_cast(system_clock::now().time_since_epoch()); m_msSinceEpochQtFree = static_cast(ms.count()); } - - void CXSwiftBusSettingsQtFree::objectUpdated() - { - // void - } } // ns } // ns } // ns diff --git a/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.h b/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.h index cccf88772..192ce57ee 100644 --- a/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.h +++ b/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.h @@ -24,16 +24,17 @@ namespace BlackMisc */ class CXSwiftBusSettingsQtFree { - public: + protected: //! Constructor. CXSwiftBusSettingsQtFree(); //! JSON Constructor. CXSwiftBusSettingsQtFree(const std::string &json); - //! Dtor - virtual ~CXSwiftBusSettingsQtFree() {} + //! Destructor. + ~CXSwiftBusSettingsQtFree() = default; + public: //! DBus server const std::string &getDBusServerAddress() const { return m_dBusServerAddress; } @@ -112,7 +113,7 @@ namespace BlackMisc //! @} //! Object has been updated - virtual void objectUpdated(); + virtual void objectUpdated() = 0; std::string m_dBusServerAddress { "tcp:host=127.0.0.1,port=45001" }; //!< DBus server std::string m_nightTextureMode { "auto" }; //!< night texture mode diff --git a/src/xswiftbus/settings.h b/src/xswiftbus/settings.h index ec841d7f7..7e4e03f26 100644 --- a/src/xswiftbus/settings.h +++ b/src/xswiftbus/settings.h @@ -18,7 +18,7 @@ namespace XSwiftBus /*! * XSwiftBus/swift side settings class, JSON capable, shared among all services */ - class CSettings : public BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree + class CSettings final : public BlackMisc::Simulation::Settings::CXSwiftBusSettingsQtFree { public: //! Constructor. @@ -27,8 +27,9 @@ namespace XSwiftBus //! JSON constructor CSettings(const std::string &json); - //! Destructor; - virtual ~CSettings() {} + protected: + //! \copydoc CXSwiftBusSettingsQtFree::objectUpdated + virtual void objectUpdated() override final {} }; //! Something owning the settings