Skip to content
Snippets Groups Projects
Commit 1266505c authored by graeser's avatar graeser Committed by graeser
Browse files

Use shared_ptr

[[Imported from SVN: r12421]]
parent de753e85
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <dune/istl/bcrsmatrix.hh> #include <dune/istl/bcrsmatrix.hh>
#include <dune/common/fmatrix.hh> #include <dune/common/fmatrix.hh>
#include <dune/common/bitsetvector.hh> #include <dune/common/bitsetvector.hh>
#include <dune/common/shared_ptr.hh>
#include <dune/solvers/operators/sumoperator.hh> #include <dune/solvers/operators/sumoperator.hh>
#include <dune/solvers/common/staticmatrixtools.hh> #include <dune/solvers/common/staticmatrixtools.hh>
...@@ -43,15 +44,15 @@ public: ...@@ -43,15 +44,15 @@ public:
CompressedMultigridTransfer() CompressedMultigridTransfer()
{ {
matrix_ = new TransferOperatorType; matrix_ = Dune::make_shared<TransferOperatorType>();
matrixInternallyAllocated = true;
} }
CompressedMultigridTransfer(typename Dune::shared_ptr<TransferOperatorType>& matrix) :
matrix_(matrix)
{}
virtual ~CompressedMultigridTransfer() virtual ~CompressedMultigridTransfer()
{ {}
if (matrixInternallyAllocated)
delete matrix_;
}
/** \brief Sets up the operator between two P1 spaces /** \brief Sets up the operator between two P1 spaces
...@@ -134,22 +135,23 @@ public: ...@@ -134,22 +135,23 @@ public:
return *matrix_; return *matrix_;
} }
/** \brief Set matrix! */
void setMatrix(typename Dune::shared_ptr<TransferOperatorType>& matrix)
{
matrix_ = matrix;
}
/** \brief Set matrix! */ /** \brief Set matrix! */
void setMatrix(TransferOperatorType& matrix) void setMatrix(TransferOperatorType& matrix)
{ {
if (matrixInternallyAllocated) matrix_ = Dune::stackobject_to_shared_ptr<TransferOperatorType>(matrix);
delete matrix_;
matrixInternallyAllocated = false;
matrix_ = &matrix;
} }
protected: protected:
TransferOperatorType* matrix_; typename Dune::shared_ptr<TransferOperatorType> matrix_;
bool matrixInternallyAllocated;
}; };
template< template<
...@@ -173,15 +175,15 @@ public: ...@@ -173,15 +175,15 @@ public:
CompressedMultigridTransfer() CompressedMultigridTransfer()
{ {
matrix_ = new TransferOperatorType; matrix_ = Dune::make_shared<TransferOperatorType>();
matrixInternallyAllocated = true;
} }
CompressedMultigridTransfer(typename Dune::shared_ptr<TransferOperatorType>& matrix) :
matrix_(matrix)
{}
virtual ~CompressedMultigridTransfer() virtual ~CompressedMultigridTransfer()
{ {}
if (matrixInternallyAllocated)
delete matrix_;
}
/** \brief Sets up the operator between two P1 spaces /** \brief Sets up the operator between two P1 spaces
...@@ -285,22 +287,23 @@ public: ...@@ -285,22 +287,23 @@ public:
return *matrix_; return *matrix_;
} }
/** \brief Set matrix! */
void setMatrix(typename Dune::shared_ptr<TransferOperatorType>& matrix)
{
matrix_ = matrix;
}
/** \brief Set matrix! */ /** \brief Set matrix! */
void setMatrix(TransferOperatorType& matrix) void setMatrix(TransferOperatorType& matrix)
{ {
if (matrixInternallyAllocated) matrix_ = Dune::stackobject_to_shared_ptr<TransferOperatorType>(matrix);
delete matrix_;
matrixInternallyAllocated = false;
matrix_ = &matrix;
} }
protected: protected:
TransferOperatorType* matrix_; typename Dune::shared_ptr<TransferOperatorType> matrix_;
bool matrixInternallyAllocated;
}; };
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment