From f539138dd9d76dc4a59c1912d6f77310e8ea48c2 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 15 Nov 2023 10:50:27 +0100 Subject: [PATCH] fix readability-*: * readability-const-return-type * readability-container-data-pointer * readability-container-size-empty * readability-delete-null-pointer * readability-else-after-return * readability-inconsistent-declaration-parameter-name * readability-redundant-member-init * readability-redundant-smartptr-get * readability-redundant-string-cstr * readability-use-anyofallof * readability-static-definition-in-anonymous-namespace * readability-static-accessed-through-instance * readability-simplify-boolean-expr --- src/Base/BaseClass.h | 10 ++- src/Base/BoundBoxPyImp.cpp | 28 ++++----- src/Base/Builder3D.cpp | 23 +++---- src/Base/Console.cpp | 10 ++- src/Base/Console.h | 10 +-- src/Base/ConsoleObserver.cpp | 4 +- src/Base/Exception.cpp | 96 ++++++++--------------------- src/Base/ExceptionFactory.cpp | 6 +- src/Base/Factory.cpp | 9 +-- src/Base/FileInfo.cpp | 16 ++--- src/Base/GeometryPyCXX.cpp | 30 ++++----- src/Base/GeometryPyCXX.h | 2 +- src/Base/Interpreter.cpp | 101 ++++++++++++++----------------- src/Base/Interpreter.h | 6 +- src/Base/Matrix.cpp | 33 +++++----- src/Base/MatrixPyImp.cpp | 25 ++++---- src/Base/Parameter.cpp | 44 ++++++-------- src/Base/ParameterPy.cpp | 5 +- src/Base/PersistencePyImp.cpp | 4 +- src/Base/ProgressIndicatorPy.cpp | 6 +- src/Base/Rotation.cpp | 37 ++++++----- src/Base/Rotation.h | 6 +- src/Base/RotationPyImp.cpp | 8 +-- src/Base/Sequencer.cpp | 2 +- src/Base/Stream.cpp | 36 ++++++----- src/Base/Stream.h | 12 ++-- src/Base/TimeInfo.h | 16 ++--- src/Base/Tools.cpp | 9 ++- src/Base/Tools.h | 5 +- src/Base/Tools2D.cpp | 51 ++++++---------- src/Base/Tools2D.h | 4 +- src/Base/Type.cpp | 21 +++---- src/Base/Type.h | 4 +- src/Base/TypePyImp.cpp | 4 +- src/Base/UnitsApi.cpp | 33 +++++----- src/Base/UnitsApi.h | 2 +- src/Base/UnitsApiPy.cpp | 2 +- src/Base/Vector3D.cpp | 2 +- src/Base/ViewProj.h | 8 +-- src/Base/Writer.cpp | 41 +++++++------ src/Base/XMLTools.cpp | 2 +- src/Base/ZipHeader.cpp | 15 +++-- 42 files changed, 330 insertions(+), 458 deletions(-) diff --git a/src/Base/BaseClass.h b/src/Base/BaseClass.h index a7514848c3..ff5b578427 100644 --- a/src/Base/BaseClass.h +++ b/src/Base/BaseClass.h @@ -196,9 +196,8 @@ T* freecad_dynamic_cast(Base::BaseClass* type) if (type && type->isDerivedFrom(T::getClassTypeId())) { return static_cast(type); } - else { - return nullptr; - } + + return nullptr; } /** @@ -212,9 +211,8 @@ const T* freecad_dynamic_cast(const Base::BaseClass* type) if (type && type->isDerivedFrom(T::getClassTypeId())) { return static_cast(type); } - else { - return nullptr; - } + + return nullptr; } diff --git a/src/Base/BoundBoxPyImp.cpp b/src/Base/BoundBoxPyImp.cpp index 1f5e1c7282..8dbeabd605 100644 --- a/src/Base/BoundBoxPyImp.cpp +++ b/src/Base/BoundBoxPyImp.cpp @@ -221,10 +221,9 @@ PyObject* BoundBoxPy::closestPoint(PyObject* args) vec = *(static_cast(object)->getVectorPtr()); break; } - else { - PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected"); - return nullptr; - } + + PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected"); + return nullptr; } while (false); Base::Vector3d point = getBoundBoxPtr()->ClosestPoint(vec); @@ -347,10 +346,9 @@ PyObject* BoundBoxPy::getIntersectionPoint(PyObject* args) if (ok) { return new VectorPy(point); } - else { - PyErr_SetString(Base::PyExc_FC_GeneralError, "No intersection"); - return nullptr; - } + + PyErr_SetString(Base::PyExc_FC_GeneralError, "No intersection"); + return nullptr; } PyObject* BoundBoxPy::move(PyObject* args) @@ -377,10 +375,9 @@ PyObject* BoundBoxPy::move(PyObject* args) vec = *(static_cast(object)->getVectorPtr()); break; } - else { - PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected"); - return nullptr; - } + + PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected"); + return nullptr; } while (false); getBoundBoxPtr()->MoveX(vec.x); @@ -414,10 +411,9 @@ PyObject* BoundBoxPy::scale(PyObject* args) vec = *(static_cast(object)->getVectorPtr()); break; } - else { - PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected"); - return nullptr; - } + + PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected"); + return nullptr; } while (false); getBoundBoxPtr()->ScaleX(vec.x); diff --git a/src/Base/Builder3D.cpp b/src/Base/Builder3D.cpp index 73876446f5..550308ebe8 100644 --- a/src/Base/Builder3D.cpp +++ b/src/Base/Builder3D.cpp @@ -941,8 +941,8 @@ void TransformItem::write(InventorOutput& out) const // ----------------------------------------------------------------------------- -InventorBuilder::InventorBuilder(std::ostream& output) - : result(output) +InventorBuilder::InventorBuilder(std::ostream& str) + : result(str) { addHeader(); } @@ -1020,7 +1020,7 @@ void Builder3D::saveToLog() ILogger* obs = Base::Console().Get("StatusBar"); if (obs) { obs->SendLog("Builder3D", - result.str().c_str(), + result.str(), Base::LogStyle::Log, Base::IntendedRecipient::Developer, Base::ContentType::Untranslatable); @@ -1240,25 +1240,22 @@ bool InventorLoader::read() bool InventorLoader::isValid() const { int32_t value {static_cast(points.size())}; - auto inRange = [value](const Face& f) { - if (f.p1 < 0 || f.p1 >= value) { + auto inRange = [value](const Face& face) { + if (face.p1 < 0 || face.p1 >= value) { return false; } - if (f.p2 < 0 || f.p2 >= value) { + if (face.p2 < 0 || face.p2 >= value) { return false; } - if (f.p3 < 0 || f.p3 >= value) { + if (face.p3 < 0 || face.p3 >= value) { return false; } return true; }; - for (auto it : faces) { - if (!inRange(it)) { - return false; - } - } - return true; + return std::all_of(faces.cbegin(), faces.cend(), [&inRange](const Face& face) { + return inRange(face); + }); } namespace Base diff --git a/src/Base/Console.cpp b/src/Base/Console.cpp index c25c24b042..0d031ce73e 100644 --- a/src/Base/Console.cpp +++ b/src/Base/Console.cpp @@ -256,9 +256,8 @@ ConsoleMsgFlags ConsoleSingleton::SetEnabledMsgType(const char* sObs, ConsoleMsg return flags; } - else { - return 0; - } + + return 0; } bool ConsoleSingleton::IsMsgTypeEnabled(const char* sObs, FreeCAD_ConsoleMsgType type) const @@ -814,9 +813,8 @@ PyObject* ConsoleSingleton::sPySetStatus(PyObject* /*self*/, PyObject* args) Py_Return; } - else { - Py_Error(Base::PyExc_FC_GeneralError, "Unknown logger type"); - } + + Py_Error(Base::PyExc_FC_GeneralError, "Unknown logger type"); } PY_CATCH; } diff --git a/src/Base/Console.h b/src/Base/Console.h index ad641d792a..2bf6b7ca24 100644 --- a/src/Base/Console.h +++ b/src/Base/Console.h @@ -576,19 +576,19 @@ public: if (category == Base::LogStyle::Log) { return bLog; } - else if (category == Base::LogStyle::Warning) { + if (category == Base::LogStyle::Warning) { return bWrn; } - else if (category == Base::LogStyle::Error) { + if (category == Base::LogStyle::Error) { return bErr; } - else if (category == Base::LogStyle::Message) { + if (category == Base::LogStyle::Message) { return bMsg; } - else if (category == Base::LogStyle::Critical) { + if (category == Base::LogStyle::Critical) { return bCritical; } - else if (category == Base::LogStyle::Notification) { + if (category == Base::LogStyle::Notification) { return bNotification; } diff --git a/src/Base/ConsoleObserver.cpp b/src/Base/ConsoleObserver.cpp index 2689e70243..1fd0ae5ead 100644 --- a/src/Base/ConsoleObserver.cpp +++ b/src/Base/ConsoleObserver.cpp @@ -197,7 +197,7 @@ void ConsoleObserverStd::Error(const char* sErr) } } -void ConsoleObserverStd::Log(const char* sErr) +void ConsoleObserverStd::Log(const char* sLog) { if (useColorStderr) { #if defined(FC_OS_WIN32) @@ -208,7 +208,7 @@ void ConsoleObserverStd::Log(const char* sErr) #endif } - fprintf(stderr, "%s", sErr); + fprintf(stderr, "%s", sLog); if (useColorStderr) { #if defined(FC_OS_WIN32) diff --git a/src/Base/Exception.cpp b/src/Base/Exception.cpp index d5fcf2e92d..b271d7aa96 100644 --- a/src/Base/Exception.cpp +++ b/src/Base/Exception.cpp @@ -86,7 +86,7 @@ void Exception::ReportException() const msg = _sErrMsg.c_str(); } #ifdef FC_DEBUG - if (_function.size()) { + if (!_function.empty()) { _FC_ERR(_file.c_str(), _line, _function << " -- " << msg); } else @@ -186,9 +186,7 @@ PyObject* AbortException::getPyExceptionType() const // --------------------------------------------------------- -XMLBaseException::XMLBaseException() - : Exception() -{} +XMLBaseException::XMLBaseException() = default; XMLBaseException::XMLBaseException(const char* sMessage) : Exception(sMessage) @@ -315,7 +313,7 @@ void FileException::ReportException() const msg = _sErrMsgAndFileName.c_str(); } #ifdef FC_DEBUG - if (_function.size()) { + if (!_function.empty()) { _FC_ERR(_file.c_str(), _line, _function << " -- " << msg); } else @@ -354,9 +352,7 @@ PyObject* FileException::getPyExceptionType() const // --------------------------------------------------------- -FileSystemError::FileSystemError() - : Exception() -{} +FileSystemError::FileSystemError() = default; FileSystemError::FileSystemError(const char* sMessage) : Exception(sMessage) @@ -374,9 +370,7 @@ PyObject* FileSystemError::getPyExceptionType() const // --------------------------------------------------------- -BadFormatError::BadFormatError() - : Exception() -{} +BadFormatError::BadFormatError() = default; BadFormatError::BadFormatError(const char* sMessage) : Exception(sMessage) @@ -469,9 +463,7 @@ PyObject* AbnormalProgramTermination::getPyExceptionType() const // --------------------------------------------------------- -UnknownProgramOption::UnknownProgramOption() - : Exception() -{} +UnknownProgramOption::UnknownProgramOption() = default; UnknownProgramOption::UnknownProgramOption(const char* sMessage) : Exception(sMessage) @@ -488,9 +480,7 @@ PyObject* UnknownProgramOption::getPyExceptionType() const // --------------------------------------------------------- -ProgramInformation::ProgramInformation() - : Exception() -{} +ProgramInformation::ProgramInformation() = default; ProgramInformation::ProgramInformation(const char* sMessage) : Exception(sMessage) @@ -502,9 +492,7 @@ ProgramInformation::ProgramInformation(const std::string& sMessage) // --------------------------------------------------------- -TypeError::TypeError() - : Exception() -{} +TypeError::TypeError() = default; TypeError::TypeError(const char* sMessage) : Exception(sMessage) @@ -521,9 +509,7 @@ PyObject* TypeError::getPyExceptionType() const // --------------------------------------------------------- -ValueError::ValueError() - : Exception() -{} +ValueError::ValueError() = default; ValueError::ValueError(const char* sMessage) : Exception(sMessage) @@ -540,9 +526,7 @@ PyObject* ValueError::getPyExceptionType() const // --------------------------------------------------------- -IndexError::IndexError() - : Exception() -{} +IndexError::IndexError() = default; IndexError::IndexError(const char* sMessage) : Exception(sMessage) @@ -559,9 +543,7 @@ PyObject* IndexError::getPyExceptionType() const // --------------------------------------------------------- -NameError::NameError() - : Exception() -{} +NameError::NameError() = default; NameError::NameError(const char* sMessage) : Exception(sMessage) @@ -578,9 +560,7 @@ PyObject* NameError::getPyExceptionType() const // --------------------------------------------------------- -ImportError::ImportError() - : Exception() -{} +ImportError::ImportError() = default; ImportError::ImportError(const char* sMessage) : Exception(sMessage) @@ -597,9 +577,7 @@ PyObject* ImportError::getPyExceptionType() const // --------------------------------------------------------- -AttributeError::AttributeError() - : Exception() -{} +AttributeError::AttributeError() = default; AttributeError::AttributeError(const char* sMessage) : Exception(sMessage) @@ -616,9 +594,7 @@ PyObject* AttributeError::getPyExceptionType() const // --------------------------------------------------------- -RuntimeError::RuntimeError() - : Exception() -{} +RuntimeError::RuntimeError() = default; RuntimeError::RuntimeError(const char* sMessage) : Exception(sMessage) @@ -654,9 +630,7 @@ PyObject* BadGraphError::getPyExceptionType() const // --------------------------------------------------------- -NotImplementedError::NotImplementedError() - : Exception() -{} +NotImplementedError::NotImplementedError() = default; NotImplementedError::NotImplementedError(const char* sMessage) : Exception(sMessage) @@ -673,9 +647,7 @@ PyObject* NotImplementedError::getPyExceptionType() const // --------------------------------------------------------- -ZeroDivisionError::ZeroDivisionError() - : Exception() -{} +ZeroDivisionError::ZeroDivisionError() = default; ZeroDivisionError::ZeroDivisionError(const char* sMessage) : Exception(sMessage) @@ -692,9 +664,7 @@ PyObject* ZeroDivisionError::getPyExceptionType() const // --------------------------------------------------------- -ReferenceError::ReferenceError() - : Exception() -{} +ReferenceError::ReferenceError() = default; ReferenceError::ReferenceError(const char* sMessage) : Exception(sMessage) @@ -711,9 +681,7 @@ PyObject* ReferenceError::getPyExceptionType() const // --------------------------------------------------------- -ExpressionError::ExpressionError() - : Exception() -{} +ExpressionError::ExpressionError() = default; ExpressionError::ExpressionError(const char* sMessage) : Exception(sMessage) @@ -730,9 +698,7 @@ PyObject* ExpressionError::getPyExceptionType() const // --------------------------------------------------------- -ParserError::ParserError() - : Exception() -{} +ParserError::ParserError() = default; ParserError::ParserError(const char* sMessage) : Exception(sMessage) @@ -749,9 +715,7 @@ PyObject* ParserError::getPyExceptionType() const // --------------------------------------------------------- -UnicodeError::UnicodeError() - : Exception() -{} +UnicodeError::UnicodeError() = default; UnicodeError::UnicodeError(const char* sMessage) : Exception(sMessage) @@ -768,9 +732,7 @@ PyObject* UnicodeError::getPyExceptionType() const // --------------------------------------------------------- -OverflowError::OverflowError() - : Exception() -{} +OverflowError::OverflowError() = default; OverflowError::OverflowError(const char* sMessage) : Exception(sMessage) @@ -787,9 +749,7 @@ PyObject* OverflowError::getPyExceptionType() const // --------------------------------------------------------- -UnderflowError::UnderflowError() - : Exception() -{} +UnderflowError::UnderflowError() = default; UnderflowError::UnderflowError(const char* sMessage) : Exception(sMessage) @@ -806,9 +766,7 @@ PyObject* UnderflowError::getPyExceptionType() const // --------------------------------------------------------- -UnitsMismatchError::UnitsMismatchError() - : Exception() -{} +UnitsMismatchError::UnitsMismatchError() = default; UnitsMismatchError::UnitsMismatchError(const char* sMessage) : Exception(sMessage) @@ -825,9 +783,7 @@ PyObject* UnitsMismatchError::getPyExceptionType() const // --------------------------------------------------------- -CADKernelError::CADKernelError() - : Exception() -{} +CADKernelError::CADKernelError() = default; CADKernelError::CADKernelError(const char* sMessage) : Exception(sMessage) @@ -844,9 +800,7 @@ PyObject* CADKernelError::getPyExceptionType() const // --------------------------------------------------------- -RestoreError::RestoreError() - : Exception() -{} +RestoreError::RestoreError() = default; RestoreError::RestoreError(const char* sMessage) : Exception(sMessage) diff --git a/src/Base/ExceptionFactory.cpp b/src/Base/ExceptionFactory.cpp index 0c2f22e61d..8fe1141c91 100644 --- a/src/Base/ExceptionFactory.cpp +++ b/src/Base/ExceptionFactory.cpp @@ -40,9 +40,7 @@ ExceptionFactory& ExceptionFactory::Instance() void ExceptionFactory::Destruct() { - if (_pcSingleton) { - delete _pcSingleton; - } + delete _pcSingleton; _pcSingleton = nullptr; } @@ -56,7 +54,7 @@ void ExceptionFactory::raiseException(PyObject* pydict) const std::map::const_iterator pProd; - pProd = _mpcProducers.find(classname.c_str()); + pProd = _mpcProducers.find(classname); if (pProd != _mpcProducers.end()) { static_cast(pProd->second)->raiseException(pydict); } diff --git a/src/Base/Factory.cpp b/src/Base/Factory.cpp index b970f05e41..8b937d3228 100644 --- a/src/Base/Factory.cpp +++ b/src/Base/Factory.cpp @@ -50,9 +50,8 @@ void* Factory::Produce(const char* sClassName) const if (pProd != _mpcProducers.end()) { return pProd->second->Produce(); } - else { - return nullptr; - } + + return nullptr; } void Factory::AddProducer(const char* sClassName, AbstractProducer* pcProducer) @@ -91,9 +90,7 @@ ScriptFactorySingleton& ScriptFactorySingleton::Instance() void ScriptFactorySingleton::Destruct() { - if (_pcSingleton) { - delete _pcSingleton; - } + delete _pcSingleton; _pcSingleton = nullptr; } diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index 7be10cae87..5ed4170341 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -107,7 +107,7 @@ const std::string& FileInfo::getTempPath() { static std::string tempPath; - if (tempPath == "") { + if (tempPath.empty()) { #ifdef FC_OS_WIN32 wchar_t buf[MAX_PATH + 2]; GetTempPathW(MAX_PATH + 1, buf); @@ -286,9 +286,8 @@ std::string FileInfo::fileNamePure() const if (pos != std::string::npos) { return temp.substr(0, pos); } - else { - return temp; - } + + return temp; } std::wstring FileInfo::toStdWString() const @@ -332,12 +331,9 @@ bool FileInfo::hasExtension(const char* Ext) const bool FileInfo::hasExtension(std::initializer_list Exts) const { - for (const char* Ext : Exts) { - if (hasExtension(Ext)) { - return true; - } - } - return false; + return std::any_of(Exts.begin(), Exts.end(), [this](const char* ext) { + return hasExtension(ext); + }); } bool FileInfo::exists() const diff --git a/src/Base/GeometryPyCXX.cpp b/src/Base/GeometryPyCXX.cpp index d7acbb307f..5dd5365f14 100644 --- a/src/Base/GeometryPyCXX.cpp +++ b/src/Base/GeometryPyCXX.cpp @@ -41,7 +41,7 @@ bool Py::Vector::accepts(PyObject* obj) const if (obj && Vector_TypeCheck(obj)) { return true; } - else if (obj && PySequence_Check(obj)) { + if (obj && PySequence_Check(obj)) { return (PySequence_Size(obj) == 3); } @@ -86,9 +86,8 @@ Base::Vector3d Py::Vector::toVector() const if (Vector_TypeCheck(ptr())) { return static_cast(ptr())->value(); } - else { - return Base::getVectorFromTuple(ptr()); - } + + return Base::getVectorFromTuple(ptr()); } namespace Base @@ -164,15 +163,14 @@ Py::Object Vector2dPy::getattro(const Py::String& name_) attr.setItem(Py::String("y"), Py::Float(v.y)); return attr; } - else if (name == "x") { + if (name == "x") { return Py::Float(v.x); } - else if (name == "y") { + if (name == "y") { return Py::Float(v.y); } - else { - return genericGetAttro(name_); - } + + return genericGetAttro(name_); } int Vector2dPy::setattro(const Py::String& name_, const Py::Object& value) @@ -183,13 +181,12 @@ int Vector2dPy::setattro(const Py::String& name_, const Py::Object& value) v.x = static_cast(Py::Float(value)); return 0; } - else if (name == "y" && !value.isNull()) { + if (name == "y" && !value.isNull()) { v.y = static_cast(Py::Float(value)); return 0; } - else { - return genericSetAttro(name_, value); - } + + return genericSetAttro(name_, value); } Py::Object Vector2dPy::number_negative() @@ -243,13 +240,12 @@ Py::Object Vector2dPy::number_multiply(const Py::Object& py) double scalar = v * vec; return Py::Float(scalar); } - else if (py.isNumeric()) { + if (py.isNumeric()) { double scale = static_cast(Py::Float(py)); return create(v * scale); } - else { - throw Py::TypeError("Argument must be Vector2d or Float"); - } + + throw Py::TypeError("Argument must be Vector2d or Float"); } Py::Object Vector2dPy::number_remainder(const Py::Object&) diff --git a/src/Base/GeometryPyCXX.h b/src/Base/GeometryPyCXX.h index 2f075c6a99..aac57cf686 100644 --- a/src/Base/GeometryPyCXX.h +++ b/src/Base/GeometryPyCXX.h @@ -159,7 +159,7 @@ public: explicit Vector(const Base::Vector3d&); explicit Vector(const Base::Vector3f&); - bool accepts(PyObject* pyob) const override; + bool accepts(PyObject* obj) const override; Vector(const Object& other) : Object(other.ptr()) diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp index 87e82f29b3..f6866f50b7 100644 --- a/src/Base/Interpreter.cpp +++ b/src/Base/Interpreter.cpp @@ -246,10 +246,9 @@ std::string InterpreterSingleton::runString(const char* sCmd) if (PyErr_ExceptionMatches(PyExc_SystemExit)) { throw SystemExitException(); } - else { - PyException::ThrowException(); - return {}; // just to quieten code analyzers - } + + PyException::ThrowException(); + return {}; // just to quieten code analyzers } PyObject* repr = PyObject_Repr(presult); @@ -259,10 +258,9 @@ std::string InterpreterSingleton::runString(const char* sCmd) Py_DECREF(repr); return ret; } - else { - PyErr_Clear(); - return {}; - } + + PyErr_Clear(); + return {}; } /** runStringWithKey(psCmd, key, key_initial_value) @@ -292,10 +290,9 @@ std::string InterpreterSingleton::runStringWithKey(const char* psCmd, if (PyErr_ExceptionMatches(PyExc_SystemExit)) { throw SystemExitException(); } - else { - PyException::ThrowException(); - return {}; // just to quieten code analyzers - } + + PyException::ThrowException(); + return {}; // just to quieten code analyzers } Py_DECREF(presult); @@ -329,9 +326,8 @@ Py::Object InterpreterSingleton::runStringObject(const char* sCmd) if (PyErr_ExceptionMatches(PyExc_SystemExit)) { throw SystemExitException(); } - else { - throw PyException(); - } + + throw PyException(); } return Py::asObject(presult); @@ -417,9 +413,8 @@ void InterpreterSingleton::runInteractiveString(const char* sCmd) } throw exc; } - else { - Py_DECREF(presult); - } + + Py_DECREF(presult); } void InterpreterSingleton::runFile(const char* pxFileName, bool local) @@ -466,9 +461,8 @@ void InterpreterSingleton::runFile(const char* pxFileName, bool local) if (PyErr_ExceptionMatches(PyExc_SystemExit)) { throw SystemExitException(); } - else { - throw PyException(); - } + + throw PyException(); } Py_DECREF(result); } @@ -490,9 +484,8 @@ bool InterpreterSingleton::loadModule(const char* psModName) if (PyErr_ExceptionMatches(PyExc_SystemExit)) { throw SystemExitException(); } - else { - throw PyException(); - } + + throw PyException(); } return true; @@ -825,7 +818,7 @@ void InterpreterSingleton::dbgUnsetBreakPoint(unsigned int /*uiLineNumber*/) void InterpreterSingleton::dbgStep() {} -const std::string InterpreterSingleton::strToPython(const char* Str) +std::string InterpreterSingleton::strToPython(const char* Str) { std::string result; const char* It = Str; @@ -859,40 +852,38 @@ int getSWIGVersionFromModule(const std::string& module) if (it != moduleMap.end()) { return it->second; } - else { - try { - // Get the module and check its __file__ attribute - Py::Dict dict(PyImport_GetModuleDict()); - if (!dict.hasKey(module)) { - return 0; - } - Py::Module mod(module); - Py::String file(mod.getAttr("__file__")); - std::string filename = (std::string)file; - // file can have the extension .py or .pyc - filename = filename.substr(0, filename.rfind('.')); - filename += ".py"; - boost::regex rx("^# Version ([1-9])\\.([0-9])\\.([0-9]+)"); - boost::cmatch what; + try { + // Get the module and check its __file__ attribute + Py::Dict dict(PyImport_GetModuleDict()); + if (!dict.hasKey(module)) { + return 0; + } + Py::Module mod(module); + Py::String file(mod.getAttr("__file__")); + std::string filename = (std::string)file; + // file can have the extension .py or .pyc + filename = filename.substr(0, filename.rfind('.')); + filename += ".py"; + boost::regex rx("^# Version ([1-9])\\.([0-9])\\.([0-9]+)"); + boost::cmatch what; - std::string line; - Base::FileInfo fi(filename); + std::string line; + Base::FileInfo fi(filename); - Base::ifstream str(fi, std::ios::in); - while (str && std::getline(str, line)) { - if (boost::regex_match(line.c_str(), what, rx)) { - int major = std::atoi(what[1].first); - int minor = std::atoi(what[2].first); - int micro = std::atoi(what[3].first); - int version = (major << 16) + (minor << 8) + micro; - moduleMap[module] = version; - return version; - } + Base::ifstream str(fi, std::ios::in); + while (str && std::getline(str, line)) { + if (boost::regex_match(line.c_str(), what, rx)) { + int major = std::atoi(what[1].first); + int minor = std::atoi(what[2].first); + int micro = std::atoi(what[3].first); + int version = (major << 16) + (minor << 8) + micro; + moduleMap[module] = version; + return version; } } - catch (Py::Exception& e) { - e.clear(); - } + } + catch (Py::Exception& e) { + e.clear(); } #if (defined(HAVE_SWIG) && (HAVE_SWIG == 1)) diff --git a/src/Base/Interpreter.h b/src/Base/Interpreter.h index 1a9535cd0b..cad7f569b5 100644 --- a/src/Base/Interpreter.h +++ b/src/Base/Interpreter.h @@ -305,7 +305,7 @@ public: //@{ /// generate a SWIG object PyObject* - createSWIGPointerObj(const char* Modole, const char* TypeName, void* Pointer, int own); + createSWIGPointerObj(const char* Module, const char* TypeName, void* Pointer, int own); bool convertSWIGPointerObj(const char* Module, const char* TypeName, PyObject* obj, @@ -333,8 +333,8 @@ public: */ //@{ /// replaces all char with escapes for usage in python console - static const std::string strToPython(const char* Str); - static const std::string strToPython(const std::string& Str) + static std::string strToPython(const char* Str); + static std::string strToPython(const std::string& Str) { return strToPython(Str.c_str()); } diff --git a/src/Base/Matrix.cpp b/src/Base/Matrix.cpp index a530b46708..d9a07d3f08 100644 --- a/src/Base/Matrix.cpp +++ b/src/Base/Matrix.cpp @@ -978,24 +978,23 @@ std::array Matrix4D::decompose() const prim_dir = i; continue; } - else { - Vector3d cross = dirs[prim_dir].Cross(residualMatrix.getCol(i)); - if (cross.IsNull()) { - continue; - } - cross.Normalize(); - int last_dir = 3 - i - prim_dir; - if (i - prim_dir == 1) { - dirs[last_dir] = cross; - dirs[i] = cross.Cross(dirs[prim_dir]); - } - else { - dirs[last_dir] = -cross; - dirs[i] = dirs[prim_dir].Cross(-cross); - } - prim_dir = -2; // done - break; + + Vector3d cross = dirs[prim_dir].Cross(residualMatrix.getCol(i)); + if (cross.IsNull()) { + continue; } + cross.Normalize(); + int last_dir = 3 - i - prim_dir; + if (i - prim_dir == 1) { + dirs[last_dir] = cross; + dirs[i] = cross.Cross(dirs[prim_dir]); + } + else { + dirs[last_dir] = -cross; + dirs[i] = dirs[prim_dir].Cross(-cross); + } + prim_dir = -2; // done + break; } if (prim_dir >= 0) { // handle case with only one valid direction diff --git a/src/Base/MatrixPyImp.cpp b/src/Base/MatrixPyImp.cpp index b3a46aba52..9dc8a5fb32 100644 --- a/src/Base/MatrixPyImp.cpp +++ b/src/Base/MatrixPyImp.cpp @@ -244,16 +244,15 @@ PyObject* MatrixPy::richCompare(PyObject* v, PyObject* w, int op) PyErr_SetString(PyExc_TypeError, "no ordering relation is defined for Matrix"); return nullptr; } - else if (op == Py_EQ) { + if (op == Py_EQ) { res = (m1 == m2) ? Py_True : Py_False; // NOLINT Py_INCREF(res); return res; } - else { - res = (m1 != m2) ? Py_True : Py_False; // NOLINT - Py_INCREF(res); - return res; - } + + res = (m1 != m2) ? Py_True : Py_False; // NOLINT + Py_INCREF(res); + return res; } else { // This always returns False @@ -667,10 +666,9 @@ PyObject* MatrixPy::invert() getMatrixPtr()->inverseGauss(); Py_Return; } - else { - PyErr_SetString(Base::PyExc_FC_GeneralError, "Cannot invert singular matrix"); - return nullptr; - } + + PyErr_SetString(Base::PyExc_FC_GeneralError, "Cannot invert singular matrix"); + return nullptr; } PY_CATCH; } @@ -684,10 +682,9 @@ PyObject* MatrixPy::inverse() m.inverseGauss(); return new MatrixPy(m); } - else { - PyErr_SetString(Base::PyExc_FC_GeneralError, "Cannot invert singular matrix"); - return nullptr; - } + + PyErr_SetString(Base::PyExc_FC_GeneralError, "Cannot invert singular matrix"); + return nullptr; } PY_CATCH; } diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index 6e671273de..98dd8ccc53 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -25,6 +25,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +#include #include #include #include @@ -464,7 +465,7 @@ std::string ParameterGrp::GetPath() const if (_Parent && _Parent != _Manager) { path = _Parent->GetPath(); } - if (path.size() && _cName.size()) { + if (!path.empty() && !_cName.empty()) { path += "/"; } path += _cName; @@ -506,9 +507,8 @@ bool ParameterGrp::IsEmpty() const if (_pGroupNode && _pGroupNode->getFirstChild()) { return false; } - else { - return true; - } + + return true; } /// test if a special sub group is in this group @@ -730,13 +730,9 @@ bool ParameterGrp::GetBool(const char* Name, bool bPreset) const if (!pcElem) { return bPreset; } + // if yes check the value and return - if (strcmp(StrX(pcElem->getAttribute(XStr("Value").unicodeForm())).c_str(), "1")) { - return false; - } - else { - return true; - } + return (strcmp(StrX(pcElem->getAttribute(XStr("Value").unicodeForm())).c_str(), "1") == 0); } void ParameterGrp::SetBool(const char* Name, bool bValue) @@ -1381,13 +1377,10 @@ bool ParameterGrp::ShouldRemove() const if (this->getRefCount() > 1) { return false; } - for (const auto& it : _GroupMap) { - bool ok = it.second->ShouldRemove(); - if (!ok) { - return false; - } - } - return true; + + return std::all_of(_GroupMap.cbegin(), _GroupMap.cend(), [](const auto& it) { + return it.second->ShouldRemove(); + }); } XERCES_CPP_NAMESPACE_QUALIFIER DOMElement* @@ -1710,9 +1703,8 @@ int ParameterManager::LoadDocument() if (paramSerializer) { return paramSerializer->LoadDocument(*this); } - else { - return -1; - } + + return -1; } bool ParameterManager::LoadOrCreateDocument() @@ -1720,9 +1712,8 @@ bool ParameterManager::LoadOrCreateDocument() if (paramSerializer) { return paramSerializer->LoadOrCreateDocument(*this); } - else { - return false; - } + + return false; } void ParameterManager::SaveDocument() const @@ -1742,10 +1733,9 @@ bool ParameterManager::LoadOrCreateDocument(const char* sFileName) LoadDocument(sFileName); return false; } - else { - CreateDocument(); - return true; - } + + CreateDocument(); + return true; } int ParameterManager::LoadDocument(const char* sFileName) diff --git a/src/Base/ParameterPy.cpp b/src/Base/ParameterPy.cpp index d17c816e2a..d04cf934d7 100644 --- a/src/Base/ParameterPy.cpp +++ b/src/Base/ParameterPy.cpp @@ -315,9 +315,8 @@ Py::Object ParameterGrpPy::getGroup(const Py::Tuple& args) // increment the ref count return Py::asObject(pcParamGrp); } - else { - throw Py::RuntimeError("GetGroup failed"); - } + + throw Py::RuntimeError("GetGroup failed"); } catch (const Base::Exception& e) { e.setPyException(); diff --git a/src/Base/PersistencePyImp.cpp b/src/Base/PersistencePyImp.cpp index 4f5cbf962b..3c9f72d323 100644 --- a/src/Base/PersistencePyImp.cpp +++ b/src/Base/PersistencePyImp.cpp @@ -83,13 +83,13 @@ PyObject* PersistencePy::dumpContent(PyObject* args, PyObject* kwds) } // build the byte array with correct size - if (!stream.seekp(0, stream.end)) { + if (!stream.seekp(0, std::stringstream::end)) { PyErr_SetString(PyExc_IOError, "Unable to find end of stream"); return nullptr; } std::stringstream::pos_type offset = stream.tellp(); - if (!stream.seekg(0, stream.beg)) { + if (!stream.seekg(0, std::stringstream::beg)) { PyErr_SetString(PyExc_IOError, "Unable to find begin of stream"); return nullptr; } diff --git a/src/Base/ProgressIndicatorPy.cpp b/src/Base/ProgressIndicatorPy.cpp index 34fd911f1c..a28e3183bc 100644 --- a/src/Base/ProgressIndicatorPy.cpp +++ b/src/Base/ProgressIndicatorPy.cpp @@ -80,7 +80,7 @@ Py::Object ProgressIndicatorPy::start(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "sI", &text, &steps)) { throw Py::Exception(); } - if (!_seq.get()) { + if (!_seq) { _seq = std::make_unique(text, steps); } return Py::None(); @@ -92,9 +92,9 @@ Py::Object ProgressIndicatorPy::next(const Py::Tuple& args) if (!PyArg_ParseTuple(args.ptr(), "|i", &b)) { throw Py::Exception(); } - if (_seq.get()) { + if (_seq) { try { - _seq->next(b ? true : false); + _seq->next(b != 0); } catch (const Base::AbortException&) { _seq.reset(); diff --git a/src/Base/Rotation.cpp b/src/Base/Rotation.cpp index e506a4248c..bc1da5de7b 100644 --- a/src/Base/Rotation.cpp +++ b/src/Base/Rotation.cpp @@ -423,13 +423,7 @@ Rotation& Rotation::multLeft(const Base::Rotation& q) bool Rotation::operator==(const Rotation& q) const { - if ((this->quat[0] == q.quat[0] && this->quat[1] == q.quat[1] && this->quat[2] == q.quat[2] - && this->quat[3] == q.quat[3]) - || (this->quat[0] == -q.quat[0] && this->quat[1] == -q.quat[1] - && this->quat[2] == -q.quat[2] && this->quat[3] == -q.quat[3])) { - return true; - } - return false; + return isSame(q); } bool Rotation::operator!=(const Rotation& q) const @@ -591,9 +585,9 @@ Rotation::makeRotationByAxes(Vector3d xdir, Vector3d ydir, Vector3d zdir, const if (mainDir.Length() > tol) { break; } - else { - dropPriority(0); - } + + dropPriority(0); + if (i == 2) { THROWM(ValueError, "makeRotationByAxes: all directions supplied are zero"); } @@ -607,9 +601,9 @@ Rotation::makeRotationByAxes(Vector3d xdir, Vector3d ydir, Vector3d zdir, const if ((hintDir.Cross(mainDir)).Length() > tol) { break; } - else { - dropPriority(1); - } + + dropPriority(1); + if (i == 1) { hintDir = Vector3d(); // no vector can be used as hint direction. Zero it out, to // indicate that a guess is needed. @@ -757,13 +751,16 @@ void Rotation::getYawPitchRoll(double& y, double& p, double& r) const bool Rotation::isSame(const Rotation& q) const { - if ((this->quat[0] == q.quat[0] && this->quat[1] == q.quat[1] && this->quat[2] == q.quat[2] - && this->quat[3] == q.quat[3]) - || (this->quat[0] == -q.quat[0] && this->quat[1] == -q.quat[1] - && this->quat[2] == -q.quat[2] && this->quat[3] == -q.quat[3])) { - return true; - } - return false; + // clang-format off + return ((this->quat[0] == q.quat[0] && + this->quat[1] == q.quat[1] && + this->quat[2] == q.quat[2] && + this->quat[3] == q.quat[3]) || + (this->quat[0] == -q.quat[0] && + this->quat[1] == -q.quat[1] && + this->quat[2] == -q.quat[2] && + this->quat[3] == -q.quat[3])); + // clang-format on } bool Rotation::isSame(const Rotation& q, double tol) const diff --git a/src/Base/Rotation.h b/src/Base/Rotation.h index 9f36b71e9c..35e4f281ef 100644 --- a/src/Base/Rotation.h +++ b/src/Base/Rotation.h @@ -112,8 +112,8 @@ public: }; static const char* eulerSequenceName(EulerSequence seq); static EulerSequence eulerSequenceFromName(const char* name); - void getEulerAngles(EulerSequence seq, double& alpha, double& beta, double& gamma) const; - void setEulerAngles(EulerSequence seq, double alpha, double beta, double gamma); + void getEulerAngles(EulerSequence theOrder, double& alpha, double& beta, double& gamma) const; + void setEulerAngles(EulerSequence theOrder, double alpha, double beta, double gamma); bool isIdentity() const; bool isIdentity(double tol) const; bool isNull() const; @@ -154,7 +154,7 @@ public: //@} /** Specialty constructors */ - static Rotation slerp(const Rotation& rot0, const Rotation& rot1, double t); + static Rotation slerp(const Rotation& q1, const Rotation& q2, double t); static Rotation identity(); /** diff --git a/src/Base/RotationPyImp.cpp b/src/Base/RotationPyImp.cpp index 80c6eb180b..5fabe4e560 100644 --- a/src/Base/RotationPyImp.cpp +++ b/src/Base/RotationPyImp.cpp @@ -515,22 +515,22 @@ PyObject* RotationPy::getCustomAttributes(const char* attr) const this->getRotationPtr()->getValue(mat); return new MatrixPy(mat); } - else if (strcmp(attr, "Yaw") == 0) { + if (strcmp(attr, "Yaw") == 0) { double A {}, B {}, C {}; this->getRotationPtr()->getYawPitchRoll(A, B, C); return PyFloat_FromDouble(A); } - else if (strcmp(attr, "Pitch") == 0) { + if (strcmp(attr, "Pitch") == 0) { double A {}, B {}, C {}; this->getRotationPtr()->getYawPitchRoll(A, B, C); return PyFloat_FromDouble(B); } - else if (strcmp(attr, "Roll") == 0) { + if (strcmp(attr, "Roll") == 0) { double A {}, B {}, C {}; this->getRotationPtr()->getYawPitchRoll(A, B, C); return PyFloat_FromDouble(C); } - else if (strcmp(attr, "toEuler") == 0) { + if (strcmp(attr, "toEuler") == 0) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) Py::Object self(const_cast(this), false); return Py::new_reference_to(self.getAttr("getYawPitchRoll")); diff --git a/src/Base/Sequencer.cpp b/src/Base/Sequencer.cpp index f6cb224fa1..5dfaf4027a 100644 --- a/src/Base/Sequencer.cpp +++ b/src/Base/Sequencer.cpp @@ -72,7 +72,7 @@ QRecursiveMutex SequencerP::mutex; SequencerBase& SequencerBase::Instance() { // not initialized? - if (SequencerP::_instances.size() == 0) { + if (SequencerP::_instances.empty()) { new ConsoleSequencer(); } diff --git a/src/Base/Stream.cpp b/src/Base/Stream.cpp index d32ff3df51..b3121ccfee 100644 --- a/src/Base/Stream.cpp +++ b/src/Base/Stream.cpp @@ -602,7 +602,7 @@ PyStreambuf::int_type PyStreambuf::underflow() return traits_type::eof(); } - std::memcpy(start, &(c[0]), c.size()); + std::memcpy(start, c.data(), c.size()); } catch (Py::Exception& e) { e.clear(); @@ -666,31 +666,29 @@ bool PyStreambuf::writeStr(const char* str, std::streamsize num) meth.apply(arg); return true; } - else if (type == BytesIO) { + if (type == BytesIO) { arg.setItem(0, Py::Bytes(str, num)); meth.apply(arg); return true; } - else { - // try out what works - try { - arg.setItem(0, Py::String(str, num)); + + // try out what works + try { + arg.setItem(0, Py::String(str, num)); + meth.apply(arg); + type = StringIO; + return true; + } + catch (Py::Exception& e) { + if (PyErr_ExceptionMatches(PyExc_TypeError)) { + e.clear(); + arg.setItem(0, Py::Bytes(str, num)); meth.apply(arg); - type = StringIO; + type = BytesIO; return true; } - catch (Py::Exception& e) { - if (PyErr_ExceptionMatches(PyExc_TypeError)) { - e.clear(); - arg.setItem(0, Py::Bytes(str, num)); - meth.apply(arg); - type = BytesIO; - return true; - } - else { - throw; // re-throw - } - } + + throw; // re-throw } } catch (Py::Exception& e) { diff --git a/src/Base/Stream.h b/src/Base/Stream.h index e7664211a3..511989d6b4 100644 --- a/src/Base/Stream.h +++ b/src/Base/Stream.h @@ -154,12 +154,12 @@ public: ~ByteArrayOStreambuf() override; protected: - int_type overflow(std::streambuf::int_type v) override; + int_type overflow(std::streambuf::int_type c) override; std::streamsize xsputn(const char* s, std::streamsize num) override; pos_type seekoff(std::streambuf::off_type off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios::in | std::ios::out) override; - pos_type seekpos(std::streambuf::pos_type sp, + pos_type seekpos(std::streambuf::pos_type pos, std::ios_base::openmode which = std::ios::in | std::ios::out) override; public: @@ -180,7 +180,7 @@ private: class BaseExport ByteArrayIStreambuf: public std::streambuf { public: - explicit ByteArrayIStreambuf(const QByteArray& buf); + explicit ByteArrayIStreambuf(const QByteArray& data); ~ByteArrayIStreambuf() override; protected: @@ -217,12 +217,12 @@ public: ~IODeviceOStreambuf() override; protected: - int_type overflow(std::streambuf::int_type v) override; + int_type overflow(std::streambuf::int_type c) override; std::streamsize xsputn(const char* s, std::streamsize num) override; pos_type seekoff(std::streambuf::off_type off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios::in | std::ios::out) override; - pos_type seekpos(std::streambuf::pos_type sp, + pos_type seekpos(std::streambuf::pos_type pos, std::ios_base::openmode which = std::ios::in | std::ios::out) override; public: @@ -251,7 +251,7 @@ protected: pos_type seekoff(std::streambuf::off_type off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios::in | std::ios::out) override; - pos_type seekpos(std::streambuf::pos_type sp, + pos_type seekpos(std::streambuf::pos_type pos, std::ios_base::openmode which = std::ios::in | std::ios::out) override; public: diff --git a/src/Base/TimeInfo.h b/src/Base/TimeInfo.h index 084dddd2f2..482c8452b6 100644 --- a/src/Base/TimeInfo.h +++ b/src/Base/TimeInfo.h @@ -126,9 +126,7 @@ inline bool TimeInfo::operator<(const TimeInfo& time) const if (timebuffer.time == time.timebuffer.time) { return timebuffer.millitm < time.timebuffer.millitm; } - else { - return timebuffer.time < time.timebuffer.time; - } + return timebuffer.time < time.timebuffer.time; } inline bool TimeInfo::operator<=(const TimeInfo& time) const @@ -136,9 +134,7 @@ inline bool TimeInfo::operator<=(const TimeInfo& time) const if (timebuffer.time == time.timebuffer.time) { return timebuffer.millitm <= time.timebuffer.millitm; } - else { - return timebuffer.time <= time.timebuffer.time; - } + return timebuffer.time <= time.timebuffer.time; } inline bool TimeInfo::operator>=(const TimeInfo& time) const @@ -146,9 +142,7 @@ inline bool TimeInfo::operator>=(const TimeInfo& time) const if (timebuffer.time == time.timebuffer.time) { return timebuffer.millitm >= time.timebuffer.millitm; } - else { - return timebuffer.time >= time.timebuffer.time; - } + return timebuffer.time >= time.timebuffer.time; } inline bool TimeInfo::operator>(const TimeInfo& time) const @@ -156,9 +150,7 @@ inline bool TimeInfo::operator>(const TimeInfo& time) const if (timebuffer.time == time.timebuffer.time) { return timebuffer.millitm > time.timebuffer.millitm; } - else { - return timebuffer.time > time.timebuffer.time; - } + return timebuffer.time > time.timebuffer.time; } } // namespace Base diff --git a/src/Base/Tools.cpp b/src/Base/Tools.cpp index 224c123ba9..a764c0c5e8 100644 --- a/src/Base/Tools.cpp +++ b/src/Base/Tools.cpp @@ -43,12 +43,11 @@ struct string_comp if (s1.size() < s2.size()) { return true; } - else if (s1.size() > s2.size()) { + if (s1.size() > s2.size()) { return false; } - else { - return s1 < s2; - } + + return s1 < s2; } static std::string increment(const std::string& s) { @@ -105,7 +104,7 @@ private: for (const auto& name : names) { if (name.substr(0, base_name.length()) == base_name) { // same prefix std::string suffix(name.substr(base_name.length())); - if (suffix.size() > 0) { + if (!suffix.empty()) { std::string::size_type pos = suffix.find_first_not_of("0123456789"); if (pos == std::string::npos) { num_suffix = std::max(num_suffix, suffix, Base::string_comp()); diff --git a/src/Base/Tools.h b/src/Base/Tools.h index 2f637db067..7559bff920 100644 --- a/src/Base/Tools.h +++ b/src/Base/Tools.h @@ -116,9 +116,8 @@ inline T sgn(T t) if (t == 0) { return T(0); } - else { - return (t > 0) ? T(1) : T(-1); - } + + return (t > 0) ? T(1) : T(-1); } #ifndef M_PI diff --git a/src/Base/Tools2D.cpp b/src/Base/Tools2D.cpp index cc68068170..3e12de6a58 100644 --- a/src/Base/Tools2D.cpp +++ b/src/Base/Tools2D.cpp @@ -33,34 +33,32 @@ using namespace Base; -double Vector2d::GetAngle(const Vector2d& rclVect) const +double Vector2d::GetAngle(const Vector2d& vec) const { double fDivid = 0.0, fNum = 0.0; - fDivid = Length() * rclVect.Length(); + fDivid = Length() * vec.Length(); if ((fDivid < -1e-10) || (fDivid > 1e-10)) { - fNum = (*this * rclVect) / fDivid; + fNum = (*this * vec) / fDivid; if (fNum < -1) { return D_PI; } - else if (fNum > 1) { + if (fNum > 1) { return 0.0; } - else { - return acos(fNum); - } - } - else { - return -FLOAT_MAX; // division by zero + + return acos(fNum); } + + return -FLOAT_MAX; // division by zero } -void Vector2d::ProjectToLine(const Vector2d& rclPt, const Vector2d& rclLine) +void Vector2d::ProjectToLine(const Vector2d& point, const Vector2d& line) { - double l = rclLine.Length(); - double t1 = (rclPt * rclLine) / l; - Vector2d clNormal = rclLine; + double l = line.Length(); + double t1 = (point * line) / l; + Vector2d clNormal = line; clNormal.Normalize(); clNormal.Scale(t1); *this = clNormal; @@ -103,30 +101,20 @@ bool BoundBox2d::Intersect(const Line2d& rclLine) const clThisLine.clV1 = clThisLine.clV2; clThisLine.clV2.x = MinX; clThisLine.clV2.y = MinY; - if (clThisLine.IntersectAndContain(rclLine, clVct)) { - return true; - } - - return false; + return (clThisLine.IntersectAndContain(rclLine, clVct)); } bool BoundBox2d::Intersect(const BoundBox2d& rclBB) const { - if (MinX < rclBB.MaxX && rclBB.MinX < MaxX && MinY < rclBB.MaxY && rclBB.MinY < MaxY) { - return true; - } - else { // no intersection - return false; - } + return (MinX < rclBB.MaxX && rclBB.MinX < MaxX && MinY < rclBB.MaxY && rclBB.MinY < MaxY); } bool BoundBox2d::Intersect(const Polygon2d& rclPoly) const { - unsigned long i = 0; Line2d clLine; // points contained in boundbox - for (i = 0; i < rclPoly.GetCtVectors(); i++) { + for (unsigned long i = 0; i < rclPoly.GetCtVectors(); i++) { if (Contains(rclPoly[i])) { return true; /***** RETURN INTERSECTION *********/ } @@ -142,7 +130,7 @@ bool BoundBox2d::Intersect(const Polygon2d& rclPoly) const if (rclPoly.GetCtVectors() < 3) { return false; } - for (i = 0; i < rclPoly.GetCtVectors(); i++) { + for (unsigned long i = 0; i < rclPoly.GetCtVectors(); i++) { if (i == rclPoly.GetCtVectors() - 1) { clLine.clV1 = rclPoly[i]; clLine.clV2 = rclPoly[0]; @@ -231,10 +219,7 @@ bool Line2d::Intersect(const Vector2d& rclV, double eps) const // point is on line but it is also between V1 and V2? double dot = dxc * dxl + dyc * dyl; double len = dxl * dxl + dyl * dyl; - if (dot < -eps || dot > len + eps) { - return false; - } - return true; + return (dot >= -eps && dot <= len + eps); } Vector2d Line2d::FromPos(double fDistance) const @@ -390,7 +375,7 @@ void Polygon2d::Intersect(const Polygon2d& rclPolygon, } } - if (afIntersections.size() > 0) // intersections founded + if (!afIntersections.empty()) // intersections founded { for (double it : afIntersections) { // intersection point diff --git a/src/Base/Tools2D.h b/src/Base/Tools2D.h index c4538d1aa8..a61c9e7526 100644 --- a/src/Base/Tools2D.h +++ b/src/Base/Tools2D.h @@ -93,7 +93,7 @@ public: inline double Distance(const Vector2d& v) const; inline bool IsEqual(const Vector2d& v, double tolerance = 0.0) const; - double GetAngle(const Vector2d& v) const; + double GetAngle(const Vector2d& vec) const; void ProjectToLine(const Vector2d& point, const Vector2d& line); }; @@ -198,7 +198,7 @@ public: BoundBox2d CalcBoundBox() const; bool Contains(const Vector2d& rclV) const; void Intersect(const Polygon2d& rclPolygon, std::list& rclResultPolygonList) const; - bool Intersect(const Polygon2d& rclPolygon) const; + bool Intersect(const Polygon2d& other) const; bool Intersect(const Vector2d& rclV, double eps) const; private: diff --git a/src/Base/Type.cpp b/src/Base/Type.cpp index ed74e1af05..f137ba55bf 100644 --- a/src/Base/Type.cpp +++ b/src/Base/Type.cpp @@ -119,7 +119,7 @@ Type Type::badType() } -const Type Type::createType(const Type& parent, const char* name, instantiationMethod method) +Type Type::createType(const Type& parent, const char* name, instantiationMethod method) { Type newType; newType.index = static_cast(Type::typedata.size()); @@ -135,7 +135,7 @@ const Type Type::createType(const Type& parent, const char* name, instantiationM void Type::init() { - assert(Type::typedata.size() == 0); + assert(Type::typedata.empty()); Type::typedata.push_back(new TypeData("BadType")); @@ -160,9 +160,8 @@ Type Type::fromName(const char* name) if (pos != typemap.end()) { return typedata[pos->second]->type; } - else { - return Type::badType(); - } + + return Type::badType(); } Type Type::fromKey(unsigned int key) @@ -170,9 +169,8 @@ Type Type::fromKey(unsigned int key) if (key < typedata.size()) { return typedata[key]->type; } - else { - return Type::badType(); - } + + return Type::badType(); } const char* Type::getName() const @@ -180,7 +178,7 @@ const char* Type::getName() const return typedata[index]->name.c_str(); } -const Type Type::getParent() const +Type Type::getParent() const { return typedata[index]->parent; } @@ -228,7 +226,6 @@ Type Type::getTypeIfDerivedFrom(const char* name, const Type& parent, bool bLoad if (type.isDerivedFrom(parent)) { return type; } - else { - return Type::badType(); - } + + return Type::badType(); } diff --git a/src/Base/Type.h b/src/Base/Type.h index 5bfce4f194..cf138ade2f 100644 --- a/src/Base/Type.h +++ b/src/Base/Type.h @@ -98,7 +98,7 @@ public: static Type fromName(const char* name); static Type fromKey(unsigned int key); const char* getName() const; - const Type getParent() const; + Type getParent() const; bool isDerivedFrom(const Type& type) const; static int getAllDerivedFrom(const Type& type, std::vector& List); @@ -108,7 +108,7 @@ public: static int getNumTypes(); - static const Type + static Type createType(const Type& parent, const char* name, instantiationMethod method = nullptr); unsigned int getKey() const; diff --git a/src/Base/TypePyImp.cpp b/src/Base/TypePyImp.cpp index 3d4b6b397a..d8e9016407 100644 --- a/src/Base/TypePyImp.cpp +++ b/src/Base/TypePyImp.cpp @@ -176,7 +176,7 @@ PyObject* TypePy::getAllDerived(PyObject* args) namespace { -static void deallocPyObject(PyObject* py) +void deallocPyObject(PyObject* py) { Base::PyObjectBase* pybase = static_cast(py); Base::BaseClass* base = static_cast(pybase->getTwinPointer()); @@ -188,7 +188,7 @@ static void deallocPyObject(PyObject* py) Base::PyObjectBase::PyDestructor(py); } -static PyObject* createPyObject(Base::BaseClass* base) +PyObject* createPyObject(Base::BaseClass* base) { PyObject* py = base->getPyObject(); diff --git a/src/Base/UnitsApi.cpp b/src/Base/UnitsApi.cpp index ed3c20acef..eb25c42e4d 100644 --- a/src/Base/UnitsApi.cpp +++ b/src/Base/UnitsApi.cpp @@ -182,10 +182,10 @@ QString UnitsApi::schemaTranslate(const Base::Quantity& quant, double& factor, Q return UserPrefSystem->schemaTranslate(quant, factor, unitString); } -double UnitsApi::toDouble(PyObject* ArgObj, const Base::Unit& u) +double UnitsApi::toDouble(PyObject* args, const Base::Unit& u) { - if (PyUnicode_Check(ArgObj)) { - QString str = QString::fromUtf8(PyUnicode_AsUTF8(ArgObj)); + if (PyUnicode_Check(args)) { + QString str = QString::fromUtf8(PyUnicode_AsUTF8(args)); // Parse the string Quantity q = Quantity::parse(str); if (q.getUnit() == u) { @@ -193,31 +193,30 @@ double UnitsApi::toDouble(PyObject* ArgObj, const Base::Unit& u) } throw Base::UnitsMismatchError("Wrong unit type!"); } - else if (PyFloat_Check(ArgObj)) { - return PyFloat_AsDouble(ArgObj); + if (PyFloat_Check(args)) { + return PyFloat_AsDouble(args); } - else if (PyLong_Check(ArgObj)) { - return static_cast(PyLong_AsLong(ArgObj)); - } - else { - throw Base::UnitsMismatchError("Wrong parameter type!"); + if (PyLong_Check(args)) { + return static_cast(PyLong_AsLong(args)); } + + throw Base::UnitsMismatchError("Wrong parameter type!"); } -Quantity UnitsApi::toQuantity(PyObject* ArgObj, const Base::Unit& u) +Quantity UnitsApi::toQuantity(PyObject* args, const Base::Unit& u) { double d {}; - if (PyUnicode_Check(ArgObj)) { - QString str = QString::fromUtf8(PyUnicode_AsUTF8(ArgObj)); + if (PyUnicode_Check(args)) { + QString str = QString::fromUtf8(PyUnicode_AsUTF8(args)); // Parse the string Quantity q = Quantity::parse(str); d = q.getValue(); } - else if (PyFloat_Check(ArgObj)) { - d = PyFloat_AsDouble(ArgObj); + else if (PyFloat_Check(args)) { + d = PyFloat_AsDouble(args); } - else if (PyLong_Check(ArgObj)) { - d = static_cast(PyLong_AsLong(ArgObj)); + else if (PyLong_Check(args)) { + d = static_cast(PyLong_AsLong(args)); } else { throw Base::UnitsMismatchError("Wrong parameter type!"); diff --git a/src/Base/UnitsApi.h b/src/Base/UnitsApi.h index 1837bae019..66a0e18487 100644 --- a/src/Base/UnitsApi.h +++ b/src/Base/UnitsApi.h @@ -87,7 +87,7 @@ public: * needed represented in scientific notation. The string doesn't include the unit of the * quantity. */ - static QString toNumber(double d, + static QString toNumber(double value, const QuantityFormat& f = QuantityFormat(QuantityFormat::Default)); /// generate a value for a quantity with default user preferred system diff --git a/src/Base/UnitsApiPy.cpp b/src/Base/UnitsApiPy.cpp index ab14bebada..ba14c0726f 100644 --- a/src/Base/UnitsApiPy.cpp +++ b/src/Base/UnitsApiPy.cpp @@ -168,7 +168,7 @@ PyObject* UnitsApi::sSchemaTranslate(PyObject* /*self*/, PyObject* args) quant = *static_cast(py)->getQuantityPtr(); std::unique_ptr schema(createSchema(static_cast(index))); - if (!schema.get()) { + if (!schema) { PyErr_SetString(PyExc_ValueError, "invalid schema value"); return nullptr; } diff --git a/src/Base/Vector3D.cpp b/src/Base/Vector3D.cpp index 2d0711ed28..99bce19ca3 100644 --- a/src/Base/Vector3D.cpp +++ b/src/Base/Vector3D.cpp @@ -434,7 +434,7 @@ _Precision Vector3<_Precision>::GetAngle(const Vector3& rcVect) const if (dot <= -1.0) { return traits_type::pi(); } - else if (dot >= 1.0) { + if (dot >= 1.0) { return 0.0; } diff --git a/src/Base/ViewProj.h b/src/Base/ViewProj.h index 846972cd4d..b4460f9e16 100644 --- a/src/Base/ViewProj.h +++ b/src/Base/ViewProj.h @@ -80,10 +80,10 @@ class BaseExport ViewProjMatrix: public ViewProjMethod public: ViewProjMatrix(const Matrix4D& rclMtx); - Vector3f operator()(const Vector3f& rclPt) const override; - Vector3d operator()(const Vector3d& rclPt) const override; - Vector3f inverse(const Vector3f& rclPt) const override; - Vector3d inverse(const Vector3d& rclPt) const override; + Vector3f operator()(const Vector3f& inp) const override; + Vector3d operator()(const Vector3d& inp) const override; + Vector3f inverse(const Vector3f& src) const override; + Vector3d inverse(const Vector3d& src) const override; Matrix4D getProjectionMatrix() const override; diff --git a/src/Base/Writer.cpp b/src/Base/Writer.cpp index b30926ab87..58c277cf12 100644 --- a/src/Base/Writer.cpp +++ b/src/Base/Writer.cpp @@ -162,8 +162,8 @@ void Writer::insertBinFile(const char* FileName) from.seekg(0, std::ios::beg); std::vector bytes(static_cast(fileSize)); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - from.read(reinterpret_cast(&bytes[0]), fileSize); - Stream() << Base::base64_encode(&bytes[0], static_cast(fileSize)); + from.read(reinterpret_cast(bytes.data()), fileSize); + Stream() << Base::base64_encode(bytes.data(), static_cast(fileSize)); Stream() << "]]>" << endl; } @@ -269,26 +269,27 @@ std::string Writer::getUniqueFileName(const char* Name) // if not, name is OK return CleanName; } - else { - std::vector names; - names.reserve(FileNames.size()); - FileInfo fi(CleanName); - CleanName = fi.fileNamePure(); - std::string ext = fi.extension(); - for (pos = FileNames.begin(); pos != FileNames.end(); ++pos) { - fi.setFile(*pos); - std::string FileName = fi.fileNamePure(); - if (fi.extension() == ext) { - names.push_back(FileName); - } + + std::vector names; + names.reserve(FileNames.size()); + FileInfo fi(CleanName); + CleanName = fi.fileNamePure(); + std::string ext = fi.extension(); + for (pos = FileNames.begin(); pos != FileNames.end(); ++pos) { + fi.setFile(*pos); + std::string FileName = fi.fileNamePure(); + if (fi.extension() == ext) { + names.push_back(FileName); } - std::stringstream str; - str << Base::Tools::getUniqueName(CleanName, names); - if (!ext.empty()) { - str << "." << ext; - } - return str.str(); } + + std::stringstream str; + str << Base::Tools::getUniqueName(CleanName, names); + if (!ext.empty()) { + str << "." << ext; + } + + return str.str(); } const std::vector& Writer::getFilenames() const diff --git a/src/Base/XMLTools.cpp b/src/Base/XMLTools.cpp index 2fec3b5e3d..a9f780e407 100644 --- a/src/Base/XMLTools.cpp +++ b/src/Base/XMLTools.cpp @@ -32,7 +32,7 @@ std::unique_ptr XMLTools::transcoder; void XMLTools::initialize() { - if (!transcoder.get()) { + if (!transcoder) { XMLTransService::Codes res {}; transcoder.reset(XMLPlatformUtils::fgTransService->makeNewTranscoderFor( XMLRecognizer::UTF_8, diff --git a/src/Base/ZipHeader.cpp b/src/Base/ZipHeader.cpp index b0660eaad8..b3273810d5 100644 --- a/src/Base/ZipHeader.cpp +++ b/src/Base/ZipHeader.cpp @@ -68,12 +68,11 @@ std::istream* ZipHeader::getInputStream(const std::string& entry_name, MatchPath if (!ent) { return nullptr; } - else { - return new zipios::ZipInputStream( - _input, - static_cast(ent.get())->getLocalHeaderOffset() - + _vs.startOffset()); - } + + return new zipios::ZipInputStream( + _input, + static_cast(ent.get())->getLocalHeaderOffset() + + _vs.startOffset()); } bool ZipHeader::init(std::istream& _zipfile) @@ -110,11 +109,11 @@ bool ZipHeader::readCentralDirectory(std::istream& _zipfile) throw zipios::IOException( "Error reading zip file while reading zip file central directory"); } - else if (_zipfile.fail()) { + if (_zipfile.fail()) { throw zipios::FCollException("Zip file consistency problem. Failure while reading " "zip file central directory"); } - else if (_zipfile.eof()) { + if (_zipfile.eof()) { throw zipios::IOException( "Premature end of file while reading zip file central directory"); }