From a7f0d0112ed42f48b506cd649e80f2ef7e461864 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Sat, 6 Mar 2021 00:51:43 +0100 Subject: [PATCH] [App] Use std::shared_ptr instead of boost::shared_ptr There's no need to use boost version when stl has support for shared_ptr --- src/App/DocumentObject.cpp | 4 ++-- src/App/DocumentObject.h | 2 +- src/App/DocumentObjectPyImp.cpp | 8 +++---- src/App/PropertyExpressionEngine.cpp | 34 ++++++++++++++-------------- src/App/PropertyExpressionEngine.h | 12 +++++----- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index fe929c3152..250b4bab10 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -682,7 +682,7 @@ bool DocumentObject::removeDynamicProperty(const char* name) } for (auto it : removeExpr) { - ExpressionEngine.setValue(it, boost::shared_ptr()); + ExpressionEngine.setValue(it, std::shared_ptr()); } return TransactionalObject::removeDynamicProperty(name); @@ -912,7 +912,7 @@ void DocumentObject::Save (Base::Writer &writer) const * @param expr Expression tree */ -void DocumentObject::setExpression(const ObjectIdentifier &path, boost::shared_ptr expr) +void DocumentObject::setExpression(const ObjectIdentifier &path, std::shared_ptr expr) { ExpressionEngine.setValue(path, expr); } diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h index b4b166075f..75fd9642d8 100644 --- a/src/App/DocumentObject.h +++ b/src/App/DocumentObject.h @@ -422,7 +422,7 @@ public: /* Expression support */ - virtual void setExpression(const ObjectIdentifier & path, boost::shared_ptr expr); + virtual void setExpression(const ObjectIdentifier & path, std::shared_ptr expr); virtual const PropertyExpressionEngine::ExpressionInfo getExpression(const ObjectIdentifier &path) const; diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index 618968d42f..a0fecb195e 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -329,7 +329,7 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args) App::ObjectIdentifier p(ObjectIdentifier::parse(getDocumentObjectPtr(), path)); if (Py::Object(expr).isNone()) - getDocumentObjectPtr()->setExpression(p, boost::shared_ptr()); + getDocumentObjectPtr()->setExpression(p, std::shared_ptr()); #if PY_MAJOR_VERSION >= 3 else if (PyUnicode_Check(expr)) { const char * exprStr = PyUnicode_AsUTF8(expr); @@ -337,7 +337,7 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args) else if (PyString_Check(expr)) { const char * exprStr = PyString_AsString(expr); #endif - boost::shared_ptr shared_expr(Expression::parse(getDocumentObjectPtr(), exprStr)); + std::shared_ptr shared_expr(Expression::parse(getDocumentObjectPtr(), exprStr)); if(shared_expr && comment) shared_expr->comment = comment; @@ -351,7 +351,7 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args) if (unicode) { std::string exprStr = PyString_AsString(unicode); Py_DECREF(unicode); - boost::shared_ptr shared_expr(ExpressionParser::parse(getDocumentObjectPtr(), exprStr.c_str())); + std::shared_ptr shared_expr(ExpressionParser::parse(getDocumentObjectPtr(), exprStr.c_str())); if(shared_expr && comment) shared_expr->comment = comment; @@ -375,7 +375,7 @@ PyObject* DocumentObjectPy::evalExpression(PyObject * args) return NULL; // NULL triggers exception PY_TRY { - boost::shared_ptr shared_expr(Expression::parse(getDocumentObjectPtr(), expr)); + std::shared_ptr shared_expr(Expression::parse(getDocumentObjectPtr(), expr)); if(shared_expr) return Py::new_reference_to(shared_expr->getPyValue()); Py_Return; diff --git a/src/App/PropertyExpressionEngine.cpp b/src/App/PropertyExpressionEngine.cpp index 3801f475b8..f8f8e84f5d 100644 --- a/src/App/PropertyExpressionEngine.cpp +++ b/src/App/PropertyExpressionEngine.cpp @@ -110,7 +110,7 @@ Property *PropertyExpressionEngine::Copy() const PropertyExpressionEngine * engine = new PropertyExpressionEngine(); for (ExpressionMap::const_iterator it = expressions.begin(); it != expressions.end(); ++it) - engine->expressions[it->first] = ExpressionInfo(boost::shared_ptr(it->second.expression->copy())); + engine->expressions[it->first] = ExpressionInfo(std::shared_ptr(it->second.expression->copy())); engine->validator = validator; @@ -153,7 +153,7 @@ void PropertyExpressionEngine::Paste(const Property &from) expressions.clear(); for(auto &e : fromee.expressions) { expressions[e.first] = ExpressionInfo( - boost::shared_ptr(e.second.expression->copy())); + std::shared_ptr(e.second.expression->copy())); expressionChanged(e.first); } validator = fromee.validator; @@ -218,7 +218,7 @@ void PropertyExpressionEngine::Restore(Base::XMLReader &reader) */ void PropertyExpressionEngine::buildGraphStructures(const ObjectIdentifier & path, - const boost::shared_ptr expression, + const std::shared_ptr expression, boost::unordered_map & nodes, boost::unordered_map & revNodes, std::vector & edges) const @@ -304,7 +304,7 @@ void PropertyExpressionEngine::afterRestore() for(auto &info : *restoredExpressions) { ObjectIdentifier path = ObjectIdentifier::parse(docObj, info.path); - boost::shared_ptr expression(Expression::parse(docObj, info.expr.c_str())); + std::shared_ptr expression(Expression::parse(docObj, info.expr.c_str())); if(expression) expression->comment = std::move(info.comment); setValue(path, expression); @@ -351,7 +351,7 @@ const boost::any PropertyExpressionEngine::getPathValue(const App::ObjectIdentif * @param comment Optional comment. */ -void PropertyExpressionEngine::setValue(const ObjectIdentifier & path, boost::shared_ptr expr) +void PropertyExpressionEngine::setValue(const ObjectIdentifier & path, std::shared_ptr expr) { ObjectIdentifier usePath(canonicalPath(path)); const Property * prop = usePath.getProperty(); @@ -623,7 +623,7 @@ bool PropertyExpressionEngine::depsAreTouched() const * @return Empty string on success, error message on failure. */ -std::string PropertyExpressionEngine::validateExpression(const ObjectIdentifier &path, boost::shared_ptr expr) const +std::string PropertyExpressionEngine::validateExpression(const ObjectIdentifier &path, std::shared_ptr expr) const { std::string error; ObjectIdentifier usePath(canonicalPath(path)); @@ -653,7 +653,7 @@ std::string PropertyExpressionEngine::validateExpression(const ObjectIdentifier ExpressionMap newExpressions = expressions; // Add expression in question - boost::shared_ptr exprClone(expr->copy()); + std::shared_ptr exprClone(expr->copy()); newExpressions[usePath].expression = exprClone; // Build graph; an exception will be thrown if it is not a DAG @@ -819,9 +819,9 @@ Property *PropertyExpressionEngine::CopyOnImportExternal( std::unique_ptr engine; for(auto it=expressions.begin();it!=expressions.end();++it) { #ifdef BOOST_NO_CXX11_SMART_PTR - boost::shared_ptr expr(it->second.expression->importSubNames(nameMap).release()); + std::shared_ptr expr(it->second.expression->importSubNames(nameMap).release()); #else - boost::shared_ptr expr(it->second.expression->importSubNames(nameMap)); + std::shared_ptr expr(it->second.expression->importSubNames(nameMap)); #endif if(!expr && !engine) continue; @@ -829,7 +829,7 @@ Property *PropertyExpressionEngine::CopyOnImportExternal( engine.reset(new PropertyExpressionEngine); for(auto it2=expressions.begin();it2!=it;++it2) { engine->expressions[it2->first] = ExpressionInfo( - boost::shared_ptr(it2->second.expression->copy())); + std::shared_ptr(it2->second.expression->copy())); } }else if(!expr) expr = it->second.expression; @@ -847,9 +847,9 @@ Property *PropertyExpressionEngine::CopyOnLabelChange(App::DocumentObject *obj, std::unique_ptr engine; for(auto it=expressions.begin();it!=expressions.end();++it) { #ifdef BOOST_NO_CXX11_SMART_PTR - boost::shared_ptr expr(it->second.expression->updateLabelReference(obj,ref,newLabel).release()); + std::shared_ptr expr(it->second.expression->updateLabelReference(obj,ref,newLabel).release()); #else - boost::shared_ptr expr(it->second.expression->updateLabelReference(obj,ref,newLabel)); + std::shared_ptr expr(it->second.expression->updateLabelReference(obj,ref,newLabel)); #endif if(!expr && !engine) continue; @@ -857,7 +857,7 @@ Property *PropertyExpressionEngine::CopyOnLabelChange(App::DocumentObject *obj, engine.reset(new PropertyExpressionEngine); for(auto it2=expressions.begin();it2!=it;++it2) { engine->expressions[it2->first] = ExpressionInfo( - boost::shared_ptr(it2->second.expression->copy())); + std::shared_ptr(it2->second.expression->copy())); } }else if(!expr) expr = it->second.expression; @@ -875,10 +875,10 @@ Property *PropertyExpressionEngine::CopyOnLinkReplace(const App::DocumentObject std::unique_ptr engine; for(auto it=expressions.begin();it!=expressions.end();++it) { #ifdef BOOST_NO_CXX11_SMART_PTR - boost::shared_ptr expr( + std::shared_ptr expr( it->second.expression->replaceObject(parent,oldObj,newObj).release()); #else - boost::shared_ptr expr( + std::shared_ptr expr( it->second.expression->replaceObject(parent,oldObj,newObj)); #endif if(!expr && !engine) @@ -887,7 +887,7 @@ Property *PropertyExpressionEngine::CopyOnLinkReplace(const App::DocumentObject engine.reset(new PropertyExpressionEngine); for(auto it2=expressions.begin();it2!=it;++it2) { engine->expressions[it2->first] = ExpressionInfo( - boost::shared_ptr(it2->second.expression->copy())); + std::shared_ptr(it2->second.expression->copy())); } }else if(!expr) expr = it->second.expression; @@ -914,7 +914,7 @@ void PropertyExpressionEngine::setExpressions( AtomicPropertyChange signaller(*this); #ifdef BOOST_NO_CXX11_SMART_PTR for(auto &v : exprs) - setValue(v.first,boost::shared_ptr(v.second.release())); + setValue(v.first,std::shared_ptr(v.second.release())); #else for(auto &v : exprs) setValue(v.first,std::move(v.second)); diff --git a/src/App/PropertyExpressionEngine.h b/src/App/PropertyExpressionEngine.h index 1b343628ea..5510a74961 100644 --- a/src/App/PropertyExpressionEngine.h +++ b/src/App/PropertyExpressionEngine.h @@ -77,16 +77,16 @@ public: virtual Property *CopyOnLinkReplace(const App::DocumentObject *parent, App::DocumentObject *oldObj, App::DocumentObject *newObj) const override; - typedef boost::function expr)> ValidatorFunc; + typedef boost::function expr)> ValidatorFunc; /** * @brief The ExpressionInfo struct encapsulates an expression and a comment. */ struct ExpressionInfo { - boost::shared_ptr expression; /**< The actual expression tree */ + std::shared_ptr expression; /**< The actual expression tree */ - ExpressionInfo(boost::shared_ptr expression = boost::shared_ptr()) { + ExpressionInfo(std::shared_ptr expression = std::shared_ptr()) { this->expression = expression; } @@ -119,7 +119,7 @@ public: void Restore(Base::XMLReader &reader) override; - void setValue(const App::ObjectIdentifier &path, boost::shared_ptr expr); + void setValue(const App::ObjectIdentifier &path, std::shared_ptr expr); const boost::any getPathValue(const App::ObjectIdentifier & path) const override; @@ -147,7 +147,7 @@ public: /* Expression validator */ void setValidator(ValidatorFunc f) { validator = f; } - std::string validateExpression(const App::ObjectIdentifier & path, boost::shared_ptr expr) const; + std::string validateExpression(const App::ObjectIdentifier & path, std::shared_ptr expr) const; void renameExpressions(const std::map &paths); @@ -179,7 +179,7 @@ private: std::vector computeEvaluationOrder(ExecuteOption option); void buildGraphStructures(const App::ObjectIdentifier &path, - const boost::shared_ptr expression, boost::unordered_map &nodes, + const std::shared_ptr expression, boost::unordered_map &nodes, boost::unordered_map &revNodes, std::vector &edges) const; void buildGraph(const ExpressionMap &exprs,