From 7a5e4b726c2315e95c5f4e715b2baa92f2721671 Mon Sep 17 00:00:00 2001 From: Felix Schindler <felix.schindler@wwu.de> Date: Thu, 6 Oct 2016 14:58:43 +0200 Subject: [PATCH] [container] make ensure_uniqueness protected And require it in ContainerInterface. This will allow interface default implementations to call ensure_uniqueness() only one in a for loop. --- dune/xt/la/container/common.hh | 8 ++++++-- dune/xt/la/container/container-interface.hh | 7 +++++++ dune/xt/la/container/eigen/base.hh | 3 ++- dune/xt/la/container/eigen/dense.hh | 7 ++++++- dune/xt/la/container/eigen/sparse.hh | 3 ++- dune/xt/la/container/istl.hh | 5 ++++- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/dune/xt/la/container/common.hh b/dune/xt/la/container/common.hh index da967281f..a01c0b00f 100644 --- a/dune/xt/la/container/common.hh +++ b/dune/xt/la/container/common.hh @@ -346,7 +346,7 @@ public: /// \} -private: +protected: /** * \see ContainerInterface */ @@ -356,6 +356,7 @@ private: backend_ = std::make_shared<BackendType>(*backend_); } // ... ensure_uniqueness(...) +private: friend class VectorInterface<internal::CommonDenseVectorTraits<ScalarType>, ScalarType>; friend class CommonDenseMatrix<ScalarType>; @@ -598,7 +599,7 @@ public: /// \} -private: +protected: /** * \see ContainerInterface */ @@ -608,6 +609,7 @@ private: backend_ = std::make_shared<BackendType>(*backend_); } // ... ensure_uniqueness(...) +private: mutable std::shared_ptr<BackendType> backend_; }; // class CommonDenseMatrix @@ -909,12 +911,14 @@ private: return size_t(-1); } +protected: inline void ensure_uniqueness() const { if (!backend_.unique()) backend_ = std::make_shared<BackendType>(*backend_); } // ... ensure_uniqueness(...) +private: size_t num_rows_, num_cols_; mutable std::shared_ptr<BackendType> backend_; std::shared_ptr<IndexVectorType> row_pointers_; diff --git a/dune/xt/la/container/container-interface.hh b/dune/xt/la/container/container-interface.hh index 97af127ad..80279d071 100644 --- a/dune/xt/la/container/container-interface.hh +++ b/dune/xt/la/container/container-interface.hh @@ -176,6 +176,13 @@ public: return this->as_imp().has_equal_shape(other); } +protected: + inline void ensure_uniqueness() + { + CHECK_AND_CALL_CRTP(this->as_imp().ensure_uniqueness()); + } + +public: /// \} /// \name Are provided by the interface for convenience! /// \note Those marked as virtual may be implemented more efficiently in a derived class! diff --git a/dune/xt/la/container/eigen/base.hh b/dune/xt/la/container/eigen/base.hh index bc8334f0f..ea1f806c1 100644 --- a/dune/xt/la/container/eigen/base.hh +++ b/dune/xt/la/container/eigen/base.hh @@ -286,7 +286,7 @@ public: //! disambiguation necessary since it exists in multiple bases using VectorInterfaceType::as_imp; -private: +protected: /** * \see ContainerInterface */ @@ -296,6 +296,7 @@ private: VectorInterfaceType::as_imp().ensure_uniqueness(); } +private: #ifndef NDEBUG //! disambiguation necessary since it exists in multiple bases using VectorInterfaceType::crtp_mutex_; diff --git a/dune/xt/la/container/eigen/dense.hh b/dune/xt/la/container/eigen/dense.hh index e57ec92d6..dfdd9e64c 100644 --- a/dune/xt/la/container/eigen/dense.hh +++ b/dune/xt/la/container/eigen/dense.hh @@ -196,12 +196,14 @@ public: private: using BaseType::backend_; +protected: inline void ensure_uniqueness() { if (!backend_.unique()) backend_ = std::make_shared<BackendType>(*(backend_)); } // ... ensure_uniqueness(...) +private: friend class EigenBaseVector<internal::EigenDenseVectorTraits<ScalarType>, ScalarType>; }; // class EigenDenseVector @@ -313,6 +315,7 @@ public: private: using BaseType::backend_; +protected: inline void ensure_uniqueness() const { if (!backend_.unique()) { @@ -322,6 +325,7 @@ private: } } // ... ensure_uniqueness(...) +private: friend class EigenBaseVector<internal::EigenMappedDenseVectorTraits<ScalarType>, ScalarType>; }; // class EigenMappedDenseVector @@ -583,13 +587,14 @@ public: * \} */ -private: +protected: inline void ensure_uniqueness() { if (!backend_.unique()) backend_ = std::make_shared<BackendType>(*backend_); } // ... ensure_uniqueness(...) +private: std::shared_ptr<BackendType> backend_; }; // class EigenDenseMatrix diff --git a/dune/xt/la/container/eigen/sparse.hh b/dune/xt/la/container/eigen/sparse.hh index 3dce30dc3..01ac1319d 100644 --- a/dune/xt/la/container/eigen/sparse.hh +++ b/dune/xt/la/container/eigen/sparse.hh @@ -423,12 +423,13 @@ private: return false; } // ... these_are_valid_indices(...) +protected: inline void ensure_uniqueness() { if (!backend_.unique()) backend_ = std::make_shared<BackendType>(*backend_); } // ... ensure_uniqueness(...) - +private: std::shared_ptr<BackendType> backend_; }; // class EigenRowMajorSparseMatrix diff --git a/dune/xt/la/container/istl.hh b/dune/xt/la/container/istl.hh index 7a6f2c58a..9b02745ab 100644 --- a/dune/xt/la/container/istl.hh +++ b/dune/xt/la/container/istl.hh @@ -355,7 +355,7 @@ public: /// \} -private: +protected: /** * \see ContainerInterface */ @@ -365,6 +365,7 @@ private: backend_ = std::make_shared<BackendType>(*backend_); } // ... ensure_uniqueness(...) +private: friend class VectorInterface<internal::IstlDenseVectorTraits<ScalarType>, ScalarType>; friend class IstlRowMajorSparseMatrix<ScalarType>; @@ -703,6 +704,7 @@ private: return backend_->exists(ii, jj); } // ... these_are_valid_indices(...) +protected: /** * \see ContainerInterface */ @@ -712,6 +714,7 @@ private: backend_ = std::make_shared<BackendType>(*backend_); } // ... ensure_uniqueness(...) +private: mutable std::shared_ptr<BackendType> backend_; }; // class IstlRowMajorSparseMatrix -- GitLab