Commit 0d69b9d1 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#527 Add two Swap definitions to avoid compilation of the code: we do not want...

#527 Add two Swap definitions to avoid compilation of the code: we do not want to be able to swap Wrappers::Petsc::Vector and GlobalVector.
parent 26bde411
......@@ -13,6 +13,21 @@ namespace HappyHeart
{
GlobalVector::GlobalVector(const GlobalVector& rhs)
: Parent(rhs)
{ }
void Swap(GlobalVector& A, GlobalVector& B)
{
// \todo #527 Add assert about numbering subset!
using Parent = GlobalVector::Parent;
Swap(static_cast<Parent&>(A), static_cast<Parent&>(B));
}
} // namespace HappyHeart
......@@ -19,7 +19,7 @@ namespace HappyHeart
{
class GlobalVector : public Wrappers::Petsc::Vector
class GlobalVector final : public Wrappers::Petsc::Vector
{
public:
......@@ -29,6 +29,9 @@ namespace HappyHeart
//! Alias to vector of unique pointers.
using vector_unique_ptr = std::vector<unique_ptr>;
//! Alias to parent.
using Parent = Wrappers::Petsc::Vector;
public:
......@@ -42,16 +45,16 @@ namespace HappyHeart
~GlobalVector() = default;
//! Copy constructor.
GlobalVector(const GlobalVector&) = default;
GlobalVector(const GlobalVector&);
//! Move constructor.
GlobalVector(GlobalVector&&) = default;
GlobalVector(GlobalVector&&) = delete;
//! Copy affectation.
GlobalVector& operator=(const GlobalVector&) = default;
GlobalVector& operator=(const GlobalVector&) = delete;
//! Move affectation.
GlobalVector& operator=(GlobalVector&&) = default;
GlobalVector& operator=(GlobalVector&&) = delete;
///@}
......@@ -62,6 +65,22 @@ namespace HappyHeart
};
/*!
* \brief Swap two vectors.
*
* The Petsc content of the vectors is swapped; however the numbering subsets must be the same on both ends
* (we expect here to swap only vectors with same structure).
*/
void Swap(GlobalVector& A, GlobalVector& B);
/*!
* \brief Declare but do not define: we do not want to be able to do this but we also want to avoid the
* 'slicing effect' (attributes of child class ignored entirely).
*/
void Swap(GlobalVector& A, GlobalVector::Parent& B);
void Swap(GlobalVector::Parent& A, GlobalVector& B);
/*!
* \brief Useful typedef to avoid cluttering the main programs with too low-level C++.
......
......@@ -79,7 +79,7 @@ namespace HappyHeart
auto& evaluation_state = vm.GetNonCstEvaluationState();
Wrappers::Petsc::Swap(evaluation_state, buf_evaluation_state);
Swap(evaluation_state, buf_evaluation_state);
}
#ifndef NDEBUG
......
......@@ -20,6 +20,16 @@ namespace HappyHeart
{
void Swap(Wrappers::Petsc::Vector& A, Wrappers::Petsc::Vector& B)
{
using std::swap;
swap(A.do_petsc_destroy_, B.do_petsc_destroy_);
swap(A.petsc_vector_, B.petsc_vector_);
}
namespace Wrappers
{
......@@ -49,14 +59,6 @@ namespace HappyHeart
}
void Swap(Vector& A, Vector& B)
{
using std::swap;
swap(A.do_petsc_destroy_, B.do_petsc_destroy_);
swap(A.petsc_vector_, B.petsc_vector_);
}
Vector::~Vector()
{
......
......@@ -27,6 +27,13 @@
namespace HappyHeart
{
//! Swap two Vectors.
void Swap(Wrappers::Petsc::Vector& A, Wrappers::Petsc::Vector& B);
namespace Wrappers
{
......@@ -457,15 +464,10 @@ namespace HappyHeart
bool do_petsc_destroy_;
//! Friendship.
friend void Swap(Vector& A, Vector& B);
friend void ::HappyHeart::Swap(Vector& A, Vector& B);
};
//! Swap two Vectors.
void Swap(Vector& A, Vector& B);
/*!
* \brief A quick and dirty way to display some values of a petsc vector (for debug purposes)
......@@ -534,6 +536,8 @@ namespace HappyHeart
} // namespace Wrappers
} // namespace HappyHeart
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment