Skip to content

Commit

Permalink
Part: Geometry extensions constness correction
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahtahiriyo committed Nov 3, 2020
1 parent 33b4d00 commit 5b415f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/Mod/Part/App/Geometry.cpp
Expand Up @@ -258,9 +258,9 @@ boost::uuids::uuid Geometry::getTag() const
return tag;
}

const std::vector<std::weak_ptr<GeometryExtension>> Geometry::getExtensions() const
std::vector<std::weak_ptr<const GeometryExtension>> Geometry::getExtensions() const
{
std::vector<std::weak_ptr<GeometryExtension>> wp;
std::vector<std::weak_ptr<const GeometryExtension>> wp;

for(auto & ext:extensions)
wp.push_back(ext);
Expand Down Expand Up @@ -288,7 +288,7 @@ bool Geometry::hasExtension(std::string name) const
return false;
}

const std::weak_ptr<GeometryExtension> Geometry::getExtension(Base::Type type) const
std::weak_ptr<const GeometryExtension> Geometry::getExtension(Base::Type type) const
{
for( auto ext : extensions) {
if(ext->getTypeId() == type)
Expand All @@ -298,7 +298,7 @@ const std::weak_ptr<GeometryExtension> Geometry::getExtension(Base::Type type) c
throw Base::ValueError("No geometry extension of the requested type.");
}

const std::weak_ptr<GeometryExtension> Geometry::getExtension(std::string name) const
std::weak_ptr<const GeometryExtension> Geometry::getExtension(std::string name) const
{
for( auto ext : extensions) {
if(ext->getName() == name)
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/Part/App/Geometry.h
Expand Up @@ -101,12 +101,12 @@ class PartExport Geometry: public Base::Persistence
/// returns the tag of the geometry object
boost::uuids::uuid getTag() const;

const std::vector<std::weak_ptr<GeometryExtension>> getExtensions() const;
std::vector<std::weak_ptr<const GeometryExtension>> getExtensions() const;

bool hasExtension(Base::Type type) const;
bool hasExtension(std::string name) const;
const std::weak_ptr<GeometryExtension> getExtension(Base::Type type) const;
const std::weak_ptr<GeometryExtension> getExtension(std::string name) const;
std::weak_ptr<const GeometryExtension> getExtension(Base::Type type) const;
std::weak_ptr<const GeometryExtension> getExtension(std::string name) const;
void setExtension(std::unique_ptr<GeometryExtension> &&geo);
void deleteExtension(Base::Type type);
void deleteExtension(std::string name);
Expand Down
13 changes: 7 additions & 6 deletions src/Mod/Part/App/GeometryPyImp.cpp
Expand Up @@ -245,10 +245,10 @@ PyObject* GeometryPy::getExtensionOfType(PyObject *args)

if(type != Base::Type::badType()) {
try {
std::shared_ptr<GeometryExtension> ext(this->getGeometryPtr()->getExtension(type));
std::shared_ptr<const GeometryExtension> ext(this->getGeometryPtr()->getExtension(type));

// we create a copy and transfer this copy's memory management responsibility to Python
PyObject* cpy = static_cast<GeometryExtensionPy *>(ext->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0))));
PyObject* cpy = static_cast<GeometryExtensionPy *>(std::const_pointer_cast<GeometryExtension>(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0))));

return cpy;
}
Expand Down Expand Up @@ -279,10 +279,10 @@ PyObject* GeometryPy::getExtensionOfName(PyObject *args)
if (PyArg_ParseTuple(args, "s", &o)) {

try {
std::shared_ptr<GeometryExtension> ext(this->getGeometryPtr()->getExtension(std::string(o)));
std::shared_ptr<const GeometryExtension> 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<GeometryExtensionPy *>(ext->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0))));
PyObject* cpy = static_cast<GeometryExtensionPy *>(std::const_pointer_cast<GeometryExtension>(ext)->getPyObject())->copy(Py::new_reference_to(Py::Tuple(size_t(0))));

return cpy;
}
Expand Down Expand Up @@ -404,15 +404,16 @@ PyObject* GeometryPy::getExtensions(PyObject *args)
}

try {
const std::vector<std::weak_ptr<GeometryExtension>> ext = this->getGeometryPtr()->getExtensions();
const std::vector<std::weak_ptr<const GeometryExtension>> ext = this->getGeometryPtr()->getExtensions();

PyObject* list = PyList_New(ext.size());

Py::Tuple tuple(ext.size());

for (std::size_t i=0; i<ext.size(); ++i) {

std::shared_ptr<GeometryExtension> p = ext[i].lock();
// const casting only to get the Python object to make a copy
std::shared_ptr<GeometryExtension> p = std::const_pointer_cast<GeometryExtension>(ext[i].lock());

if(p) {
// we create a python copy and add it to the list
Expand Down

0 comments on commit 5b415f6

Please sign in to comment.