From 1266505c598bfd4cb0ee388f64d8781137c410b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20Gr=C3=A4ser?= <graeser@mi.fu-berlin.de> Date: Mon, 2 Dec 2013 20:15:04 +0000 Subject: [PATCH] Use shared_ptr [[Imported from SVN: r12421]] --- .../compressedmultigridtransfer.hh | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/dune/solvers/transferoperators/compressedmultigridtransfer.hh b/dune/solvers/transferoperators/compressedmultigridtransfer.hh index cce655cb..bf99cb81 100644 --- a/dune/solvers/transferoperators/compressedmultigridtransfer.hh +++ b/dune/solvers/transferoperators/compressedmultigridtransfer.hh @@ -4,6 +4,7 @@ #include <dune/istl/bcrsmatrix.hh> #include <dune/common/fmatrix.hh> #include <dune/common/bitsetvector.hh> +#include <dune/common/shared_ptr.hh> #include <dune/solvers/operators/sumoperator.hh> #include <dune/solvers/common/staticmatrixtools.hh> @@ -43,15 +44,15 @@ public: CompressedMultigridTransfer() { - matrix_ = new TransferOperatorType; - matrixInternallyAllocated = true; + matrix_ = Dune::make_shared<TransferOperatorType>(); } + CompressedMultigridTransfer(typename Dune::shared_ptr<TransferOperatorType>& matrix) : + matrix_(matrix) + {} + virtual ~CompressedMultigridTransfer() - { - if (matrixInternallyAllocated) - delete matrix_; - } + {} /** \brief Sets up the operator between two P1 spaces @@ -134,22 +135,23 @@ public: return *matrix_; } + /** \brief Set matrix! */ + void setMatrix(typename Dune::shared_ptr<TransferOperatorType>& matrix) + { + matrix_ = matrix; + } + /** \brief Set matrix! */ void setMatrix(TransferOperatorType& matrix) { - if (matrixInternallyAllocated) - delete matrix_; - matrixInternallyAllocated = false; - matrix_ = &matrix; + matrix_ = Dune::stackobject_to_shared_ptr<TransferOperatorType>(matrix); } protected: - TransferOperatorType* matrix_; - bool matrixInternallyAllocated; - + typename Dune::shared_ptr<TransferOperatorType> matrix_; }; template< @@ -173,15 +175,15 @@ public: CompressedMultigridTransfer() { - matrix_ = new TransferOperatorType; - matrixInternallyAllocated = true; + matrix_ = Dune::make_shared<TransferOperatorType>(); } + CompressedMultigridTransfer(typename Dune::shared_ptr<TransferOperatorType>& matrix) : + matrix_(matrix) + {} + virtual ~CompressedMultigridTransfer() - { - if (matrixInternallyAllocated) - delete matrix_; - } + {} /** \brief Sets up the operator between two P1 spaces @@ -285,22 +287,23 @@ public: return *matrix_; } + /** \brief Set matrix! */ + void setMatrix(typename Dune::shared_ptr<TransferOperatorType>& matrix) + { + matrix_ = matrix; + } + /** \brief Set matrix! */ void setMatrix(TransferOperatorType& matrix) { - if (matrixInternallyAllocated) - delete matrix_; - matrixInternallyAllocated = false; - matrix_ = &matrix; + matrix_ = Dune::stackobject_to_shared_ptr<TransferOperatorType>(matrix); } protected: - TransferOperatorType* matrix_; - bool matrixInternallyAllocated; - + typename Dune::shared_ptr<TransferOperatorType> matrix_; }; #endif -- GitLab