Part/Sketcher: Geometry/Geometry facade pass by const-reference instead of by value

This commit is contained in:
Abdullah Tahiri
2022-12-31 14:45:10 +01:00
committed by abdullahtahiriyo
parent b7945b6a15
commit 7fcee31c07
3 changed files with 20 additions and 16 deletions

View File

@@ -281,7 +281,7 @@ std::vector<std::weak_ptr<const GeometryExtension>> 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<GeometryExtension> Geometry::getExtension(Base::Type type)
std::weak_ptr<GeometryExtension> Geometry::getExtension(const Base::Type & type)
{
for(const auto& ext : extensions) {
if(ext->getTypeId() == type)
@@ -321,7 +321,7 @@ std::weak_ptr<GeometryExtension> Geometry::getExtension(const std::string & name
throw Base::ValueError("No geometry extension with the requested name.");
}
std::weak_ptr<const GeometryExtension> Geometry::getExtension(Base::Type type) const
std::weak_ptr<const GeometryExtension> Geometry::getExtension(const Base::Type & type) const
{
return const_cast<Geometry*>(this)->getExtension(type).lock();
}
@@ -353,7 +353,7 @@ void Geometry::setExtension(std::unique_ptr<GeometryExtension> && geoext )
}
}
void Geometry::deleteExtension(Base::Type type)
void Geometry::deleteExtension(const Base::Type & type)
{
extensions.erase(
std::remove_if( extensions.begin(),

View File

@@ -99,14 +99,14 @@ public:
std::vector<std::weak_ptr<const GeometryExtension>> 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<const GeometryExtension> getExtension(Base::Type type) const;
std::weak_ptr<const GeometryExtension> getExtension(const Base::Type & type) const;
std::weak_ptr<const GeometryExtension> getExtension(const std::string & name) const;
std::weak_ptr<GeometryExtension> getExtension(Base::Type type);
std::weak_ptr<GeometryExtension> getExtension(const Base::Type & type);
std::weak_ptr<GeometryExtension> getExtension(const std::string & name);
void setExtension(std::unique_ptr<GeometryExtension> &&geo);
void deleteExtension(Base::Type type);
void deleteExtension(const Base::Type & type);
void deleteExtension(const std::string & name);
void mirror(const Base::Vector3d& point);

View File

@@ -197,12 +197,12 @@ public:
boost::uuids::uuid getTag() const {return getGeo()->getTag();}
std::vector<std::weak_ptr<const Part::GeometryExtension>> 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<const Part::GeometryExtension> getExtension(Base::Type type) const {return getGeo()->getExtension(type);}
std::weak_ptr<const Part::GeometryExtension> getExtension(std::string name) const {return getGeo()->getExtension(name);}
std::weak_ptr<const Part::GeometryExtension> getExtension(const Base::Type & type) const {return getGeo()->getExtension(type);}
std::weak_ptr<const Part::GeometryExtension> getExtension(const std::string & name) const {return getGeo()->getExtension(name);}
void setExtension(std::unique_ptr<Part::GeometryExtension> &&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<GeometryTypedFacade<GeometryT>> getTypedFacade(GeometryT * geometry, bool owner = false) {
if(geometry)
if(geometry) {
return std::unique_ptr<GeometryTypedFacade<GeometryT>>(new GeometryTypedFacade(geometry, owner));
else
}
else {
return std::unique_ptr<GeometryTypedFacade<GeometryT>>(nullptr);
}
}
static std::unique_ptr<const GeometryTypedFacade<GeometryT>> getTypedFacade(const GeometryT * geometry) {
if(geometry)
if(geometry) {
return std::unique_ptr<const GeometryTypedFacade<GeometryT>>(new GeometryTypedFacade(geometry));
else
}
else {
return std::unique_ptr<const GeometryTypedFacade<GeometryT>>(nullptr);
}
}
// This function takes direct ownership of the object it creates.