From 08b10cd28762c5716f03476ca33dc8d8664eed47 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 15 Nov 2023 17:12:50 +0100 Subject: [PATCH] fix cppcoreguidelines-* * cppcoreguidelines-init-variables * cppcoreguidelines-c-copy-assignment-signature * cppcoreguidelines-macro-usage * cppcoreguidelines-non-private-member-variables-in-classes * cppcoreguidelines-pro-type-member-init * cppcoreguidelines-slicing * cppcoreguidelines-special-member-functions * cppcoreguidelines-virtual-class-destructor --- src/Base/BaseClass.h | 2 + src/Base/Console.cpp | 8 +- src/Base/Console.h | 21 ++++- src/Base/Exception.cpp | 36 ++++++-- src/Base/Exception.h | 137 +++++++++++++++++++++++++++++- src/Base/ExceptionFactory.h | 2 - src/Base/Factory.h | 23 +++-- src/Base/FileInfo.cpp | 4 +- src/Base/FileTemplate.cpp | 7 ++ src/Base/FileTemplate.h | 4 + src/Base/GeometryPyCXX.cpp | 38 ++++----- src/Base/GeometryPyCXX.h | 3 +- src/Base/InputSource.h | 4 + src/Base/Interpreter.cpp | 2 +- src/Base/Interpreter.h | 29 ++++++- src/Base/Matrix.cpp | 5 +- src/Base/Observer.h | 7 +- src/Base/Parameter.cpp | 17 ++-- src/Base/Parameter.h | 21 ++++- src/Base/ParameterPy.cpp | 36 ++++---- src/Base/PyObjectBase.h | 2 + src/Base/Rotation.cpp | 33 ------- src/Base/Rotation.h | 7 +- src/Base/Sequencer.h | 8 +- src/Base/TimeInfo.cpp | 4 +- src/Base/TimeInfo.h | 17 ++-- src/Base/Tools.h | 5 ++ src/Base/Tools2D.cpp | 3 +- src/Base/Unit.cpp | 21 +---- src/Base/Unit.h | 8 +- src/Base/UnitsSchema.h | 5 ++ src/Base/UnitsSchemaImperial1.cpp | 2 +- src/Base/Uuid.h | 2 + src/Base/ViewProj.h | 6 +- src/Base/Writer.h | 16 ++++ src/Base/XMLTools.h | 7 +- src/Base/ZipHeader.h | 2 - src/FCGlobal.h | 30 +++++++ 38 files changed, 418 insertions(+), 166 deletions(-) diff --git a/src/Base/BaseClass.h b/src/Base/BaseClass.h index ff5b578427..d1adc97602 100644 --- a/src/Base/BaseClass.h +++ b/src/Base/BaseClass.h @@ -30,6 +30,7 @@ using PyObject = struct _object; +// NOLINTBEGIN(cppcoreguidelines-macro-usage) /// define for subclassing Base::BaseClass #define TYPESYSTEM_HEADER() \ public: \ @@ -129,6 +130,7 @@ private: { \ initSubclass(_class_::classTypeId, #_class_, #_parentclass_, &(_class_::create)); \ } +// NOLINTEND(cppcoreguidelines-macro-usage) namespace Base { diff --git a/src/Base/Console.cpp b/src/Base/Console.cpp index 0d031ce73e..450864855a 100644 --- a/src/Base/Console.cpp +++ b/src/Base/Console.cpp @@ -68,7 +68,6 @@ public: , notifier(notifier) , msg(msg) {} - ~ConsoleEvent() override = default; }; class ConsoleOutput: public QObject // clazy:exclude=missing-qobject-macro @@ -139,13 +138,10 @@ public: } private: - ConsoleOutput() = default; - ~ConsoleOutput() override = default; - - static ConsoleOutput* instance; + static ConsoleOutput* instance; // NOLINT }; -ConsoleOutput* ConsoleOutput::instance = nullptr; +ConsoleOutput* ConsoleOutput::instance = nullptr; // NOLINT } // namespace Base diff --git a/src/Base/Console.h b/src/Base/Console.h index 4cc7a53f2a..ab2a2b3616 100644 --- a/src/Base/Console.h +++ b/src/Base/Console.h @@ -550,6 +550,10 @@ class BaseExport ILogger { public: ILogger() = default; + ILogger(const ILogger&) = delete; + ILogger(ILogger&&) = delete; + ILogger& operator=(const ILogger&) = delete; + ILogger& operator=(ILogger&&) = delete; virtual ~ILogger() = 0; /** Used to send a Log message at the given level. @@ -841,7 +845,7 @@ public: inline constexpr FreeCAD_ConsoleMsgType getConsoleMsg(Base::LogStyle style); -protected: +private: // python exports goes here +++++++++++++++++++++++++++++++++++++++++++ // static python wrapper of the exported functions static PyObject* sPyLog(PyObject* self, PyObject* args); @@ -867,7 +871,13 @@ protected: // Singleton! ConsoleSingleton(); - virtual ~ConsoleSingleton(); + ~ConsoleSingleton(); + +public: + ConsoleSingleton(const ConsoleSingleton&) = delete; + ConsoleSingleton(ConsoleSingleton&&) = delete; + ConsoleSingleton& operator=(const ConsoleSingleton&) = delete; + ConsoleSingleton& operator=(ConsoleSingleton&&) = delete; private: void postEvent(ConsoleSingleton::FreeCAD_ConsoleMsgType type, @@ -883,7 +893,7 @@ private: // singleton static void Destruct(); - static ConsoleSingleton* _pcSingleton; + static ConsoleSingleton* _pcSingleton; // NOLINT // observer list std::set _aclObservers; @@ -929,6 +939,11 @@ public: { Console().EnableRefresh(true); } + + ConsoleRefreshDisabler(const ConsoleRefreshDisabler&) = delete; + ConsoleRefreshDisabler(ConsoleRefreshDisabler&&) = delete; + ConsoleRefreshDisabler& operator=(const ConsoleRefreshDisabler&) = delete; + ConsoleRefreshDisabler& operator=(ConsoleRefreshDisabler&&) = delete; }; diff --git a/src/Base/Exception.cpp b/src/Base/Exception.cpp index b271d7aa96..c2e419a73f 100644 --- a/src/Base/Exception.cpp +++ b/src/Base/Exception.cpp @@ -47,6 +47,8 @@ Exception::Exception() Exception::Exception(const Exception& inst) = default; +Exception::Exception(Exception&& inst) noexcept = default; + Exception::Exception(const char* sMessage) : _sErrMsg(sMessage) , _line(0) @@ -67,6 +69,17 @@ Exception& Exception::operator=(const Exception& inst) _file = inst._file; _line = inst._line; _function = inst._function; + _isTranslatable = inst._isTranslatable; + return *this; +} + +Exception& Exception::operator=(Exception&& inst) noexcept +{ + _sErrMsg = std::move(inst._sErrMsg); + _file = std::move(inst._file); + _line = inst._line; + _function = std::move(inst._function); + _isTranslatable = inst._isTranslatable; return *this; } @@ -289,14 +302,6 @@ std::string FileException::getFileName() const return file.fileName(); } -FileException& FileException::operator=(const FileException& inst) -{ - Exception::operator=(inst); - file = inst.file; - _sErrMsgAndFileName = inst._sErrMsgAndFileName; - return *this; -} - const char* FileException::what() const noexcept { return _sErrMsgAndFileName.c_str(); @@ -402,12 +407,27 @@ MemoryException::MemoryException(const MemoryException& inst) #endif {} +MemoryException::MemoryException(MemoryException&& inst) noexcept +#if defined(__GNUC__) + : std::bad_alloc() + , Exception(inst) +#else + : Exception(inst) +#endif +{} + MemoryException& MemoryException::operator=(const MemoryException& inst) { Exception::operator=(inst); return *this; } +MemoryException& MemoryException::operator=(MemoryException&& inst) noexcept +{ + Exception::operator=(inst); + return *this; +} + #if defined(__GNUC__) const char* MemoryException::what() const noexcept { diff --git a/src/Base/Exception.h b/src/Base/Exception.h index b5663fcca8..6430ec0990 100644 --- a/src/Base/Exception.h +++ b/src/Base/Exception.h @@ -199,6 +199,7 @@ public: ~Exception() noexcept override = default; Exception& operator=(const Exception& inst); + Exception& operator=(Exception&& inst) noexcept; virtual const char* what() const noexcept; @@ -250,6 +251,7 @@ protected: Exception(const std::string& sMessage); Exception(); Exception(const Exception& inst); + Exception(Exception&& inst) noexcept; protected: std::string _sErrMsg; @@ -274,9 +276,14 @@ public: AbortException(const char* sMessage); /// Construction AbortException(); + AbortException(const AbortException&) = default; + AbortException(AbortException&&) = default; /// Destruction ~AbortException() noexcept override = default; + AbortException& operator=(const AbortException&) = default; + AbortException& operator=(AbortException&&) = default; + /// Description of the exception const char* what() const noexcept override; /// returns the corresponding python exception type @@ -294,9 +301,14 @@ public: XMLBaseException(); XMLBaseException(const char* sMessage); XMLBaseException(const std::string& sMessage); + XMLBaseException(const XMLBaseException&) = default; + XMLBaseException(XMLBaseException&&) = default; /// Destruction ~XMLBaseException() noexcept override = default; + XMLBaseException& operator=(const XMLBaseException&) = default; + XMLBaseException& operator=(XMLBaseException&&) = default; + PyObject* getPyExceptionType() const override; }; @@ -313,9 +325,14 @@ public: XMLParseException(const std::string& sMessage); /// Construction XMLParseException(); + XMLParseException(const XMLParseException&) = default; + XMLParseException(XMLParseException&&) = default; /// Destruction ~XMLParseException() noexcept override = default; + XMLParseException& operator=(const XMLParseException&) = default; + XMLParseException& operator=(XMLParseException&&) = default; + /// Description of the exception const char* what() const noexcept override; PyObject* getPyExceptionType() const override; @@ -334,9 +351,14 @@ public: XMLAttributeError(const std::string& sMessage); /// Construction XMLAttributeError(); + XMLAttributeError(const XMLAttributeError&) = default; + XMLAttributeError(XMLAttributeError&&) = default; /// Destruction ~XMLAttributeError() noexcept override = default; + XMLAttributeError& operator=(const XMLAttributeError&) = default; + XMLAttributeError& operator=(XMLAttributeError&&) = default; + /// Description of the exception const char* what() const noexcept override; PyObject* getPyExceptionType() const override; @@ -355,12 +377,14 @@ public: FileException(const char* sMessage, const FileInfo& File); /// standard construction FileException(); - /// Construction FileException(const FileException&) = default; + FileException(FileException&&) = default; /// Destruction ~FileException() noexcept override = default; /// Assignment operator - FileException& operator=(const FileException& inst); + FileException& operator=(const FileException&) = default; + FileException& operator=(FileException&&) = default; + /// Description of the exception const char* what() const noexcept override; /// Report generation @@ -394,8 +418,13 @@ public: FileSystemError(); FileSystemError(const char* sMessage); FileSystemError(const std::string& sMessage); + FileSystemError(const FileSystemError&) = default; + FileSystemError(FileSystemError&&) = default; /// Destruction ~FileSystemError() noexcept override = default; + FileSystemError& operator=(const FileSystemError&) = default; + FileSystemError& operator=(FileSystemError&&) = default; + PyObject* getPyExceptionType() const override; }; @@ -410,8 +439,12 @@ public: BadFormatError(); BadFormatError(const char* sMessage); BadFormatError(const std::string& sMessage); + BadFormatError(const BadFormatError&) = default; + BadFormatError(BadFormatError&&) = default; /// Destruction ~BadFormatError() noexcept override = default; + BadFormatError& operator=(const BadFormatError&) = default; + BadFormatError& operator=(BadFormatError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -431,10 +464,12 @@ public: MemoryException(); /// Construction MemoryException(const MemoryException& inst); + MemoryException(MemoryException&& inst) noexcept; /// Destruction ~MemoryException() noexcept override = default; /// Assignment operator MemoryException& operator=(const MemoryException& inst); + MemoryException& operator=(MemoryException&& inst) noexcept; #if defined(__GNUC__) /// Description of the exception const char* what() const noexcept override; @@ -453,8 +488,12 @@ public: AccessViolation(); AccessViolation(const char* sMessage); AccessViolation(const std::string& sMessage); + AccessViolation(const AccessViolation&) = default; + AccessViolation(AccessViolation&&) = default; /// Destruction ~AccessViolation() noexcept override = default; + AccessViolation& operator=(const AccessViolation&) = default; + AccessViolation& operator=(AccessViolation&&) = default; PyObject* getPyExceptionType() const override; }; @@ -470,8 +509,12 @@ public: /// Construction AbnormalProgramTermination(const char* sMessage); AbnormalProgramTermination(const std::string& sMessage); + AbnormalProgramTermination(const AbnormalProgramTermination&) = default; + AbnormalProgramTermination(AbnormalProgramTermination&&) = default; /// Destruction ~AbnormalProgramTermination() noexcept override = default; + AbnormalProgramTermination& operator=(const AbnormalProgramTermination&) = default; + AbnormalProgramTermination& operator=(AbnormalProgramTermination&&) = default; PyObject* getPyExceptionType() const override; }; @@ -486,8 +529,12 @@ public: UnknownProgramOption(); UnknownProgramOption(const char* sMessage); UnknownProgramOption(const std::string& sMessage); + UnknownProgramOption(const UnknownProgramOption&) = default; + UnknownProgramOption(UnknownProgramOption&&) = default; /// Destruction ~UnknownProgramOption() noexcept override = default; + UnknownProgramOption& operator=(const UnknownProgramOption&) = default; + UnknownProgramOption& operator=(UnknownProgramOption&&) = default; PyObject* getPyExceptionType() const override; }; @@ -502,9 +549,13 @@ public: ProgramInformation(); ProgramInformation(const char* sMessage); ProgramInformation(const std::string& sMessage); + ProgramInformation(const ProgramInformation&) = default; + ProgramInformation(ProgramInformation&&) = default; /// Destruction ~ProgramInformation() noexcept override = default; + ProgramInformation& operator=(const ProgramInformation&) = default; + ProgramInformation& operator=(ProgramInformation&&) = default; }; /** @@ -518,8 +569,12 @@ public: TypeError(); TypeError(const char* sMessage); TypeError(const std::string& sMessage); + TypeError(const TypeError&) = default; + TypeError(TypeError&&) = default; /// Destruction ~TypeError() noexcept override = default; + TypeError& operator=(const TypeError&) = default; + TypeError& operator=(TypeError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -534,8 +589,12 @@ public: ValueError(); ValueError(const char* sMessage); ValueError(const std::string& sMessage); + ValueError(const ValueError&) = default; + ValueError(ValueError&&) = default; /// Destruction ~ValueError() noexcept override = default; + ValueError& operator=(const ValueError&) = default; + ValueError& operator=(ValueError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -550,8 +609,12 @@ public: IndexError(); IndexError(const char* sMessage); IndexError(const std::string& sMessage); + IndexError(const IndexError&) = default; + IndexError(IndexError&&) = default; /// Destruction ~IndexError() noexcept override = default; + IndexError& operator=(const IndexError&) = default; + IndexError& operator=(IndexError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -562,8 +625,12 @@ public: NameError(); NameError(const char* sMessage); NameError(const std::string& sMessage); + NameError(const NameError&) = default; + NameError(NameError&&) = default; /// Destruction ~NameError() noexcept override = default; + NameError& operator=(const NameError&) = default; + NameError& operator=(NameError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -574,8 +641,12 @@ public: ImportError(); ImportError(const char* sMessage); ImportError(const std::string& sMessage); + ImportError(const ImportError&) = default; + ImportError(ImportError&&) = default; /// Destruction ~ImportError() noexcept override = default; + ImportError& operator=(const ImportError&) = default; + ImportError& operator=(ImportError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -590,8 +661,12 @@ public: AttributeError(); AttributeError(const char* sMessage); AttributeError(const std::string& sMessage); + AttributeError(const AttributeError&) = default; + AttributeError(AttributeError&&) = default; /// Destruction ~AttributeError() noexcept override = default; + AttributeError& operator=(const AttributeError&) = default; + AttributeError& operator=(AttributeError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -606,8 +681,12 @@ public: RuntimeError(); RuntimeError(const char* sMessage); RuntimeError(const std::string& sMessage); + RuntimeError(const RuntimeError&) = default; + RuntimeError(RuntimeError&&) = default; /// Destruction ~RuntimeError() noexcept override = default; + RuntimeError& operator=(const RuntimeError&) = default; + RuntimeError& operator=(RuntimeError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -622,8 +701,12 @@ public: BadGraphError(); BadGraphError(const char* sMessage); BadGraphError(const std::string& sMessage); + BadGraphError(const BadGraphError&) = default; + BadGraphError(BadGraphError&&) = default; /// Destruction ~BadGraphError() noexcept override = default; + BadGraphError& operator=(const BadGraphError&) = default; + BadGraphError& operator=(BadGraphError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -638,8 +721,12 @@ public: NotImplementedError(); NotImplementedError(const char* sMessage); NotImplementedError(const std::string& sMessage); + NotImplementedError(const NotImplementedError&) = default; + NotImplementedError(NotImplementedError&&) = default; /// Destruction ~NotImplementedError() noexcept override = default; + NotImplementedError& operator=(const NotImplementedError&) = default; + NotImplementedError& operator=(NotImplementedError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -654,8 +741,12 @@ public: ZeroDivisionError(); ZeroDivisionError(const char* sMessage); ZeroDivisionError(const std::string& sMessage); + ZeroDivisionError(const ZeroDivisionError&) = default; + ZeroDivisionError(ZeroDivisionError&&) = default; /// Destruction ~ZeroDivisionError() noexcept override = default; + ZeroDivisionError& operator=(const ZeroDivisionError&) = default; + ZeroDivisionError& operator=(ZeroDivisionError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -670,8 +761,12 @@ public: ReferenceError(); ReferenceError(const char* sMessage); ReferenceError(const std::string& sMessage); + ReferenceError(const ReferenceError&) = default; + ReferenceError(ReferenceError&&) = default; /// Destruction ~ReferenceError() noexcept override = default; + ReferenceError& operator=(const ReferenceError&) = default; + ReferenceError& operator=(ReferenceError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -687,8 +782,12 @@ public: ExpressionError(); ExpressionError(const char* sMessage); ExpressionError(const std::string& sMessage); + ExpressionError(const ExpressionError&) = default; + ExpressionError(ExpressionError&&) = default; /// Destruction ~ExpressionError() noexcept override = default; + ExpressionError& operator=(const ExpressionError&) = default; + ExpressionError& operator=(ExpressionError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -703,8 +802,12 @@ public: ParserError(); ParserError(const char* sMessage); ParserError(const std::string& sMessage); + ParserError(const ParserError&) = default; + ParserError(ParserError&&) = default; /// Destruction ~ParserError() noexcept override = default; + ParserError& operator=(const ParserError&) = default; + ParserError& operator=(ParserError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -719,8 +822,12 @@ public: UnicodeError(); UnicodeError(const char* sMessage); UnicodeError(const std::string& sMessage); + UnicodeError(const UnicodeError&) = default; + UnicodeError(UnicodeError&&) = default; /// Destruction ~UnicodeError() noexcept override = default; + UnicodeError& operator=(const UnicodeError&) = default; + UnicodeError& operator=(UnicodeError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -735,8 +842,12 @@ public: OverflowError(); OverflowError(const char* sMessage); OverflowError(const std::string& sMessage); + OverflowError(const OverflowError&) = default; + OverflowError(OverflowError&&) = default; /// Destruction ~OverflowError() noexcept override = default; + OverflowError& operator=(const OverflowError&) = default; + OverflowError& operator=(OverflowError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -751,8 +862,12 @@ public: UnderflowError(); UnderflowError(const char* sMessage); UnderflowError(const std::string& sMessage); + UnderflowError(const UnderflowError&) = default; + UnderflowError(UnderflowError&&) = default; /// Destruction ~UnderflowError() noexcept override = default; + UnderflowError& operator=(const UnderflowError&) = default; + UnderflowError& operator=(UnderflowError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -767,8 +882,12 @@ public: UnitsMismatchError(); UnitsMismatchError(const char* sMessage); UnitsMismatchError(const std::string& sMessage); + UnitsMismatchError(const UnitsMismatchError&) = default; + UnitsMismatchError(UnitsMismatchError&&) = default; /// Destruction ~UnitsMismatchError() noexcept override = default; + UnitsMismatchError& operator=(const UnitsMismatchError&) = default; + UnitsMismatchError& operator=(UnitsMismatchError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -784,8 +903,12 @@ public: CADKernelError(); CADKernelError(const char* sMessage); CADKernelError(const std::string& sMessage); + CADKernelError(const CADKernelError&) = default; + CADKernelError(CADKernelError&&) = default; /// Destruction ~CADKernelError() noexcept override = default; + CADKernelError& operator=(const CADKernelError&) = default; + CADKernelError& operator=(CADKernelError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -803,8 +926,12 @@ public: RestoreError(); RestoreError(const char* sMessage); RestoreError(const std::string& sMessage); + RestoreError(const RestoreError&) = default; + RestoreError(RestoreError&&) = default; /// Destruction ~RestoreError() noexcept override = default; + RestoreError& operator=(const RestoreError&) = default; + RestoreError& operator=(RestoreError&&) = default; PyObject* getPyExceptionType() const override; }; @@ -868,8 +995,10 @@ private: static void throw_signal(int signum); private: - struct sigaction new_action, old_action; - bool ok; + // clang-format off + struct sigaction new_action {}, old_action {}; + bool ok {false}; + // clang-format on }; #endif diff --git a/src/Base/ExceptionFactory.h b/src/Base/ExceptionFactory.h index 76d12aa825..6cb32448df 100644 --- a/src/Base/ExceptionFactory.h +++ b/src/Base/ExceptionFactory.h @@ -75,8 +75,6 @@ public: ExceptionFactory::Instance().AddProducer(typeid(CLASS).name(), this); } - ~ExceptionProducer() override = default; - void raiseException(PyObject* pydict) const override { CLASS cls; diff --git a/src/Base/Factory.h b/src/Base/Factory.h index 0900569b3f..9193c355aa 100644 --- a/src/Base/Factory.h +++ b/src/Base/Factory.h @@ -44,6 +44,8 @@ public: virtual ~AbstractProducer() = default; /// overwritten by a concrete producer to produce the needed object virtual void* Produce() const = 0; + + FC_DISABLE_COPY_MOVE(AbstractProducer) }; @@ -62,22 +64,25 @@ public: bool CanProduce(const char* sClassName) const; /// returns a list of all registered producer std::list CanProduce() const; + /// destruction + virtual ~Factory(); + + FC_DISABLE_COPY_MOVE(Factory) protected: /// produce a class with the given name void* Produce(const char* sClassName) const; - std::map _mpcProducers; /// construction Factory() = default; - /// destruction - virtual ~Factory(); + + std::map _mpcProducers; }; // -------------------------------------------------------------------- /** The ScriptFactorySingleton singleton */ -class BaseExport ScriptFactorySingleton: public Factory +class BaseExport ScriptFactorySingleton: public Factory // NOLINT { public: static ScriptFactorySingleton& Instance(); @@ -85,9 +90,12 @@ public: const char* ProduceScript(const char* sScriptName) const; -private: - static ScriptFactorySingleton* _pcSingleton; + FC_DISABLE_COPY_MOVE(ScriptFactorySingleton) +private: + static ScriptFactorySingleton* _pcSingleton; // NOLINT + +protected: ScriptFactorySingleton() = default; ~ScriptFactorySingleton() override = default; }; @@ -118,9 +126,12 @@ public: /// Produce an instance void* Produce() const override { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) return const_cast(mScript); } + FC_DISABLE_COPY_MOVE(ScriptProducer) + private: const char* mScript; }; diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index 0dea57a97e..ee70cb4f9a 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -401,7 +401,9 @@ bool FileInfo::isFile() const } return ok; #else - struct stat st; + // clang-format off + struct stat st {}; + // clang-format on if (stat(FileName.c_str(), &st) != 0) { return false; } diff --git a/src/Base/FileTemplate.cpp b/src/Base/FileTemplate.cpp index 09da6cf4ff..6533bd7d18 100644 --- a/src/Base/FileTemplate.cpp +++ b/src/Base/FileTemplate.cpp @@ -38,12 +38,19 @@ using namespace Base; */ ClassTemplate::ClassTemplate() = default; +ClassTemplate::ClassTemplate(const ClassTemplate&) = default; + +ClassTemplate::ClassTemplate(ClassTemplate&&) = default; + /** * A destructor. * A more elaborate description of the destructor. */ ClassTemplate::~ClassTemplate() = default; +ClassTemplate& ClassTemplate::operator=(const ClassTemplate&) = default; + +ClassTemplate& ClassTemplate::operator=(ClassTemplate&&) = default; //************************************************************************** // separator for other implementation aspects diff --git a/src/Base/FileTemplate.h b/src/Base/FileTemplate.h index f509b8cae9..e2b61435d8 100644 --- a/src/Base/FileTemplate.h +++ b/src/Base/FileTemplate.h @@ -86,9 +86,13 @@ class BaseExport ClassTemplate public: /// Construction ClassTemplate(); + ClassTemplate(const ClassTemplate&); + ClassTemplate(ClassTemplate&&); /// Destruction virtual ~ClassTemplate(); + ClassTemplate& operator=(const ClassTemplate&); + ClassTemplate& operator=(ClassTemplate&&); int testMe(int a, const char* s); /** diff --git a/src/Base/GeometryPyCXX.cpp b/src/Base/GeometryPyCXX.cpp index 89fbe67c9c..dc96d98314 100644 --- a/src/Base/GeometryPyCXX.cpp +++ b/src/Base/GeometryPyCXX.cpp @@ -148,7 +148,7 @@ Py::Object Vector2dPy::repr() str << static_cast(vx.repr()) << ", " << static_cast(vy.repr()); str << ")"; - return Py::String(str.str()); + return Py::String(str.str()); // NOLINT } Py::Object Vector2dPy::getattro(const Py::String& name_) @@ -162,13 +162,13 @@ Py::Object Vector2dPy::getattro(const Py::String& name_) Py::Dict attr; attr.setItem(Py::String("x"), Py::Float(v.x)); attr.setItem(Py::String("y"), Py::Float(v.y)); - return attr; + return attr; // NOLINT } if (name == "x") { - return Py::Float(v.x); + return Py::Float(v.x); // NOLINT } if (name == "y") { - return Py::Float(v.y); + return Py::Float(v.y); // NOLINT } return genericGetAttro(name_); @@ -192,17 +192,17 @@ int Vector2dPy::setattro(const Py::String& name_, const Py::Object& value) Py::Object Vector2dPy::number_negative() { - return create(-v.x, -v.y); + return create(-v.x, -v.y); // NOLINT } Py::Object Vector2dPy::number_positive() { - return create(v.x, v.y); + return create(v.x, v.y); // NOLINT } Py::Object Vector2dPy::number_absolute() { - return create(fabs(v.x), fabs(v.y)); + return create(fabs(v.x), fabs(v.y)); // NOLINT } Py::Object Vector2dPy::number_invert() @@ -224,14 +224,14 @@ Py::Object Vector2dPy::number_add(const Py::Object& py) { Vector2d vec(Py::toVector2d(py)); vec = v + vec; - return create(vec); + return create(vec); // NOLINT } Py::Object Vector2dPy::number_subtract(const Py::Object& py) { Vector2d vec(Py::toVector2d(py)); vec = v - vec; - return create(vec); + return create(vec); // NOLINT } Py::Object Vector2dPy::number_multiply(const Py::Object& py) @@ -239,11 +239,11 @@ Py::Object Vector2dPy::number_multiply(const Py::Object& py) if (PyObject_TypeCheck(py.ptr(), Vector2dPy::type_object())) { Vector2d vec(Py::toVector2d(py)); double scalar = v * vec; - return Py::Float(scalar); + return Py::Float(scalar); // NOLINT } if (py.isNumeric()) { double scale = static_cast(Py::Float(py)); - return create(v * scale); + return create(v * scale); // NOLINT } throw Py::TypeError("Argument must be Vector2d or Float"); @@ -295,25 +295,25 @@ Py::Object Vector2dPy::isNull(const Py::Tuple& args) if (args.size() > 0) { tol = static_cast(Py::Float(args[0])); } - return Py::Boolean(v.IsNull(tol)); + return Py::Boolean(v.IsNull(tol)); // NOLINT } PYCXX_VARARGS_METHOD_DECL(Vector2dPy, isNull) Py::Object Vector2dPy::length(const Py::Tuple&) { - return Py::Float(v.Length()); + return Py::Float(v.Length()); // NOLINT } PYCXX_VARARGS_METHOD_DECL(Vector2dPy, length) Py::Object Vector2dPy::atan2(const Py::Tuple&) { - return Py::Float(v.Angle()); + return Py::Float(v.Angle()); // NOLINT } PYCXX_VARARGS_METHOD_DECL(Vector2dPy, atan2) Py::Object Vector2dPy::square(const Py::Tuple&) { - return Py::Float(v.Sqr()); + return Py::Float(v.Sqr()); // NOLINT } PYCXX_VARARGS_METHOD_DECL(Vector2dPy, square) @@ -344,14 +344,14 @@ Py::Object Vector2dPy::perpendicular(const Py::Tuple& args) { bool value = static_cast(Py::Boolean(args[0])); Base::Vector2d pnt = v.Perpendicular(value); - return create(pnt); + return create(pnt); // NOLINT } PYCXX_VARARGS_METHOD_DECL(Vector2dPy, perpendicular) Py::Object Vector2dPy::distance(const Py::Tuple& args) { Base::Vector2d pnt = Py::toVector2d(args[0]); - return Py::Float(pnt.Distance(v)); + return Py::Float(pnt.Distance(v)); // NOLINT } PYCXX_VARARGS_METHOD_DECL(Vector2dPy, distance) @@ -359,14 +359,14 @@ Py::Object Vector2dPy::isEqual(const Py::Tuple& args) { Base::Vector2d pnt = Py::toVector2d(args[0]); double tol = static_cast(Py::Float(args[1])); - return Py::Boolean(v.IsEqual(pnt, tol)); + return Py::Boolean(v.IsEqual(pnt, tol)); // NOLINT } PYCXX_VARARGS_METHOD_DECL(Vector2dPy, isEqual) Py::Object Vector2dPy::getAngle(const Py::Tuple& args) { Base::Vector2d vec = Py::toVector2d(args[0]); - return Py::Float(v.GetAngle(vec)); + return Py::Float(v.GetAngle(vec)); // NOLINT } PYCXX_VARARGS_METHOD_DECL(Vector2dPy, getAngle) diff --git a/src/Base/GeometryPyCXX.h b/src/Base/GeometryPyCXX.h index c9b54ac825..709c8a689e 100644 --- a/src/Base/GeometryPyCXX.h +++ b/src/Base/GeometryPyCXX.h @@ -236,7 +236,8 @@ public: } GeometryT& operator=(const Object& rhs) { - return (*this = *rhs); + *this = *rhs; + return *this; } GeometryT& operator=(PyObject* rhsp) { diff --git a/src/Base/InputSource.h b/src/Base/InputSource.h index a5fe42630c..a56d5bc507 100644 --- a/src/Base/InputSource.h +++ b/src/Base/InputSource.h @@ -63,7 +63,9 @@ public: // Unimplemented constructors and operators // ----------------------------------------------------------------------- StdInputStream(const StdInputStream&) = delete; + StdInputStream(StdInputStream&&) = delete; StdInputStream& operator=(const StdInputStream&) = delete; + StdInputStream& operator=(StdInputStream&&) = delete; private: // ----------------------------------------------------------------------- @@ -91,7 +93,9 @@ public: XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream* makeStream() const override; StdInputSource(const StdInputSource&) = delete; + StdInputSource(StdInputSource&&) = delete; StdInputSource& operator=(const StdInputSource&) = delete; + StdInputSource& operator=(StdInputSource&&) = delete; private: std::istream& stream; diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp index 57fdf138c5..9c5b7be311 100644 --- a/src/Base/Interpreter.cpp +++ b/src/Base/Interpreter.cpp @@ -303,7 +303,7 @@ std::string InterpreterSingleton::runStringWithKey(const char* psCmd, Py::Object key_return_value = localDictionary.getItem(key); if (!key_return_value.isString()) { - key_return_value = key_return_value.str(); + key_return_value = key_return_value.str(); // NOLINT } Py::Bytes str = Py::String(key_return_value).encode("utf-8", "~E~"); diff --git a/src/Base/Interpreter.h b/src/Base/Interpreter.h index 14d897baed..43b85ee0d7 100644 --- a/src/Base/Interpreter.h +++ b/src/Base/Interpreter.h @@ -96,8 +96,12 @@ public: /// constructor does the whole job PyException(); PyException(const Py::Object& obj); + PyException(const PyException&) = default; + PyException(PyException&&) = default; ~PyException() noexcept override; + PyException& operator=(const PyException&) = default; + PyException& operator=(PyException&&) = default; void raiseException(); /// this method determines if the original exception @@ -122,7 +126,7 @@ public: /// Sets the Python error indicator and an error message void setPyException() const override; -protected: +private: std::string _stackTrace; std::string _errorType; PyObject* _exceptionType; @@ -155,7 +159,11 @@ class BaseExport SystemExitException: public Exception { public: SystemExitException(); + SystemExitException(const SystemExitException&) = default; + SystemExitException(SystemExitException&&) = default; ~SystemExitException() noexcept override = default; + SystemExitException& operator=(const SystemExitException&) = default; + SystemExitException& operator=(SystemExitException&&) = default; long getExitCode() const { return _exitCode; @@ -177,13 +185,18 @@ class BaseExport PyGILStateLocker public: PyGILStateLocker() { - gstate = PyGILState_Ensure(); + gstate = PyGILState_Ensure(); // NOLINT } ~PyGILStateLocker() { PyGILState_Release(gstate); } + PyGILStateLocker(const PyGILStateLocker&) = delete; + PyGILStateLocker(PyGILStateLocker&&) = delete; + PyGILStateLocker& operator=(const PyGILStateLocker&) = delete; + PyGILStateLocker& operator=(PyGILStateLocker&&) = delete; + private: PyGILState_STATE gstate; }; @@ -203,7 +216,7 @@ public: PyGILStateRelease() { // release the global interpreter lock - state = PyEval_SaveThread(); + state = PyEval_SaveThread(); // NOLINT } ~PyGILStateRelease() { @@ -211,6 +224,11 @@ public: PyEval_RestoreThread(state); } + PyGILStateRelease(const PyGILStateRelease&) = delete; + PyGILStateRelease(PyGILStateRelease&&) = delete; + PyGILStateRelease& operator=(const PyGILStateRelease&) = delete; + PyGILStateRelease& operator=(PyGILStateRelease&&) = delete; + private: PyThreadState* state; }; @@ -226,6 +244,11 @@ public: InterpreterSingleton(); ~InterpreterSingleton(); + InterpreterSingleton(const InterpreterSingleton&) = delete; + InterpreterSingleton(InterpreterSingleton&&) = delete; + InterpreterSingleton& operator=(const InterpreterSingleton&) = delete; + InterpreterSingleton& operator=(InterpreterSingleton&&) = delete; + /** @name execution methods */ //@{ diff --git a/src/Base/Matrix.cpp b/src/Base/Matrix.cpp index cd3c3c80c2..065fc1b569 100644 --- a/src/Base/Matrix.cpp +++ b/src/Base/Matrix.cpp @@ -969,8 +969,7 @@ std::array Matrix4D::decompose() const std::array dirs = {Vector3d(1., 0., 0.), Vector3d(0., 1., 0.), Vector3d(0., 0., 1.)}; - int i; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (residualMatrix.getCol(i).IsNull()) { continue; } @@ -1032,7 +1031,7 @@ std::array Matrix4D::decompose() const // Restore trace in shear matrix residualMatrix.setDiagonal(Vector3d(1.0, 1.0, 1.0)); // Remove values close to zero - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (std::abs(scaleMatrix.dMtrx4D[i][i]) < 1e-15) { scaleMatrix.dMtrx4D[i][i] = 0.0; } diff --git a/src/Base/Observer.h b/src/Base/Observer.h index 0f7e7932c9..a45fea156c 100644 --- a/src/Base/Observer.h +++ b/src/Base/Observer.h @@ -90,6 +90,9 @@ public: { return nullptr; } + +protected: + FC_DEFAULT_COPY_MOVE(Observer) }; /** Subject class @@ -225,8 +228,10 @@ public: _ObserverSet.clear(); } - protected: + FC_DEFAULT_COPY_MOVE(Subject) + +private: /// Vector of attached observers std::set*> _ObserverSet; }; diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index 23bb112cd1..47163d7259 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -76,14 +76,6 @@ using namespace Base; class DOMTreeErrorReporter: public ErrorHandler { public: - // ----------------------------------------------------------------------- - // Constructors and Destructor - // ----------------------------------------------------------------------- - DOMTreeErrorReporter() = default; - - ~DOMTreeErrorReporter() override = default; - - // ----------------------------------------------------------------------- // Implementation of the error handler interface // ----------------------------------------------------------------------- @@ -131,10 +123,13 @@ public: // unimplemented copy ctor and assignment operator DOMPrintFilter(const DOMPrintFilter&) = delete; + DOMPrintFilter(DOMPrintFilter&&) = delete; DOMPrintFilter& operator=(const DOMPrintFilter&) = delete; + DOMPrintFilter& operator=(DOMPrintFilter&&) = delete; ShowType fWhatToShow; }; + class DOMPrintErrorHandler: public DOMErrorHandler { public: @@ -147,8 +142,10 @@ public: {} /* Unimplemented constructors and operators */ - explicit DOMPrintErrorHandler(const DOMErrorHandler&) = delete; - void operator=(const DOMErrorHandler&) = delete; + DOMPrintErrorHandler(const DOMPrintErrorHandler&) = delete; + DOMPrintErrorHandler(DOMPrintErrorHandler&&) = delete; + void operator=(const DOMPrintErrorHandler&) = delete; + void operator=(DOMPrintErrorHandler&&) = delete; }; diff --git a/src/Base/Parameter.h b/src/Base/Parameter.h index a2afb2efed..374a4d0980 100644 --- a/src/Base/Parameter.h +++ b/src/Base/Parameter.h @@ -94,6 +94,11 @@ class ParameterManager; class BaseExport ParameterGrp: public Base::Handled, public Base::Subject { public: + ParameterGrp(const ParameterGrp&) = delete; + ParameterGrp(ParameterGrp&&) = delete; + ParameterGrp& operator=(const ParameterGrp&) = delete; + ParameterGrp& operator=(ParameterGrp&&) = delete; + /** @name copy and insertation */ //@{ /// make a deep copy to the other group @@ -346,7 +351,9 @@ protected: class BaseExport ParameterSerializer { public: - ParameterSerializer(const std::string& fn); + explicit ParameterSerializer(const std::string& fn); + ParameterSerializer(const ParameterSerializer&) = delete; + ParameterSerializer(ParameterSerializer&&) = delete; virtual ~ParameterSerializer(); virtual void SaveDocument(const ParameterManager&); @@ -357,7 +364,10 @@ public: return filename; } -protected: + ParameterSerializer& operator=(const ParameterSerializer&) = delete; + ParameterSerializer& operator=(ParameterSerializer&&) = delete; + +private: std::string filename; }; @@ -446,7 +456,14 @@ private: private: ParameterManager(); + +public: ~ParameterManager() override; + ParameterManager(const ParameterManager&) = delete; + ParameterManager(ParameterManager&&) = delete; + + ParameterManager& operator=(const ParameterManager&) = delete; + ParameterManager& operator=(ParameterManager&&) = delete; }; /** python wrapper function diff --git a/src/Base/ParameterPy.cpp b/src/Base/ParameterPy.cpp index 191b71e1fe..f6ea8d797c 100644 --- a/src/Base/ParameterPy.cpp +++ b/src/Base/ParameterPy.cpp @@ -46,7 +46,7 @@ namespace Base { -class ParameterGrpObserver: public ParameterGrp::ObserverType +class ParameterGrpObserver: public ParameterGrp::ObserverType // NOLINT { public: explicit ParameterGrpObserver(const Py::Object& obj) @@ -100,7 +100,7 @@ private: using ParameterGrpObserverList = std::list; -class ParameterGrpPy: public Py::PythonExtension +class ParameterGrpPy: public Py::PythonExtension // NOLINT { public: static void init_type(); // announce properties and methods @@ -267,7 +267,7 @@ Py::Object ParameterGrpPy::repr() { std::stringstream s; s << ""; - return Py::String(s.str()); + return Py::String(s.str()); // NOLINT } Py::Object ParameterGrpPy::importFrom(const Py::Tuple& args) @@ -372,7 +372,7 @@ Py::Object ParameterGrpPy::getGroupName(const Py::Tuple& args) // get the Handle of the wanted group std::string name = _cParamGrp->GetGroupName(); - return Py::String(name); + return Py::String(name); // NOLINT } Py::Object ParameterGrpPy::getGroups(const Py::Tuple& args) @@ -388,7 +388,7 @@ Py::Object ParameterGrpPy::getGroups(const Py::Tuple& args) list.append(Py::String(it->GetGroupName())); } - return list; + return list; // NOLINT } Py::Object ParameterGrpPy::setBool(const Py::Tuple& args) @@ -411,7 +411,7 @@ Py::Object ParameterGrpPy::getBool(const Py::Tuple& args) throw Py::Exception(); } - return Py::Boolean(_cParamGrp->GetBool(pstr, Bool != 0)); + return Py::Boolean(_cParamGrp->GetBool(pstr, Bool != 0)); // NOLINT } Py::Object ParameterGrpPy::getBools(const Py::Tuple& args) @@ -427,7 +427,7 @@ Py::Object ParameterGrpPy::getBools(const Py::Tuple& args) list.append(Py::String(it.first)); } - return list; + return list; // NOLINT } Py::Object ParameterGrpPy::setInt(const Py::Tuple& args) @@ -449,7 +449,7 @@ Py::Object ParameterGrpPy::getInt(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "s|i", &pstr, &Int)) { throw Py::Exception(); } - return Py::Long(_cParamGrp->GetInt(pstr, Int)); + return Py::Long(_cParamGrp->GetInt(pstr, Int)); // NOLINT } Py::Object ParameterGrpPy::getInts(const Py::Tuple& args) @@ -465,7 +465,7 @@ Py::Object ParameterGrpPy::getInts(const Py::Tuple& args) list.append(Py::String(it.first)); } - return list; + return list; // NOLINT } Py::Object ParameterGrpPy::setUnsigned(const Py::Tuple& args) @@ -487,7 +487,7 @@ Py::Object ParameterGrpPy::getUnsigned(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "s|I", &pstr, &UInt)) { throw Py::Exception(); } - return Py::Long(_cParamGrp->GetUnsigned(pstr, UInt)); + return Py::Long(_cParamGrp->GetUnsigned(pstr, UInt)); // NOLINT } Py::Object ParameterGrpPy::getUnsigneds(const Py::Tuple& args) @@ -503,7 +503,7 @@ Py::Object ParameterGrpPy::getUnsigneds(const Py::Tuple& args) list.append(Py::String(it.first)); } - return list; + return list; // NOLINT } Py::Object ParameterGrpPy::setFloat(const Py::Tuple& args) @@ -526,7 +526,7 @@ Py::Object ParameterGrpPy::getFloat(const Py::Tuple& args) throw Py::Exception(); } - return Py::Float(_cParamGrp->GetFloat(pstr, Float)); + return Py::Float(_cParamGrp->GetFloat(pstr, Float)); // NOLINT } Py::Object ParameterGrpPy::getFloats(const Py::Tuple& args) @@ -542,7 +542,7 @@ Py::Object ParameterGrpPy::getFloats(const Py::Tuple& args) list.append(Py::String(it.first)); } - return list; + return list; // NOLINT } Py::Object ParameterGrpPy::setString(const Py::Tuple& args) @@ -565,7 +565,7 @@ Py::Object ParameterGrpPy::getString(const Py::Tuple& args) throw Py::Exception(); } - return Py::String(_cParamGrp->GetASCII(pstr, str)); + return Py::String(_cParamGrp->GetASCII(pstr, str)); // NOLINT } Py::Object ParameterGrpPy::getStrings(const Py::Tuple& args) @@ -581,7 +581,7 @@ Py::Object ParameterGrpPy::getStrings(const Py::Tuple& args) list.append(Py::String(it.first)); } - return list; + return list; // NOLINT } Py::Object ParameterGrpPy::remInt(const Py::Tuple& args) @@ -666,7 +666,7 @@ Py::Object ParameterGrpPy::isEmpty(const Py::Tuple& args) throw Py::Exception(); } - return Py::Boolean(_cParamGrp->IsEmpty()); + return Py::Boolean(_cParamGrp->IsEmpty()); // NOLINT } Py::Object ParameterGrpPy::hasGroup(const Py::Tuple& args) @@ -676,7 +676,7 @@ Py::Object ParameterGrpPy::hasGroup(const Py::Tuple& args) throw Py::Exception(); } - return Py::Boolean(_cParamGrp->HasGroup(pstr)); + return Py::Boolean(_cParamGrp->HasGroup(pstr)); // NOLINT } Py::Object ParameterGrpPy::attach(const Py::Tuple& args) @@ -870,7 +870,7 @@ Py::Object ParameterGrpPy::getContents(const Py::Tuple& args) list.append(t6); } - return list; + return list; // NOLINT } } // namespace Base diff --git a/src/Base/PyObjectBase.h b/src/Base/PyObjectBase.h index 4a154c78f4..09e6b72055 100644 --- a/src/Base/PyObjectBase.h +++ b/src/Base/PyObjectBase.h @@ -24,6 +24,7 @@ #define BASE_PYOBJECTBASE_H // clang-format off +// NOLINTBEGIN(cppcoreguidelines-macro-usage) // Std. configurations // (re-)defined in pyconfig.h @@ -556,6 +557,7 @@ inline void PyTypeCheck(PyObject** ptr, int (*method)(PyObject*), const char* ms } // namespace Base +// NOLINTBEGIN(cppcoreguidelines-macro-usage) // clang-format on #endif // BASE_PYOBJECTBASE_H diff --git a/src/Base/Rotation.cpp b/src/Base/Rotation.cpp index abb609141c..f4f3197375 100644 --- a/src/Base/Rotation.cpp +++ b/src/Base/Rotation.cpp @@ -81,39 +81,6 @@ Rotation::Rotation(const Vector3d& rotateFrom, const Vector3d& rotateTo) this->setValue(rotateFrom, rotateTo); } -Rotation::Rotation(const Rotation& rot) - : Rotation() -{ - this->quat[0] = rot.quat[0]; - this->quat[1] = rot.quat[1]; - this->quat[2] = rot.quat[2]; - this->quat[3] = rot.quat[3]; - - this->_axis[0] = rot._axis[0]; - this->_axis[1] = rot._axis[1]; - this->_axis[2] = rot._axis[2]; - this->_angle = rot._angle; -} - -Rotation& Rotation::operator=(const Rotation& rot) -{ - if (this == &rot) { - return *this; - } - - this->quat[0] = rot.quat[0]; - this->quat[1] = rot.quat[1]; - this->quat[2] = rot.quat[2]; - this->quat[3] = rot.quat[3]; - - this->_axis[0] = rot._axis[0]; - this->_axis[1] = rot._axis[1]; - this->_axis[2] = rot._axis[2]; - this->_angle = rot._angle; - - return *this; -} - const double* Rotation::getValue() const { return &this->quat[0]; diff --git a/src/Base/Rotation.h b/src/Base/Rotation.h index 8bd8e08d17..f663c81510 100644 --- a/src/Base/Rotation.h +++ b/src/Base/Rotation.h @@ -46,7 +46,9 @@ public: Rotation(const double q[4]); Rotation(double q0, double q1, double q2, double q3); Rotation(const Vector3d& rotateFrom, const Vector3d& rotateTo); - Rotation(const Rotation& rot); + Rotation(const Rotation& rot) = default; + Rotation(Rotation&& rot) = default; + ~Rotation() = default; //@} /** Methods to get or set rotations. */ @@ -141,7 +143,8 @@ public: { return quat[usIndex]; } - Rotation& operator=(const Rotation&); + Rotation& operator=(const Rotation&) = default; + Rotation& operator=(Rotation&&) = default; Rotation& multRight(const Base::Rotation& q); Rotation& multLeft(const Base::Rotation& q); diff --git a/src/Base/Sequencer.h b/src/Base/Sequencer.h index 72e39d98b7..f256832d93 100644 --- a/src/Base/Sequencer.h +++ b/src/Base/Sequencer.h @@ -126,6 +126,8 @@ public: * @see Sequencer */ static SequencerBase& Instance(); + /** Destruction */ + virtual ~SequencerBase(); /** * Returns true if the running sequencer is blocking any user input. * This might be only of interest of the GUI where the progress bar or dialog @@ -205,9 +207,9 @@ protected: /** construction */ SequencerBase(); SequencerBase(const SequencerBase&) = default; + SequencerBase(SequencerBase&&) = default; SequencerBase& operator=(const SequencerBase&) = default; - /** Destruction */ - virtual ~SequencerBase(); + SequencerBase& operator=(SequencerBase&&) = default; /** * Sets a text what the pending operation is doing. The default implementation * does nothing. @@ -375,7 +377,9 @@ public: bool wasCanceled() const; SequencerLauncher(const SequencerLauncher&) = delete; + SequencerLauncher(SequencerLauncher&&) = delete; void operator=(const SequencerLauncher&) = delete; + void operator=(SequencerLauncher&&) = delete; }; /** Access to the only SequencerBase instance */ diff --git a/src/Base/TimeInfo.cpp b/src/Base/TimeInfo.cpp index 6a16eed8f0..0fd6bb9fe9 100644 --- a/src/Base/TimeInfo.cpp +++ b/src/Base/TimeInfo.cpp @@ -58,8 +58,9 @@ TimeInfo::~TimeInfo() = default; void TimeInfo::setCurrent() { + // clang-format off #if defined(FC_OS_BSD) || defined(FC_OS_LINUX) || defined(__MINGW32__) - struct timeval tv; + struct timeval tv {}; gettimeofday(&tv, nullptr); timebuffer.time = tv.tv_sec; timebuffer.millitm = tv.tv_usec / 1000; @@ -68,6 +69,7 @@ void TimeInfo::setCurrent() #else ftime(&timebuffer); // deprecated #endif + // clang-format on } void TimeInfo::setTime_t(int64_t seconds) diff --git a/src/Base/TimeInfo.h b/src/Base/TimeInfo.h index 482c8452b6..ae9164d41d 100644 --- a/src/Base/TimeInfo.h +++ b/src/Base/TimeInfo.h @@ -60,8 +60,9 @@ public: /// Construction TimeInfo(); TimeInfo(const TimeInfo&) = default; + TimeInfo(TimeInfo&&) = default; /// Destruction - virtual ~TimeInfo(); + ~TimeInfo(); /// sets the object to the actual system time void setCurrent(); @@ -70,7 +71,8 @@ public: int64_t getSeconds() const; unsigned short getMiliseconds() const; - void operator=(const TimeInfo& time); + TimeInfo& operator=(const TimeInfo& time) = default; + TimeInfo& operator=(TimeInfo&& time) = default; bool operator==(const TimeInfo& time) const; bool operator!=(const TimeInfo& time) const; @@ -85,12 +87,14 @@ public: bool isNull() const; static TimeInfo null(); -protected: +private: + // clang-format off #if defined(_MSC_VER) struct _timeb timebuffer; #elif defined(__GNUC__) - struct timeb timebuffer; + struct timeb timebuffer {}; #endif + // clang-format on }; @@ -110,11 +114,6 @@ inline bool TimeInfo::operator!=(const TimeInfo& time) const || timebuffer.millitm != time.timebuffer.millitm); } -inline void TimeInfo::operator=(const TimeInfo& time) -{ - timebuffer = time.timebuffer; -} - inline bool TimeInfo::operator==(const TimeInfo& time) const { return (timebuffer.time == time.timebuffer.time diff --git a/src/Base/Tools.h b/src/Base/Tools.h index 7559bff920..194c92901b 100644 --- a/src/Base/Tools.h +++ b/src/Base/Tools.h @@ -156,6 +156,11 @@ public: int elapsed(); std::string toString(int ms) const; + StopWatch(const StopWatch&) = delete; + StopWatch(StopWatch&&) = delete; + StopWatch& operator=(const StopWatch&) = delete; + StopWatch& operator=(StopWatch&&) = delete; + private: struct Private; Private* d; diff --git a/src/Base/Tools2D.cpp b/src/Base/Tools2D.cpp index a9859eb63a..e9e39f8b02 100644 --- a/src/Base/Tools2D.cpp +++ b/src/Base/Tools2D.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +#include #include #include #endif @@ -302,7 +303,7 @@ bool Polygon2d::Contains(const Vector2d& rclV) const // Using the number of turns method, determines // whether a point is contained within a polygon. // The sum of all turns indicates whether yes or no. - std::array pfTmp; + std::array pfTmp {}; unsigned long i = 0; short sTorsion = 0; diff --git a/src/Base/Unit.cpp b/src/Base/Unit.cpp index 4f0edef21a..2092392b66 100644 --- a/src/Base/Unit.cpp +++ b/src/Base/Unit.cpp @@ -119,12 +119,7 @@ Unit::Unit() //NOLINT Sig.Angle = 0; } -Unit::Unit(const Unit& that) -{ - this->Sig = that.Sig; -} - -Unit::Unit(const QString& expr) +Unit::Unit(const QString& expr) // NOLINT { try { *this = Quantity::parse(expr).getUnit(); @@ -242,20 +237,6 @@ Unit Unit::operator /(const Unit &right) const return result; } -Unit& Unit::operator = (const Unit &New) -{ - Sig.Length = New.Sig.Length; - Sig.Mass = New.Sig.Mass; - Sig.Time = New.Sig.Time; - Sig.ElectricCurrent = New.Sig.ElectricCurrent; - Sig.ThermodynamicTemperature = New.Sig.ThermodynamicTemperature; - Sig.AmountOfSubstance = New.Sig.AmountOfSubstance; - Sig.LuminousIntensity = New.Sig.LuminousIntensity; - Sig.Angle = New.Sig.Angle; - - return *this; -} - QString Unit::getString() const { std::stringstream ret; diff --git a/src/Base/Unit.h b/src/Base/Unit.h index fc0b0db761..1e55763a04 100644 --- a/src/Base/Unit.h +++ b/src/Base/Unit.h @@ -70,7 +70,8 @@ public: int8_t LuminousIntensity = 0, int8_t Angle = 0); Unit(); - Unit(const Unit&); + Unit(const Unit&) = default; + Unit(Unit&&) = default; explicit Unit(const QString& expr); /// Destruction ~Unit() = default; @@ -87,7 +88,8 @@ public: { return !(*this == that); } - Unit& operator=(const Unit&); + Unit& operator=(const Unit&) = default; + Unit& operator=(Unit&&) = default; Unit pow(double exp) const; //@} /// get the unit signature @@ -171,7 +173,7 @@ public: static Unit InverseVolume; //@} -protected: +private: UnitSignature Sig; }; diff --git a/src/Base/UnitsSchema.h b/src/Base/UnitsSchema.h index 7eb3c86ca4..2a0e199e7c 100644 --- a/src/Base/UnitsSchema.h +++ b/src/Base/UnitsSchema.h @@ -56,6 +56,11 @@ enum class UnitSystem class UnitsSchema { public: + UnitsSchema() = default; + UnitsSchema(const UnitsSchema&) = default; + UnitsSchema(UnitsSchema&&) = default; + UnitsSchema& operator=(const UnitsSchema&) = default; + UnitsSchema& operator=(UnitsSchema&&) = default; virtual ~UnitsSchema() = default; /** Gets called if this schema gets activated. * Here it's theoretically possible that you can change the static factors diff --git a/src/Base/UnitsSchemaImperial1.cpp b/src/Base/UnitsSchemaImperial1.cpp index 99d4c10ed2..b838987df2 100644 --- a/src/Base/UnitsSchemaImperial1.cpp +++ b/src/Base/UnitsSchemaImperial1.cpp @@ -261,7 +261,7 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(const Quantity& quant, // Process into string. Start with negative sign if quantity is less // than zero - char plusOrMinus; + char plusOrMinus {}; if (quant.getValue() < 0) { output << "-"; plusOrMinus = '-'; diff --git a/src/Base/Uuid.h b/src/Base/Uuid.h index 27297a6e11..8e7c080524 100644 --- a/src/Base/Uuid.h +++ b/src/Base/Uuid.h @@ -43,7 +43,9 @@ public: /// Construction Uuid(); Uuid(const Uuid&) = default; + Uuid(Uuid&&) = default; Uuid& operator=(const Uuid&) = default; + Uuid& operator=(Uuid&&) = default; /// Destruction virtual ~Uuid(); diff --git a/src/Base/ViewProj.h b/src/Base/ViewProj.h index b4460f9e16..1788289714 100644 --- a/src/Base/ViewProj.h +++ b/src/Base/ViewProj.h @@ -38,7 +38,9 @@ class BaseExport ViewProjMethod { public: ViewProjMethod(const ViewProjMethod&) = default; + ViewProjMethod(ViewProjMethod&&) = default; ViewProjMethod& operator=(const ViewProjMethod&) = default; + ViewProjMethod& operator=(ViewProjMethod&&) = default; virtual ~ViewProjMethod() = default; virtual bool isValid() const; @@ -87,7 +89,7 @@ public: Matrix4D getProjectionMatrix() const override; -protected: +private: bool isOrthographic; Matrix4D _clMtx, _clMtxInv; }; @@ -110,7 +112,7 @@ public: Matrix4D getProjectionMatrix() const override; -protected: +private: Matrix4D _clMtx, _clMtxInv; }; diff --git a/src/Base/Writer.h b/src/Base/Writer.h index ee56a9d67e..63bbdfcd37 100644 --- a/src/Base/Writer.h +++ b/src/Base/Writer.h @@ -143,6 +143,7 @@ public: /// Return the current character output stream std::ostream& charStream(); + // NOLINTBEGIN /// name for underlying file saves std::string ObjectName; @@ -163,10 +164,13 @@ protected: bool forceXML {false}; int fileVersion {1}; + // NOLINTEND public: Writer(const Writer&) = delete; + Writer(Writer&&) = delete; Writer& operator=(const Writer&) = delete; + Writer& operator=(Writer&&) = delete; private: std::unique_ptr CharStream; @@ -207,6 +211,11 @@ public: ZipStream.putNextEntry(str); } + ZipWriter(const ZipWriter&) = delete; + ZipWriter(ZipWriter&&) = delete; + ZipWriter& operator=(const ZipWriter&) = delete; + ZipWriter& operator=(ZipWriter&&) = delete; + private: zipios::ZipOutputStream ZipStream; }; @@ -265,9 +274,16 @@ public: */ virtual bool shouldWrite(const std::string& name, const Base::Persistence* Object) const; + FileWriter(const FileWriter&) = delete; + FileWriter(FileWriter&&) = delete; + FileWriter& operator=(const FileWriter&) = delete; + FileWriter& operator=(FileWriter&&) = delete; + protected: + // NOLINTBEGIN std::string DirName; std::ofstream FileStream; + // NOLINTEND }; diff --git a/src/Base/XMLTools.h b/src/Base/XMLTools.h index 2cc046b2d1..80bbc975f0 100644 --- a/src/Base/XMLTools.h +++ b/src/Base/XMLTools.h @@ -48,7 +48,7 @@ public: static void terminate(); private: - static std::unique_ptr transcoder; + static std::unique_ptr transcoder; // NOLINT }; //************************************************************************** @@ -64,6 +64,7 @@ public: /// Getter method const char* c_str() const; + FC_DISABLE_COPY_MOVE(StrX) private: // This is the local code page form of the string. @@ -143,12 +144,12 @@ class XStr public: /// Constructors and Destructor XStr(const char* const toTranscode); - /// ~XStr(); /// Getter method const XMLCh* unicodeForm() const; + FC_DISABLE_COPY_MOVE(XStr) private: /// This is the Unicode XMLCh format of the string. @@ -189,6 +190,8 @@ public: /// Getter method const XMLCh* unicodeForm() const; + FC_DISABLE_COPY_MOVE(XUTF8Str) + private: std::basic_string str; }; diff --git a/src/Base/ZipHeader.h b/src/Base/ZipHeader.h index c450c58004..8c9e58dbe8 100644 --- a/src/Base/ZipHeader.h +++ b/src/Base/ZipHeader.h @@ -57,8 +57,6 @@ public: /** Create a copy of this instance. */ FileCollection* clone() const override; - ~ZipHeader() override = default; - void close() override; std::istream* getInputStream(const ConstEntryPointer& entry) override; diff --git a/src/FCGlobal.h b/src/FCGlobal.h index 6e0e5ccf54..9501af4a52 100644 --- a/src/FCGlobal.h +++ b/src/FCGlobal.h @@ -59,4 +59,34 @@ # define GuiExport FREECAD_DECL_IMPORT #endif +// Disable copy/move +#define FC_DISABLE_COPY(Class) \ + Class(const Class &) = delete;\ + Class &operator=(const Class &) = delete; + +#define FC_DISABLE_MOVE(Class) \ + Class(Class &&) = delete; \ + Class &operator=(Class &&) = delete; + +#define FC_DISABLE_COPY_MOVE(Class) \ + FC_DISABLE_COPY(Class) \ + FC_DISABLE_MOVE(Class) + +// Default copy/move +#define FC_DEFAULT_COPY(Class) \ + Class(const Class &) = default;\ + Class &operator=(const Class &) = default; + +#define FC_DEFAULT_MOVE(Class) \ + Class(Class &&) = default; \ + Class &operator=(Class &&) = default; + +#define FC_DEFAULT_COPY_MOVE(Class) \ + FC_DEFAULT_COPY(Class) \ + FC_DEFAULT_MOVE(Class) + +#ifndef Q_DISABLE_COPY_MOVE +#define Q_DISABLE_COPY_MOVE FC_DEFAULT_COPY_MOVE +#endif + #endif //FC_GLOBAL_H