From 88e542b34591d79c51d5aaa91fc0aa59e63b46e8 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Wed, 28 Oct 2020 10:29:08 +0100 Subject: [PATCH] Part: Geometry extensions constness correction --- src/Mod/Part/App/Geometry.cpp | 8 ++++---- src/Mod/Part/App/Geometry.h | 6 +++--- src/Mod/Part/App/GeometryPyImp.cpp | 13 +++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 9276f242d4..3a45e99a24 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -258,9 +258,9 @@ boost::uuids::uuid Geometry::getTag() const return tag; } -const std::vector> Geometry::getExtensions() const +std::vector> Geometry::getExtensions() const { - std::vector> wp; + std::vector> wp; for(auto & ext:extensions) wp.push_back(ext); @@ -288,7 +288,7 @@ bool Geometry::hasExtension(std::string name) const return false; } -const std::weak_ptr Geometry::getExtension(Base::Type type) const +std::weak_ptr Geometry::getExtension(Base::Type type) const { for( auto ext : extensions) { if(ext->getTypeId() == type) @@ -298,7 +298,7 @@ const std::weak_ptr Geometry::getExtension(Base::Type type) c throw Base::ValueError("No geometry extension of the requested type."); } -const std::weak_ptr Geometry::getExtension(std::string name) const +std::weak_ptr Geometry::getExtension(std::string name) const { for( auto ext : extensions) { if(ext->getName() == name) diff --git a/src/Mod/Part/App/Geometry.h b/src/Mod/Part/App/Geometry.h index 2d7e3c0a93..12c57bee60 100644 --- a/src/Mod/Part/App/Geometry.h +++ b/src/Mod/Part/App/Geometry.h @@ -101,12 +101,12 @@ public: /// returns the tag of the geometry object boost::uuids::uuid getTag() const; - const std::vector> getExtensions() const; + std::vector> getExtensions() const; bool hasExtension(Base::Type type) const; bool hasExtension(std::string name) const; - const std::weak_ptr getExtension(Base::Type type) const; - const std::weak_ptr getExtension(std::string name) const; + std::weak_ptr getExtension(Base::Type type) const; + std::weak_ptr getExtension(std::string name) const; void setExtension(std::unique_ptr &&geo); void deleteExtension(Base::Type type); void deleteExtension(std::string name); diff --git a/src/Mod/Part/App/GeometryPyImp.cpp b/src/Mod/Part/App/GeometryPyImp.cpp index ef1025f77f..c621036f8e 100644 --- a/src/Mod/Part/App/GeometryPyImp.cpp +++ b/src/Mod/Part/App/GeometryPyImp.cpp @@ -245,10 +245,10 @@ PyObject* GeometryPy::getExtensionOfType(PyObject *args) if(type != Base::Type::badType()) { try { - std::shared_ptr ext(this->getGeometryPtr()->getExtension(type)); + std::shared_ptr ext(this->getGeometryPtr()->getExtension(type)); // we create a copy and transfer this copy's memory management responsibility to Python - PyObject* cpy = static_cast(ext->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); return cpy; } @@ -279,10 +279,10 @@ PyObject* GeometryPy::getExtensionOfName(PyObject *args) if (PyArg_ParseTuple(args, "s", &o)) { try { - std::shared_ptr ext(this->getGeometryPtr()->getExtension(std::string(o))); + std::shared_ptr ext(this->getGeometryPtr()->getExtension(std::string(o))); // we create a copy and transfer this copy's memory management responsibility to Python - PyObject* cpy = static_cast(ext->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); + PyObject* cpy = static_cast(std::const_pointer_cast(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0)))); return cpy; } @@ -404,7 +404,7 @@ PyObject* GeometryPy::getExtensions(PyObject *args) } try { - const std::vector> ext = this->getGeometryPtr()->getExtensions(); + const std::vector> ext = this->getGeometryPtr()->getExtensions(); PyObject* list = PyList_New(ext.size()); @@ -412,7 +412,8 @@ PyObject* GeometryPy::getExtensions(PyObject *args) for (std::size_t i=0; i p = ext[i].lock(); + // const casting only to get the Python object to make a copy + std::shared_ptr p = std::const_pointer_cast(ext[i].lock()); if(p) { // we create a python copy and add it to the list