From ec73caa40e47e58be3a616b22e85faa471de1195 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 7 Aug 2023 20:01:45 +0200 Subject: [PATCH] modernize C++: make unique --- src/App/Document.cpp | 5 +- src/App/Expression.cpp | 12 ++-- src/App/PropertyExpressionEngine.cpp | 13 +++-- src/App/PropertyLinks.cpp | 2 +- src/Base/Parameter.cpp | 13 +++-- src/Base/ProgressIndicatorPy.cpp | 5 +- src/Gui/Action.cpp | 2 +- src/Gui/Command.cpp | 5 +- src/Gui/CommandView.cpp | 2 +- src/Gui/Tree.cpp | 4 +- src/Gui/ViewProviderLink.cpp | 13 +++-- src/Gui/ViewProviderPlacement.cpp | 2 +- src/Mod/Mesh/App/AppMeshPy.cpp | 6 +- src/Mod/Mesh/App/Exporter.cpp | 2 +- src/Mod/Mesh/App/Mesh.cpp | 2 +- src/Mod/Mesh/App/MeshPyImp.cpp | 2 +- src/Mod/Mesh/App/MeshTexture.cpp | 6 +- src/Mod/Part/App/BSplineCurvePyImp.cpp | 8 +-- src/Mod/Part/App/FaceMakerBullseye.cpp | 4 +- .../Part/App/Geom2d/BSplineCurve2dPyImp.cpp | 12 ++-- .../App/GeomPlate/CurveConstraintPyImp.cpp | 4 +- .../App/GeomPlate/PointConstraintPyImp.cpp | 2 +- src/Mod/Part/App/Geometry.cpp | 56 +++++++++---------- src/Mod/Part/App/Geometry2d.cpp | 30 +++++----- src/Mod/Part/Gui/SoBrepFaceSet.cpp | 2 +- src/Mod/Path/App/Area.cpp | 6 +- src/Mod/Points/App/AppPointsPy.cpp | 22 ++++---- src/Mod/Robot/App/Trajectory.cpp | 12 ++-- src/Mod/Spreadsheet/App/Cell.cpp | 2 +- src/Mod/Spreadsheet/App/Sheet.cpp | 2 +- 30 files changed, 134 insertions(+), 124 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 7ffd9efab3..ae41d3638d 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2757,8 +2757,9 @@ int Document::recompute(const std::vector &objs, bool forc // maximum two passes to allow some form of dependency inversion for(int passes=0; passes<2 && idx seq; - if(canAbort) - seq.reset(new Base::SequencerLauncher("Recompute...", topoSortedObjects.size())); + if(canAbort) { + seq = std::make_unique("Recompute...", topoSortedObjects.size()); + } FC_LOG("Recompute pass " << passes); for (; idx < topoSortedObjects.size(); ++idx) { auto obj = topoSortedObjects[idx]; diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 13f7d73389..db68d9e702 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -1977,22 +1977,22 @@ Py::Object FunctionExpression::evalAggregate( switch (f) { case SUM: - c.reset(new SumCollector); + c = std::make_unique(); break; case AVERAGE: - c.reset(new AverageCollector); + c = std::make_unique(); break; case STDDEV: - c.reset(new StdDevCollector); + c = std::make_unique(); break; case COUNT: - c.reset(new CountCollector); + c = std::make_unique(); break; case MIN: - c.reset(new MinCollector); + c = std::make_unique(); break; case MAX: - c.reset(new MaxCollector); + c = std::make_unique(); break; default: assert(false); diff --git a/src/App/PropertyExpressionEngine.cpp b/src/App/PropertyExpressionEngine.cpp index ab00701b76..fa8d0fec63 100644 --- a/src/App/PropertyExpressionEngine.cpp +++ b/src/App/PropertyExpressionEngine.cpp @@ -164,8 +164,9 @@ void PropertyExpressionEngine::hasSetValue() } } if(hasHidden) { - if(!pimpl) - pimpl.reset(new Private); + if(!pimpl) { + pimpl = std::make_unique(); + } for(auto &e : expressions) { auto expr = e.second.expression; if(!expr) continue; @@ -296,7 +297,7 @@ void PropertyExpressionEngine::Restore(Base::XMLReader &reader) if(reader.hasAttribute("xlink") && reader.getAttributeAsInteger("xlink")) PropertyExpressionContainer::Restore(reader); - restoredExpressions.reset(new std::vector); + restoredExpressions = std::make_unique>(); restoredExpressions->reserve(count); for (int i = 0; i < count; ++i) { @@ -968,7 +969,7 @@ Property *PropertyExpressionEngine::CopyOnImportExternal( if(!expr && !engine) continue; if(!engine) { - engine.reset(new PropertyExpressionEngine); + engine = std::make_unique(); for(auto it2=expressions.begin();it2!=it;++it2) { engine->expressions[it2->first] = ExpressionInfo( std::shared_ptr(it2->second.expression->copy())); @@ -996,7 +997,7 @@ Property *PropertyExpressionEngine::CopyOnLabelChange(App::DocumentObject *obj, if(!expr && !engine) continue; if(!engine) { - engine.reset(new PropertyExpressionEngine); + engine = std::make_unique(); for(auto it2=expressions.begin();it2!=it;++it2) { ExpressionInfo info; if (it2->second.expression) @@ -1028,7 +1029,7 @@ Property *PropertyExpressionEngine::CopyOnLinkReplace(const App::DocumentObject if(!expr && !engine) continue; if(!engine) { - engine.reset(new PropertyExpressionEngine); + engine = std::make_unique(); for(auto it2=expressions.begin();it2!=it;++it2) { ExpressionInfo info; if (it2->second.expression) diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index dc5b4502aa..028b7430ab 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -4623,7 +4623,7 @@ void PropertyXLinkContainer::Save (Base::Writer &writer) const { void PropertyXLinkContainer::Restore(Base::XMLReader &reader) { reader.readElement("XLinks"); auto count = reader.getAttributeAsUnsigned("count"); - _XLinkRestores.reset(new std::vector(count)); + _XLinkRestores = std::make_unique>(count); if(reader.hasAttribute("hidden")) { std::istringstream iss(reader.getAttribute("hidden")); diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index a0ba57237b..dea8b99004 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -1752,16 +1752,17 @@ void ParameterManager::SaveDocument(XMLFormatTarget* pFormatTarget) const theOutput->setEncoding(gOutputEncoding); if (gUseFilter) { - myFilter.reset(new DOMPrintFilter(DOMNodeFilter::SHOW_ELEMENT | - DOMNodeFilter::SHOW_ATTRIBUTE | - DOMNodeFilter::SHOW_DOCUMENT_TYPE | - DOMNodeFilter::SHOW_TEXT - )); + myFilter = std::make_unique( + DOMNodeFilter::SHOW_ELEMENT | + DOMNodeFilter::SHOW_ATTRIBUTE | + DOMNodeFilter::SHOW_DOCUMENT_TYPE | + DOMNodeFilter::SHOW_TEXT + ); theSerializer->setFilter(myFilter.get()); } // plug in user's own error handler - myErrorHandler.reset(new DOMPrintErrorHandler()); + myErrorHandler = std::make_unique(); DOMConfiguration* config = theSerializer->getDomConfig(); config->setParameter(XMLUni::fgDOMErrorHandler, myErrorHandler.get()); diff --git a/src/Base/ProgressIndicatorPy.cpp b/src/Base/ProgressIndicatorPy.cpp index a5c0dfcfe2..d67e018f5b 100644 --- a/src/Base/ProgressIndicatorPy.cpp +++ b/src/Base/ProgressIndicatorPy.cpp @@ -79,8 +79,9 @@ Py::Object ProgressIndicatorPy::start(const Py::Tuple& args) unsigned int steps; if (!PyArg_ParseTuple(args.ptr(), "sI",&text,&steps)) throw Py::Exception(); - if (!_seq.get()) - _seq.reset(new SequencerLauncher(text,steps)); + if (!_seq.get()) { + _seq = std::make_unique(text,steps); + } return Py::None(); } diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index 02cbcf0704..df663617b9 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -818,7 +818,7 @@ RecentFilesAction::RecentFilesAction ( Command* pcCmd, QObject * parent ) , visibleItems(4) , maximumItems(20) { - _pimpl.reset(new Private(this, "User parameter:BaseApp/Preferences/RecentFiles")); + _pimpl = std::make_unique(this, "User parameter:BaseApp/Preferences/RecentFiles"); restore(); } diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 3eda58d7d4..640708f76d 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -422,8 +422,9 @@ void Command::_invoke(int id, bool disablelog) getGuiApplication()->macroManager()->setModule(sAppModule); std::unique_ptr logdisabler; - if (disablelog) - logdisabler.reset(new LogDisabler); + if (disablelog) { + logdisabler = std::make_unique(); + } // check if it really works NOW (could be a delay between click deactivation of the button) if (isActive()) { diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index ccb3979122..0d9af98dba 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -2500,7 +2500,7 @@ public: return; } - currentSelectionHandler = std::unique_ptr(new SelectionCallbackHandler()); + currentSelectionHandler = std::make_unique(); if (viewer) { currentSelectionHandler->userData = ud; diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 086b928b01..2145410172 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -515,9 +515,9 @@ TreeWidget::TreeWidget(const char* name, QWidget* parent) setupText(); if (!documentPixmap) { - documentPixmap.reset(new QPixmap(Gui::BitmapFactory().pixmap("Document"))); + documentPixmap = std::make_unique(Gui::BitmapFactory().pixmap("Document")); QIcon icon(*documentPixmap); - documentPartialPixmap.reset(new QPixmap(icon.pixmap(documentPixmap->size(), QIcon::Disabled))); + documentPartialPixmap = std::make_unique(icon.pixmap(documentPixmap->size(), QIcon::Disabled)); } setColumnHidden(1, TreeParams::getHideColumn()); header()->setVisible(!TreeParams::getHideColumn()); diff --git a/src/Gui/ViewProviderLink.cpp b/src/Gui/ViewProviderLink.cpp index 2a9d17ae47..fa462244b4 100644 --- a/src/Gui/ViewProviderLink.cpp +++ b/src/Gui/ViewProviderLink.cpp @@ -1036,7 +1036,7 @@ void LinkView::setLinkViewObject(ViewProviderDocumentObject *vpd, auto it = subInfo.find(subname); if(it == subInfo.end()) { it = subInfo.insert(std::make_pair(subname,std::unique_ptr())).first; - it->second.reset(new SubInfo(*this)); + it->second = std::make_unique(*this); } if(subelement[0]) it->second->subElements.insert(subelement); @@ -1077,7 +1077,7 @@ void LinkView::setSize(int _size) { pcLinkRoot->addChild(info->pcSwitch); while(nodeArray.size()(new Element(*this))); + nodeArray.push_back(std::make_unique(*this)); auto &info = *nodeArray.back(); info.pcRoot->addChild(info.pcTransform); if(pcLinkedRoot) @@ -1129,8 +1129,9 @@ void LinkView::setChildren(const std::vector &children, std::map groups; for(size_t i=0;i(new Element(*this))); + if(nodeArray.size()<=i) { + nodeArray.push_back(std::make_unique(*this)); + } auto &info = *nodeArray[i]; info.isGroup = false; info.groupIndex = -1; @@ -2633,7 +2634,7 @@ bool ViewProviderLink::initDraggingPlacement() { FC_ERR("initDraggingPlacement() expects return of type tuple(matrix,placement,boundbox)"); return false; } - dragCtx.reset(new DraggerContext); + dragCtx = std::make_unique(); dragCtx->initialPlacement = *static_cast(pypla)->getPlacementPtr(); dragCtx->preTransform = *static_cast(pymat)->getMatrixPtr(); dragCtx->bbox = *static_cast(pybbox)->getBoundBoxPtr(); @@ -2663,7 +2664,7 @@ bool ViewProviderLink::initDraggingPlacement() { return false; } - dragCtx.reset(new DraggerContext); + dragCtx = std::make_unique(); dragCtx->preTransform = doc->getEditingTransform(); doc->setEditingTransform(dragCtx->preTransform); diff --git a/src/Gui/ViewProviderPlacement.cpp b/src/Gui/ViewProviderPlacement.cpp index a9ea023784..4b404570f9 100644 --- a/src/Gui/ViewProviderPlacement.cpp +++ b/src/Gui/ViewProviderPlacement.cpp @@ -84,7 +84,7 @@ void ViewProviderPlacement::attach(App::DocumentObject* pcObject) { ViewProviderGeometryObject::attach(pcObject); if(!Axis) { - Axis.reset(new AxisOrigin); + Axis = std::make_unique(); std::map labels; labels["O"] = "Origin"; labels["X"] = "X-Axis"; diff --git a/src/Mod/Mesh/App/AppMeshPy.cpp b/src/Mod/Mesh/App/AppMeshPy.cpp index 92c5129280..26b9c52314 100644 --- a/src/Mod/Mesh/App/AppMeshPy.cpp +++ b/src/Mod/Mesh/App/AppMeshPy.cpp @@ -257,14 +257,14 @@ private: meta[App::Application::Config()["ExeName"] + "-buildRevisionHash"] = App::Application::Config()["BuildRevisionHash"]; - exporter.reset( new ExporterAMF(outputFileName, meta, exportAmfCompressed) ); + exporter = std::make_unique(outputFileName, meta, exportAmfCompressed); } else if (exportFormat == MeshIO::ThreeMF) { Extension3MFFactory::initialize(); - exporter.reset( new Exporter3MF(outputFileName, Extension3MFFactory::createExtensions()) ); + exporter = std::make_unique(outputFileName, Extension3MFFactory::createExtensions()); } else if (exportFormat != MeshIO::Undefined) { - exporter.reset( new MergeExporter(outputFileName, exportFormat) ); + exporter = std::make_unique(outputFileName, exportFormat); } else { std::string exStr("Can't determine mesh format from file name.\nPlease specify mesh format file extension: '"); diff --git a/src/Mod/Mesh/App/Exporter.cpp b/src/Mod/Mesh/App/Exporter.cpp index 4d0cbabe9c..8f8980d50f 100644 --- a/src/Mod/Mesh/App/Exporter.cpp +++ b/src/Mod/Mesh/App/Exporter.cpp @@ -280,7 +280,7 @@ public: Exporter3MF::Exporter3MF(std::string fileName, const std::vector& ext) { throwIfNoPermission(fileName); - d.reset(new Private(fileName, ext)); + d = std::make_unique(fileName, ext); } Exporter3MF::~Exporter3MF() diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 5015925d23..13c597f33c 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -119,7 +119,7 @@ Data::Segment* MeshObject::getSubElement(const char* Type, unsigned long n) cons MeshSegment* segm = new MeshSegment(); segm->mesh = new MeshObject(*this); const Segment& faces = getSegment(n); - segm->segment.reset(new Segment(static_cast(segm->mesh), faces.getIndices(), false)); + segm->segment = std::make_unique(static_cast(segm->mesh), faces.getIndices(), false); return segm; } diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index 0335243bf3..91de9781ef 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -267,7 +267,7 @@ PyObject* MeshPy::write(PyObject *args, PyObject *kwds) std::unique_ptr mat; if (List) { - mat.reset(new MeshCore::Material); + mat = std::make_unique(); Py::Sequence list(List); for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { Py::Tuple t(*it); diff --git a/src/Mod/Mesh/App/MeshTexture.cpp b/src/Mod/Mesh/App/MeshTexture.cpp index a799ad4db7..f0cfd6c338 100644 --- a/src/Mod/Mesh/App/MeshTexture.cpp +++ b/src/Mod/Mesh/App/MeshTexture.cpp @@ -35,12 +35,12 @@ MeshTexture::MeshTexture(const Mesh::MeshObject& mesh, const MeshCore::Material if (material.binding == MeshCore::MeshIO::PER_VERTEX && material.diffuseColor.size() == countPointsRefMesh) { binding = MeshCore::MeshIO::PER_VERTEX; - kdTree.reset(new MeshCore::MeshKDTree(mesh.getKernel().GetPoints())); + kdTree = std::make_unique(mesh.getKernel().GetPoints()); } else if (material.binding == MeshCore::MeshIO::PER_FACE && material.diffuseColor.size() == countFacets) { binding = MeshCore::MeshIO::PER_FACE; - kdTree.reset(new MeshCore::MeshKDTree(mesh.getKernel().GetPoints())); - refPnt2Fac.reset(new MeshCore::MeshRefPointToFacets(mesh.getKernel())); + kdTree = std::make_unique(mesh.getKernel().GetPoints()); + refPnt2Fac = std::make_unique(mesh.getKernel()); } } diff --git a/src/Mod/Part/App/BSplineCurvePyImp.cpp b/src/Mod/Part/App/BSplineCurvePyImp.cpp index b0078d48df..7ce054ab39 100644 --- a/src/Mod/Part/App/BSplineCurvePyImp.cpp +++ b/src/Mod/Part/App/BSplineCurvePyImp.cpp @@ -1043,12 +1043,12 @@ PyObject* BSplineCurvePy::interpolate(PyObject *args, PyObject *kwds) std::unique_ptr aBSplineInterpolation; if (parameters.IsNull()) { - aBSplineInterpolation.reset(new GeomAPI_Interpolate(interpolationPoints, - Base::asBoolean(periodic), tol3d)); + aBSplineInterpolation = std::make_unique(interpolationPoints, + Base::asBoolean(periodic), tol3d); } else { - aBSplineInterpolation.reset(new GeomAPI_Interpolate(interpolationPoints, parameters, - Base::asBoolean(periodic), tol3d)); + aBSplineInterpolation = std::make_unique(interpolationPoints, parameters, + Base::asBoolean(periodic), tol3d); } if (t1 && t2) { diff --git a/src/Mod/Part/App/FaceMakerBullseye.cpp b/src/Mod/Part/App/FaceMakerBullseye.cpp index d73ebd35b9..1708c0229d 100644 --- a/src/Mod/Part/App/FaceMakerBullseye.cpp +++ b/src/Mod/Part/App/FaceMakerBullseye.cpp @@ -121,8 +121,8 @@ void FaceMakerBullseye::Build_Essence() } else { //wire is not on a face. Start a new face. - faces.push_back(std::unique_ptr( - new FaceDriller(plane, w) + faces.push_back(std::make_unique( + plane, w )); } } diff --git a/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp b/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp index d7103e7610..3a3c56fe65 100644 --- a/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp +++ b/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp @@ -949,12 +949,16 @@ PyObject* BSplineCurve2dPy::interpolate(PyObject *args, PyObject *kwds) std::unique_ptr aBSplineInterpolation; if (parameters.IsNull()) { - aBSplineInterpolation.reset(new Geom2dAPI_Interpolate(interpolationPoints, - Base::asBoolean(periodic), tol3d)); + aBSplineInterpolation = std::make_unique( + interpolationPoints, + Base::asBoolean(periodic), tol3d + ); } else { - aBSplineInterpolation.reset(new Geom2dAPI_Interpolate(interpolationPoints, parameters, - Base::asBoolean(periodic), tol3d)); + aBSplineInterpolation = std::make_unique( + interpolationPoints, parameters, + Base::asBoolean(periodic), tol3d + ); } if (t1 && t2) { diff --git a/src/Mod/Part/App/GeomPlate/CurveConstraintPyImp.cpp b/src/Mod/Part/App/GeomPlate/CurveConstraintPyImp.cpp index aca3233ddb..5ab02e40e7 100644 --- a/src/Mod/Part/App/GeomPlate/CurveConstraintPyImp.cpp +++ b/src/Mod/Part/App/GeomPlate/CurveConstraintPyImp.cpp @@ -99,10 +99,10 @@ int CurveConstraintPy::PyInit(PyObject* args, PyObject* kwds) } #endif - ptr.reset(new GeomPlate_CurveConstraint(hCurve, order, nbPts, tolDist, tolAng, tolCurv)); + ptr = std::make_unique(hCurve, order, nbPts, tolDist, tolAng, tolCurv); } else { - ptr.reset(new GeomPlate_CurveConstraint); + ptr = std::make_unique(); } setTwinPointer(ptr.release()); diff --git a/src/Mod/Part/App/GeomPlate/PointConstraintPyImp.cpp b/src/Mod/Part/App/GeomPlate/PointConstraintPyImp.cpp index 89713c5717..4c05b7222c 100644 --- a/src/Mod/Part/App/GeomPlate/PointConstraintPyImp.cpp +++ b/src/Mod/Part/App/GeomPlate/PointConstraintPyImp.cpp @@ -56,7 +56,7 @@ int PointConstraintPy::PyInit(PyObject* args, PyObject* kwds) std::unique_ptr ptr; Base::Vector3d v = static_cast(pt)->value(); - ptr.reset(new GeomPlate_PointConstraint(gp_Pnt(v.x, v.y, v.z), order, tolDist)); + ptr = std::make_unique(gp_Pnt(v.x, v.y, v.z), order, tolDist); setTwinPointer(ptr.release()); return 0; diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 3142cd9984..571d8157b1 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -5365,51 +5365,51 @@ std::unique_ptr makeFromSurface(const Handle(Geom_Surface)& s) std::unique_ptr geoSurf; if (s->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))) { Handle(Geom_ToroidalSurface) hSurf = Handle(Geom_ToroidalSurface)::DownCast(s); - geoSurf.reset(new GeomToroid(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(Geom_BezierSurface))) { Handle(Geom_BezierSurface) hSurf = Handle(Geom_BezierSurface)::DownCast(s); - geoSurf.reset(new GeomBezierSurface(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) { Handle(Geom_BSplineSurface) hSurf = Handle(Geom_BSplineSurface)::DownCast(s); - geoSurf.reset(new GeomBSplineSurface(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) { Handle(Geom_CylindricalSurface) hSurf = Handle(Geom_CylindricalSurface)::DownCast(s); - geoSurf.reset(new GeomCylinder(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(Geom_ConicalSurface))) { Handle(Geom_ConicalSurface) hSurf = Handle(Geom_ConicalSurface)::DownCast(s); - geoSurf.reset(new GeomCone(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) { Handle(Geom_SphericalSurface) hSurf = Handle(Geom_SphericalSurface)::DownCast(s); - geoSurf.reset(new GeomSphere(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(Geom_Plane))) { Handle(Geom_Plane) hSurf = Handle(Geom_Plane)::DownCast(s); - geoSurf.reset(new GeomPlane(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { Handle(Geom_OffsetSurface) hSurf = Handle(Geom_OffsetSurface)::DownCast(s); - geoSurf.reset(new GeomOffsetSurface(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(GeomPlate_Surface))) { Handle(GeomPlate_Surface) hSurf = Handle(GeomPlate_Surface)::DownCast(s); - geoSurf.reset(new GeomPlateSurface(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { Handle(Geom_RectangularTrimmedSurface) hSurf = Handle(Geom_RectangularTrimmedSurface)::DownCast(s); - geoSurf.reset(new GeomTrimmedSurface(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution))) { Handle(Geom_SurfaceOfRevolution) hSurf = Handle(Geom_SurfaceOfRevolution)::DownCast(s); - geoSurf.reset(new GeomSurfaceOfRevolution(hSurf)); + geoSurf = std::make_unique(hSurf); } else if (s->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) { Handle(Geom_SurfaceOfLinearExtrusion) hSurf = Handle(Geom_SurfaceOfLinearExtrusion)::DownCast(s); - geoSurf.reset(new GeomSurfaceOfExtrusion(hSurf)); + geoSurf = std::make_unique(hSurf); } else { std::string err = "Unhandled surface type "; @@ -5425,27 +5425,27 @@ std::unique_ptr makeFromCurve(const Handle(Geom_Curve)& c) std::unique_ptr geoCurve; if (c->IsKind(STANDARD_TYPE(Geom_Circle))) { Handle(Geom_Circle) circ = Handle(Geom_Circle)::DownCast(c); - geoCurve.reset(new GeomCircle(circ)); + geoCurve = std::make_unique(circ); } else if (c->IsKind(STANDARD_TYPE(Geom_Ellipse))) { Handle(Geom_Ellipse) ell = Handle(Geom_Ellipse)::DownCast(c); - geoCurve.reset(new GeomEllipse(ell)); + geoCurve = std::make_unique(ell); } else if (c->IsKind(STANDARD_TYPE(Geom_Hyperbola))) { Handle(Geom_Hyperbola) hyp = Handle(Geom_Hyperbola)::DownCast(c); - geoCurve.reset(new GeomHyperbola(hyp)); + geoCurve = std::make_unique(hyp); } else if (c->IsKind(STANDARD_TYPE(Geom_Line))) { Handle(Geom_Line) lin = Handle(Geom_Line)::DownCast(c); - geoCurve.reset(new GeomLine(lin)); + geoCurve = std::make_unique(lin); } else if (c->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) { Handle(Geom_OffsetCurve) oc = Handle(Geom_OffsetCurve)::DownCast(c); - geoCurve.reset(new GeomOffsetCurve(oc)); + geoCurve = std::make_unique(oc); } else if (c->IsKind(STANDARD_TYPE(Geom_Parabola))) { Handle(Geom_Parabola) par = Handle(Geom_Parabola)::DownCast(c); - geoCurve.reset(new GeomParabola(par)); + geoCurve = std::make_unique(par); } else if (c->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { return makeFromTrimmedCurve(c, c->FirstParameter(), c->LastParameter()); @@ -5456,11 +5456,11 @@ std::unique_ptr makeFromCurve(const Handle(Geom_Curve)& c) }*/ else if (c->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { Handle(Geom_BezierCurve) bezier = Handle(Geom_BezierCurve)::DownCast(c); - geoCurve.reset(new GeomBezierCurve(bezier)); + geoCurve = std::make_unique(bezier); } else if (c->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { Handle(Geom_BSplineCurve) bspline = Handle(Geom_BSplineCurve)::DownCast(c); - geoCurve.reset(new GeomBSplineCurve(bspline)); + geoCurve = std::make_unique(bspline); } else { std::string err = "Unhandled curve type "; @@ -5567,7 +5567,7 @@ std::unique_ptr makeFromCurveAdaptor(const Adaptor3d_Curve& adapt) { case GeomAbs_Line: { - geoCurve.reset(new GeomLine()); + geoCurve = std::make_unique(); Handle(Geom_Line) this_curv = Handle(Geom_Line)::DownCast (geoCurve->handle()); this_curv->SetLin(adapt.Line()); @@ -5575,7 +5575,7 @@ std::unique_ptr makeFromCurveAdaptor(const Adaptor3d_Curve& adapt) } case GeomAbs_Circle: { - geoCurve.reset(new GeomCircle()); + geoCurve = std::make_unique(); Handle(Geom_Circle) this_curv = Handle(Geom_Circle)::DownCast (geoCurve->handle()); this_curv->SetCirc(adapt.Circle()); @@ -5583,7 +5583,7 @@ std::unique_ptr makeFromCurveAdaptor(const Adaptor3d_Curve& adapt) } case GeomAbs_Ellipse: { - geoCurve.reset(new GeomEllipse()); + geoCurve = std::make_unique(); Handle(Geom_Ellipse) this_curv = Handle(Geom_Ellipse)::DownCast (geoCurve->handle()); this_curv->SetElips(adapt.Ellipse()); @@ -5591,7 +5591,7 @@ std::unique_ptr makeFromCurveAdaptor(const Adaptor3d_Curve& adapt) } case GeomAbs_Hyperbola: { - geoCurve.reset(new GeomHyperbola()); + geoCurve = std::make_unique(); Handle(Geom_Hyperbola) this_curv = Handle(Geom_Hyperbola)::DownCast (geoCurve->handle()); this_curv->SetHypr(adapt.Hyperbola()); @@ -5599,7 +5599,7 @@ std::unique_ptr makeFromCurveAdaptor(const Adaptor3d_Curve& adapt) } case GeomAbs_Parabola: { - geoCurve.reset(new GeomParabola()); + geoCurve = std::make_unique(); Handle(Geom_Parabola) this_curv = Handle(Geom_Parabola)::DownCast (geoCurve->handle()); this_curv->SetParab(adapt.Parabola()); @@ -5607,17 +5607,17 @@ std::unique_ptr makeFromCurveAdaptor(const Adaptor3d_Curve& adapt) } case GeomAbs_BezierCurve: { - geoCurve.reset(new GeomBezierCurve(adapt.Bezier())); + geoCurve = std::make_unique(adapt.Bezier()); break; } case GeomAbs_BSplineCurve: { - geoCurve.reset(new GeomBSplineCurve(adapt.BSpline())); + geoCurve = std::make_unique(adapt.BSpline()); break; } case GeomAbs_OffsetCurve: { - geoCurve.reset(new GeomOffsetCurve(adapt.OffsetCurve())); + geoCurve = std::make_unique(adapt.OffsetCurve()); break; } case GeomAbs_OtherCurve: diff --git a/src/Mod/Part/App/Geometry2d.cpp b/src/Mod/Part/App/Geometry2d.cpp index ae8d67422f..d7d69c6419 100644 --- a/src/Mod/Part/App/Geometry2d.cpp +++ b/src/Mod/Part/App/Geometry2d.cpp @@ -2304,28 +2304,28 @@ std::unique_ptr makeFromCurve2d(Handle(Geom2d_Curve) curve) if (curve.IsNull()) return geo2d; if (curve->IsKind(STANDARD_TYPE (Geom2d_Parabola))) { - geo2d.reset(new Geom2dParabola(Handle(Geom2d_Parabola)::DownCast(curve))); + geo2d = std::make_unique(Handle(Geom2d_Parabola)::DownCast(curve)); } else if (curve->IsKind(STANDARD_TYPE (Geom2d_Hyperbola))) { - geo2d.reset(new Geom2dHyperbola(Handle(Geom2d_Hyperbola)::DownCast(curve))); + geo2d = std::make_unique(Handle(Geom2d_Hyperbola)::DownCast(curve)); } else if (curve->IsKind(STANDARD_TYPE (Geom2d_Ellipse))) { - geo2d.reset(new Geom2dEllipse(Handle(Geom2d_Ellipse)::DownCast(curve))); + geo2d = std::make_unique(Handle(Geom2d_Ellipse)::DownCast(curve)); } else if (curve->IsKind(STANDARD_TYPE (Geom2d_Circle))) { - geo2d.reset(new Geom2dCircle(Handle(Geom2d_Circle)::DownCast(curve))); + geo2d = std::make_unique(Handle(Geom2d_Circle)::DownCast(curve)); } else if (curve->IsKind(STANDARD_TYPE (Geom2d_Line))) { - geo2d.reset(new Geom2dLine(Handle(Geom2d_Line)::DownCast(curve))); + geo2d = std::make_unique(Handle(Geom2d_Line)::DownCast(curve)); } else if (curve->IsKind(STANDARD_TYPE (Geom2d_BSplineCurve))) { - geo2d.reset(new Geom2dBSplineCurve(Handle(Geom2d_BSplineCurve)::DownCast(curve))); + geo2d = std::make_unique(Handle(Geom2d_BSplineCurve)::DownCast(curve)); } else if (curve->IsKind(STANDARD_TYPE (Geom2d_BezierCurve))) { - geo2d.reset(new Geom2dBezierCurve(Handle(Geom2d_BezierCurve)::DownCast(curve))); + geo2d = std::make_unique(Handle(Geom2d_BezierCurve)::DownCast(curve)); } else if (curve->IsKind(STANDARD_TYPE (Geom2d_TrimmedCurve))) { - geo2d.reset(new Geom2dTrimmedCurve(Handle(Geom2d_TrimmedCurve)::DownCast(curve))); + geo2d = std::make_unique(Handle(Geom2d_TrimmedCurve)::DownCast(curve)); } return geo2d; @@ -2426,7 +2426,7 @@ std::unique_ptr makeFromCurveAdaptor2d(const Adaptor2d_Curve2d& ada { case GeomAbs_Line: { - geoCurve.reset(new Geom2dLine()); + geoCurve = std::make_unique(); Handle(Geom2d_Line) this_curv = Handle(Geom2d_Line)::DownCast (geoCurve->handle()); this_curv->SetLin2d(adapt.Line()); @@ -2434,7 +2434,7 @@ std::unique_ptr makeFromCurveAdaptor2d(const Adaptor2d_Curve2d& ada } case GeomAbs_Circle: { - geoCurve.reset(new Geom2dCircle()); + geoCurve = std::make_unique(); Handle(Geom2d_Circle) this_curv = Handle(Geom2d_Circle)::DownCast (geoCurve->handle()); this_curv->SetCirc2d(adapt.Circle()); @@ -2442,7 +2442,7 @@ std::unique_ptr makeFromCurveAdaptor2d(const Adaptor2d_Curve2d& ada } case GeomAbs_Ellipse: { - geoCurve.reset(new Geom2dEllipse()); + geoCurve = std::make_unique(); Handle(Geom2d_Ellipse) this_curv = Handle(Geom2d_Ellipse)::DownCast (geoCurve->handle()); this_curv->SetElips2d(adapt.Ellipse()); @@ -2450,7 +2450,7 @@ std::unique_ptr makeFromCurveAdaptor2d(const Adaptor2d_Curve2d& ada } case GeomAbs_Hyperbola: { - geoCurve.reset(new Geom2dHyperbola()); + geoCurve = std::make_unique(); Handle(Geom2d_Hyperbola) this_curv = Handle(Geom2d_Hyperbola)::DownCast (geoCurve->handle()); this_curv->SetHypr2d(adapt.Hyperbola()); @@ -2458,7 +2458,7 @@ std::unique_ptr makeFromCurveAdaptor2d(const Adaptor2d_Curve2d& ada } case GeomAbs_Parabola: { - geoCurve.reset(new Geom2dParabola()); + geoCurve = std::make_unique(); Handle(Geom2d_Parabola) this_curv = Handle(Geom2d_Parabola)::DownCast (geoCurve->handle()); this_curv->SetParab2d(adapt.Parabola()); @@ -2466,12 +2466,12 @@ std::unique_ptr makeFromCurveAdaptor2d(const Adaptor2d_Curve2d& ada } case GeomAbs_BezierCurve: { - geoCurve.reset(new Geom2dBezierCurve(adapt.Bezier())); + geoCurve = std::make_unique(adapt.Bezier()); break; } case GeomAbs_BSplineCurve: { - geoCurve.reset(new Geom2dBSplineCurve(adapt.BSpline())); + geoCurve = std::make_unique(adapt.BSpline()); break; } case GeomAbs_OtherCurve: diff --git a/src/Mod/Part/Gui/SoBrepFaceSet.cpp b/src/Mod/Part/Gui/SoBrepFaceSet.cpp index 979e4b24ec..b87a5c905b 100644 --- a/src/Mod/Part/Gui/SoBrepFaceSet.cpp +++ b/src/Mod/Part/Gui/SoBrepFaceSet.cpp @@ -170,7 +170,7 @@ SoBrepFaceSet::SoBrepFaceSet() selContext2 = std::make_shared(); packedColor = 0; - pimpl.reset(new VBO); + pimpl = std::make_unique(); } SoBrepFaceSet::~SoBrepFaceSet() diff --git a/src/Mod/Path/App/Area.cpp b/src/Mod/Path/App/Area.cpp index fde743bd09..15ac2c8507 100644 --- a/src/Mod/Path/App/Area.cpp +++ b/src/Mod/Path/App/Area.cpp @@ -188,7 +188,7 @@ Area::Area(const Area& other, bool deep_copy) if (!deep_copy || !other.isBuilt()) return; if (other.myArea) - myArea.reset(new CArea(*other.myArea)); + myArea = std::make_unique(*other.myArea); myShapePlane = other.myShapePlane; myShape = other.myShape; myShapeDone = other.myShapeDone; @@ -1637,8 +1637,8 @@ void Area::build() { getPlane(&trsf); try { - myArea.reset(new CArea()); - myAreaOpen.reset(new CArea()); + myArea = std::make_unique(); + myAreaOpen = std::make_unique(); CAreaConfig conf(myParams); CArea areaClip; diff --git a/src/Mod/Points/App/AppPointsPy.cpp b/src/Mod/Points/App/AppPointsPy.cpp index 5db820f5b1..9bd3d6d74a 100644 --- a/src/Mod/Points/App/AppPointsPy.cpp +++ b/src/Mod/Points/App/AppPointsPy.cpp @@ -90,17 +90,17 @@ private: std::unique_ptr reader; if (file.hasExtension("asc")) { - reader.reset(new AscReader); + reader = std::make_unique(); } else if (file.hasExtension("e57")) { auto setting = readE57Settings(); - reader.reset(new E57Reader(std::get<0>(setting), std::get<1>(setting), std::get<2>(setting))); + reader = std::make_unique(std::get<0>(setting), std::get<1>(setting), std::get<2>(setting)); } else if (file.hasExtension("ply")) { - reader.reset(new PlyReader); + reader = std::make_unique(); } else if (file.hasExtension("pcd")) { - reader.reset(new PcdReader); + reader = std::make_unique(); } else { throw Py::RuntimeError("Unsupported file extension"); @@ -206,17 +206,17 @@ private: std::unique_ptr reader; if (file.hasExtension("asc")) { - reader.reset(new AscReader); + reader = std::make_unique(); } else if (file.hasExtension("e57")) { auto setting = readE57Settings(); - reader.reset(new E57Reader(std::get<0>(setting), std::get<1>(setting), std::get<2>(setting))); + reader = std::make_unique(std::get<0>(setting), std::get<1>(setting), std::get<2>(setting)); } else if (file.hasExtension("ply")) { - reader.reset(new PlyReader); + reader = std::make_unique(); } else if (file.hasExtension("pcd")) { - reader.reset(new PcdReader); + reader = std::make_unique(); } else { throw Py::RuntimeError("Unsupported file extension"); @@ -327,13 +327,13 @@ private: const PointKernel& kernel = fea->Points.getValue(); std::unique_ptr writer; if (file.hasExtension("asc")) { - writer.reset(new AscWriter(kernel)); + writer = std::make_unique(kernel); } else if (file.hasExtension("ply")) { - writer.reset(new PlyWriter(kernel)); + writer = std::make_unique(kernel); } else if (file.hasExtension("pcd")) { - writer.reset(new PcdWriter(kernel)); + writer = std::make_unique(kernel); } else { throw Py::RuntimeError("Unsupported file extension"); diff --git a/src/Mod/Robot/App/Trajectory.cpp b/src/Mod/Robot/App/Trajectory.cpp index e47a0cf162..b08c5248b4 100644 --- a/src/Mod/Robot/App/Trajectory.cpp +++ b/src/Mod/Robot/App/Trajectory.cpp @@ -179,10 +179,10 @@ void Trajectory::generateTrajectory() bool Cont = (*it)->Cont && !(it == --vpcWaypoints.end()); // start of a continue block if (Cont && !pcRoundComp) { - pcRoundComp.reset(new KDL::Path_RoundedComposite(3, 3, - new KDL::RotationalInterpolation_SingleAxis())); + pcRoundComp = std::make_unique(3, 3, + new KDL::RotationalInterpolation_SingleAxis()); // the velocity of the first waypoint is used - pcVelPrf.reset(new KDL::VelocityProfile_Trap((*it)->Velocity, (*it)->Acceleration)); + pcVelPrf = std::make_unique((*it)->Velocity, (*it)->Acceleration); pcRoundComp->Add(Last); pcRoundComp->Add(Next); @@ -197,7 +197,7 @@ void Trajectory::generateTrajectory() pcRoundComp->Add(Next); pcRoundComp->Finish(); pcVelPrf->SetProfile(0, pcRoundComp->PathLength()); - pcTrak.reset(new KDL::Trajectory_Segment(pcRoundComp.release(), pcVelPrf.release())); + pcTrak = std::make_unique(pcRoundComp.release(), pcVelPrf.release()); // normal block } @@ -210,9 +210,9 @@ void Trajectory::generateTrajectory() true ); - pcVelPrf.reset(new KDL::VelocityProfile_Trap((*it)->Velocity, (*it)->Acceleration)); + pcVelPrf = std::make_unique((*it)->Velocity, (*it)->Acceleration); pcVelPrf->SetProfile(0, pcPath->PathLength()); - pcTrak.reset(new KDL::Trajectory_Segment(pcPath, pcVelPrf.release())); + pcTrak = std::make_unique(pcPath, pcVelPrf.release()); } Last = Next; break; } diff --git a/src/Mod/Spreadsheet/App/Cell.cpp b/src/Mod/Spreadsheet/App/Cell.cpp index e5c78bfb9c..a94bab0c7f 100644 --- a/src/Mod/Spreadsheet/App/Cell.cpp +++ b/src/Mod/Spreadsheet/App/Cell.cpp @@ -283,7 +283,7 @@ void Cell::setContent(const char * value) if (owner->sheet()->isRestoring()) { if (value[0] == '\0' || (value[0] == '\'' && value[1] == '\0')) return; - expression.reset(new App::StringExpression(owner->sheet(), value)); + expression = std::make_unique(owner->sheet(), value); setUsed(EXPRESSION_SET, true); return; } diff --git a/src/Mod/Spreadsheet/App/Sheet.cpp b/src/Mod/Spreadsheet/App/Sheet.cpp index 2ff92ffe04..18decff708 100644 --- a/src/Mod/Spreadsheet/App/Sheet.cpp +++ b/src/Mod/Spreadsheet/App/Sheet.cpp @@ -675,7 +675,7 @@ void Sheet::updateProperty(CellAddress key) std::string s; if (cell->getStringContent(s) && !s.empty()) - output.reset(new StringExpression(this, s)); + output = std::make_unique(this, s); else { this->removeDynamicProperty(key.toString().c_str()); return;