From 7fcee31c074dba4dd19b3246fbff4f4976ea7910 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sat, 31 Dec 2022 14:45:10 +0100 Subject: [PATCH] Part/Sketcher: Geometry/Geometry facade pass by const-reference instead of by value --- src/Mod/Part/App/Geometry.cpp | 8 ++++---- src/Mod/Part/App/Geometry.h | 8 ++++---- src/Mod/Sketcher/App/GeometryFacade.h | 20 ++++++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 1e53e912fa..3a90630985 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -281,7 +281,7 @@ std::vector> Geometry::getExtensions() co return wp; } -bool Geometry::hasExtension(Base::Type type) const +bool Geometry::hasExtension(const Base::Type & type) const { for(const auto& ext : extensions) { if(ext->getTypeId() == type) @@ -301,7 +301,7 @@ bool Geometry::hasExtension(const std::string & name) const return false; } -std::weak_ptr Geometry::getExtension(Base::Type type) +std::weak_ptr Geometry::getExtension(const Base::Type & type) { for(const auto& ext : extensions) { if(ext->getTypeId() == type) @@ -321,7 +321,7 @@ std::weak_ptr Geometry::getExtension(const std::string & name throw Base::ValueError("No geometry extension with the requested name."); } -std::weak_ptr Geometry::getExtension(Base::Type type) const +std::weak_ptr Geometry::getExtension(const Base::Type & type) const { return const_cast(this)->getExtension(type).lock(); } @@ -353,7 +353,7 @@ void Geometry::setExtension(std::unique_ptr && geoext ) } } -void Geometry::deleteExtension(Base::Type type) +void Geometry::deleteExtension(const Base::Type & type) { extensions.erase( std::remove_if( extensions.begin(), diff --git a/src/Mod/Part/App/Geometry.h b/src/Mod/Part/App/Geometry.h index a8d3bb56b7..296e3223a4 100644 --- a/src/Mod/Part/App/Geometry.h +++ b/src/Mod/Part/App/Geometry.h @@ -99,14 +99,14 @@ public: std::vector> getExtensions() const; - bool hasExtension(Base::Type type) const; + bool hasExtension(const Base::Type & type) const; bool hasExtension(const std::string & name) const; - std::weak_ptr getExtension(Base::Type type) const; + std::weak_ptr getExtension(const Base::Type & type) const; std::weak_ptr getExtension(const std::string & name) const; - std::weak_ptr getExtension(Base::Type type); + std::weak_ptr getExtension(const Base::Type & type); std::weak_ptr getExtension(const std::string & name); void setExtension(std::unique_ptr &&geo); - void deleteExtension(Base::Type type); + void deleteExtension(const Base::Type & type); void deleteExtension(const std::string & name); void mirror(const Base::Vector3d& point); diff --git a/src/Mod/Sketcher/App/GeometryFacade.h b/src/Mod/Sketcher/App/GeometryFacade.h index 12b778f5bc..fbad3e111b 100644 --- a/src/Mod/Sketcher/App/GeometryFacade.h +++ b/src/Mod/Sketcher/App/GeometryFacade.h @@ -197,12 +197,12 @@ public: boost::uuids::uuid getTag() const {return getGeo()->getTag();} std::vector> getExtensions() const {return getGeo()->getExtensions();} - bool hasExtension(Base::Type type) const {return getGeo()->hasExtension(type);} + bool hasExtension(const Base::Type & type) const {return getGeo()->hasExtension(type);} bool hasExtension(const std::string & name) const {return getGeo()->hasExtension(name);} - std::weak_ptr getExtension(Base::Type type) const {return getGeo()->getExtension(type);} - std::weak_ptr getExtension(std::string name) const {return getGeo()->getExtension(name);} + std::weak_ptr getExtension(const Base::Type & type) const {return getGeo()->getExtension(type);} + std::weak_ptr getExtension(const std::string & name) const {return getGeo()->getExtension(name);} void setExtension(std::unique_ptr &&geo) {return getGeo()->setExtension(std::move(geo));} - void deleteExtension(Base::Type type) {return getGeo()->deleteExtension(type);} + void deleteExtension(const Base::Type & type) {return getGeo()->deleteExtension(type);} void deleteExtension(const std::string & name) {return getGeo()->deleteExtension(name);} void mirror(const Base::Vector3d & point) {return getGeo()->mirror(point);} @@ -272,16 +272,20 @@ class SketcherExport GeometryTypedFacade : public GeometryFacade public: // Factory methods static std::unique_ptr> getTypedFacade(GeometryT * geometry, bool owner = false) { - if(geometry) + if(geometry) { return std::unique_ptr>(new GeometryTypedFacade(geometry, owner)); - else + } + else { return std::unique_ptr>(nullptr); + } } static std::unique_ptr> getTypedFacade(const GeometryT * geometry) { - if(geometry) + if(geometry) { return std::unique_ptr>(new GeometryTypedFacade(geometry)); - else + } + else { return std::unique_ptr>(nullptr); + } } // This function takes direct ownership of the object it creates.