From 16c86a6d089197da8de2275cdb5737b21da1600d Mon Sep 17 00:00:00 2001 From: Uwe Date: Mon, 18 Jul 2022 02:51:49 +0200 Subject: [PATCH] [Sketch] remove superfluous nullptr checks --- src/Mod/Sketcher/App/ConstraintPyImp.cpp | 16 ++++++++-------- src/Mod/Sketcher/App/ExternalGeometryFacade.cpp | 8 ++++---- src/Mod/Sketcher/App/GeometryFacade.cpp | 10 +++++----- src/Mod/Sketcher/App/GeometryFacade.h | 4 ++-- src/Mod/Sketcher/App/Sketch.cpp | 4 ++-- src/Mod/Sketcher/App/SketchAnalysis.cpp | 2 +- src/Mod/Sketcher/App/SketchObject.cpp | 4 ++-- src/Mod/Sketcher/Gui/Command.cpp | 4 ++-- .../Sketcher/Gui/DrawSketchHandlerCarbonCopy.h | 2 +- src/Mod/Sketcher/Gui/DrawSketchHandlerExternal.h | 2 +- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 2 +- src/Mod/Sketcher/Gui/SoDatumLabel.cpp | 2 +- 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Mod/Sketcher/App/ConstraintPyImp.cpp b/src/Mod/Sketcher/App/ConstraintPyImp.cpp index fe7942c590..2992e1f7da 100644 --- a/src/Mod/Sketcher/App/ConstraintPyImp.cpp +++ b/src/Mod/Sketcher/App/ConstraintPyImp.cpp @@ -105,13 +105,13 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) this->getConstraintPtr()->Type = Equal; valid = true; } - else if (strstr(ConstraintType,"InternalAlignment") != nullptr) { + else if (strstr(ConstraintType,"InternalAlignment")) { this->getConstraintPtr()->Type = InternalAlignment; valid = true; - if(strstr(ConstraintType,"EllipseMajorDiameter") != nullptr) + if(strstr(ConstraintType,"EllipseMajorDiameter")) this->getConstraintPtr()->AlignmentType=EllipseMajorDiameter; - else if(strstr(ConstraintType,"EllipseMinorDiameter") != nullptr) + else if(strstr(ConstraintType,"EllipseMinorDiameter")) this->getConstraintPtr()->AlignmentType=EllipseMinorDiameter; else { this->getConstraintPtr()->AlignmentType=Undef; @@ -198,14 +198,14 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) this->getConstraintPtr()->Type = PointOnObject; valid = true; } - else if (strstr(ConstraintType,"InternalAlignment") != nullptr) { + else if (strstr(ConstraintType,"InternalAlignment")) { this->getConstraintPtr()->Type = InternalAlignment; valid = true; - if(strstr(ConstraintType,"EllipseFocus1") != nullptr) + if(strstr(ConstraintType,"EllipseFocus1")) this->getConstraintPtr()->AlignmentType=EllipseFocus1; - else if(strstr(ConstraintType,"EllipseFocus2") != nullptr) + else if(strstr(ConstraintType,"EllipseFocus2")) this->getConstraintPtr()->AlignmentType=EllipseFocus2; else { this->getConstraintPtr()->AlignmentType=Undef; @@ -313,12 +313,12 @@ int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/) this->getConstraintPtr()->ThirdPos = (Sketcher::PointPos) intArg4; return 0; } - else if (strstr(ConstraintType,"InternalAlignment") != nullptr) { // InteralAlignment with InternalElementIndex argument + else if (strstr(ConstraintType,"InternalAlignment")) { // InteralAlignment with InternalElementIndex argument this->getConstraintPtr()->Type = InternalAlignment; valid = true; - if(strstr(ConstraintType,"BSplineControlPoint") != nullptr) { + if(strstr(ConstraintType,"BSplineControlPoint")) { this->getConstraintPtr()->AlignmentType=BSplineControlPoint; } else { diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp b/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp index a60d60e464..341f4e7fff 100644 --- a/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp +++ b/src/Mod/Sketcher/App/ExternalGeometryFacade.cpp @@ -46,7 +46,7 @@ ExternalGeometryFacade::ExternalGeometryFacade(): Geo(nullptr), SketchGeoExtensi ExternalGeometryFacade::ExternalGeometryFacade(const Part::Geometry * geometry) : Geo(geometry) { - if(geometry != nullptr) + if(geometry) initExtensions(); else THROWM(Base::ValueError, "ExternalGeometryFacade initialized with Geometry null pointer"); @@ -54,7 +54,7 @@ ExternalGeometryFacade::ExternalGeometryFacade(const Part::Geometry * geometry) std::unique_ptr ExternalGeometryFacade::getFacade(Part::Geometry * geometry) { - if(geometry != nullptr) + if(geometry) return std::unique_ptr(new ExternalGeometryFacade(geometry)); else return std::unique_ptr(nullptr); @@ -62,7 +62,7 @@ std::unique_ptr ExternalGeometryFacade::getFacade(Part:: std::unique_ptr ExternalGeometryFacade::getFacade(const Part::Geometry * geometry) { - if(geometry != nullptr) + if(geometry) return std::unique_ptr(new ExternalGeometryFacade(geometry)); else return std::unique_ptr(nullptr); @@ -72,7 +72,7 @@ void ExternalGeometryFacade::setGeometry(Part::Geometry *geometry) { Geo = geometry; - if(geometry != nullptr) + if(geometry) initExtensions(); else THROWM(Base::ValueError, "ExternalGeometryFacade initialized with Geometry null pointer"); diff --git a/src/Mod/Sketcher/App/GeometryFacade.cpp b/src/Mod/Sketcher/App/GeometryFacade.cpp index e86baed471..3aae5fd0e4 100644 --- a/src/Mod/Sketcher/App/GeometryFacade.cpp +++ b/src/Mod/Sketcher/App/GeometryFacade.cpp @@ -53,13 +53,13 @@ GeometryFacade::GeometryFacade(const Part::Geometry * geometry, bool owner) GeometryFacade::~GeometryFacade() { - if (OwnerGeo && Geo != nullptr) + if (OwnerGeo && Geo) delete Geo; } std::unique_ptr GeometryFacade::getFacade(Part::Geometry * geometry, bool owner) { - if(geometry != nullptr) + if(geometry) return std::unique_ptr(new GeometryFacade(geometry, owner)); else return std::unique_ptr(nullptr); @@ -68,7 +68,7 @@ std::unique_ptr GeometryFacade::getFacade(Part::Geometry * geome std::unique_ptr GeometryFacade::getFacade(const Part::Geometry * geometry) { - if(geometry != nullptr) + if(geometry) return std::unique_ptr(new GeometryFacade(geometry)); else return std::unique_ptr(nullptr); @@ -79,7 +79,7 @@ void GeometryFacade::setGeometry(Part::Geometry *geometry) { Geo = geometry; - if(geometry != nullptr) + if(geometry) initExtension(); else THROWM(Base::ValueError, "GeometryFacade initialized with Geometry null pointer"); @@ -113,7 +113,7 @@ void GeometryFacade::initExtension() const void GeometryFacade::throwOnNullPtr(const Part::Geometry * geo) { - if(geo == nullptr) + if(!geo) THROWM(Base::ValueError, "Geometry is nullptr!"); } diff --git a/src/Mod/Sketcher/App/GeometryFacade.h b/src/Mod/Sketcher/App/GeometryFacade.h index 4ca789bdbb..f7a7479a42 100644 --- a/src/Mod/Sketcher/App/GeometryFacade.h +++ b/src/Mod/Sketcher/App/GeometryFacade.h @@ -271,13 +271,13 @@ class SketcherExport GeometryTypedFacade : public GeometryFacade public: // Factory methods static std::unique_ptr> getTypedFacade(GeometryT * geometry, bool owner = false) { - if(geometry != nullptr) + if(geometry) return std::unique_ptr>(new GeometryTypedFacade(geometry, owner)); else return std::unique_ptr>(nullptr); } static std::unique_ptr> getTypedFacade(const GeometryT * geometry) { - if(geometry != nullptr) + if(geometry) return std::unique_ptr>(new GeometryTypedFacade(geometry)); else return std::unique_ptr>(nullptr); diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index 0ff1ff38a0..6a44465f77 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -416,7 +416,7 @@ bool Sketch::analyseBlockedConstraintDependentParameters(std::vector &block continue; } // 4.2. satisfiable and not satisfied - if(prop_groups[i].blocking_param_in_group == nullptr) { + if(!prop_groups[i].blocking_param_in_group) { unsatisfied_groups = true; } } @@ -2677,7 +2677,7 @@ int Sketch::addAngleConstraint(int geoId1, PointPos pos1, int geoId2, PointPos p l2p2 = &Points[Geoms[geoId2].startPointId]; } - if (l1p1 == nullptr || l2p1 == nullptr) + if (!l1p1 || !l2p1) return -1; int tag = ++ConstraintsCounter; diff --git a/src/Mod/Sketcher/App/SketchAnalysis.cpp b/src/Mod/Sketcher/App/SketchAnalysis.cpp index 91d8082bac..1da74374a4 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.cpp +++ b/src/Mod/Sketcher/App/SketchAnalysis.cpp @@ -295,7 +295,7 @@ int SketchAnalysis::detectMissingPointOnPointConstraints(double precision, bool std::set *tempGrp = nullptr; for (auto it = coincVertexGrps.begin(); it < coincVertexGrps.end(); ++it) { if ( (it->find(v1) != it->end()) || (it->find(v2) != it->end()) ) { - if (tempGrp == nullptr) { + if (!tempGrp) { tempGrp = &*it; } else { diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index fdd946fc2a..69e6b398b1 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -3343,7 +3343,7 @@ bool SketchObject::isExternalAllowed(App::Document *pDoc, App::DocumentObject *p App::Part* part_this = App::Part::getPartOfObject(this); App::Part* part_obj = App::Part::getPartOfObject(pObj); if (part_this == part_obj){ //either in the same part, or in the root of document - if (body_this == nullptr) { + if (!body_this) { return true; } else if (body_this == body_obj) { return true; @@ -3402,7 +3402,7 @@ bool SketchObject::isCarbonCopyAllowed(App::Document *pDoc, App::DocumentObject App::Part* part_this = App::Part::getPartOfObject(this); App::Part* part_obj = App::Part::getPartOfObject(pObj); if (part_this == part_obj){ //either in the same part, or in the root of document - if (body_this != nullptr) { + if (body_this) { if (body_this != body_obj) { if (!this->allowOtherBody) { if (rsn) diff --git a/src/Mod/Sketcher/Gui/Command.cpp b/src/Mod/Sketcher/Gui/Command.cpp index 69ff5b6128..0a6597b991 100644 --- a/src/Mod/Sketcher/Gui/Command.cpp +++ b/src/Mod/Sketcher/Gui/Command.cpp @@ -87,11 +87,11 @@ namespace SketcherGui { std::vector* allmodes = nullptr){ //convert pointers into valid references, to avoid checking for null pointers everywhere Attacher::SuggestResult::eSuggestResult buf; - if (pMsgId == nullptr) + if (!pMsgId) pMsgId = &buf; Attacher::SuggestResult::eSuggestResult &msg = *pMsgId; QString buf2; - if (message == nullptr) + if (!message) message = &buf2; QString &msg_str = *message; diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h index ef5ea909d9..5b3c0fef08 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerCarbonCopy.h @@ -124,7 +124,7 @@ public: { if (msg.Type == Gui::SelectionChanges::AddSelection) { App::DocumentObject* obj = sketchgui->getObject()->getDocument()->getObject(msg.pObjectName); - if (obj == nullptr) + if (!obj) throw Base::ValueError("Sketcher: Carbon Copy: Invalid object in selection"); if (obj->getTypeId() == Sketcher::SketchObject::getClassTypeId()) { diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerExternal.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerExternal.h index ea0738e8af..b0a7f25efa 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerExternal.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerExternal.h @@ -126,7 +126,7 @@ public: { if (msg.Type == Gui::SelectionChanges::AddSelection) { App::DocumentObject* obj = sketchgui->getObject()->getDocument()->getObject(msg.pObjectName); - if (obj == nullptr) + if (!obj) throw Base::ValueError("Sketcher: External geometry: Invalid object in selection"); std::string subName(msg.pSubName); if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) || diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 4314709036..68b7b6c532 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -85,7 +85,7 @@ void EditDatumDialog::exec(bool atCursor) Base::Quantity init_val; QDialog dlg(Gui::getMainWindow()); - if (ui_ins_datum == nullptr) { + if (!ui_ins_datum) { ui_ins_datum.reset(new Ui_InsertDatum); ui_ins_datum->setupUi(&dlg); } diff --git a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp index 8f0be3b09c..69b25dd7d8 100644 --- a/src/Mod/Sketcher/Gui/SoDatumLabel.cpp +++ b/src/Mod/Sketcher/Gui/SoDatumLabel.cpp @@ -458,7 +458,7 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action) } const unsigned char * dataptr = this->image.getValue(imgsize, nc); - if (dataptr == nullptr) // no image + if (!dataptr) // no image return; srcw = imgsize[0];