From 8649fc0265c1c23bc01bedf559884dcdef118cc0 Mon Sep 17 00:00:00 2001 From: Oliver Sander <oliver.sander@tu-dresden.de> Date: Tue, 18 Oct 2016 22:28:55 +0200 Subject: [PATCH] Move various implementation classes into the 'Imp' namespace There are various classes in dune-istl that are effectively implementation classes internal to dune-istl. A few of them are base_array_unmanaged, base_array_window, compressed_base_array_unmanaged,block_vector_unmanaged, BlockVectorWindow, compressed_block_vector_unmanaged, CompressedBlockVectorWindow See https://gitlab.dune-project.org/core/dune-istl/issues/22 for a brief discussion. This patch moves the classes into the namespace 'Imp'. That way it is clear that they are internal. All code outside of dune-istl using those classes will break, but does such code really exist? --- dune/istl/basearray.hh | 5 ++++ dune/istl/bcrsmatrix.hh | 2 +- dune/istl/bvector.hh | 46 +++++++++++++++++++-------------- dune/istl/matrix.hh | 10 +++---- dune/istl/test/basearraytest.cc | 6 ++--- dune/istl/test/bvectortest.cc | 4 +-- dune/istl/vbvector.hh | 12 ++++----- 7 files changed, 49 insertions(+), 36 deletions(-) diff --git a/dune/istl/basearray.hh b/dune/istl/basearray.hh index 8cdccd5ee..fec711015 100644 --- a/dune/istl/basearray.hh +++ b/dune/istl/basearray.hh @@ -18,6 +18,9 @@ namespace Dune { +/** \brief Everything in this namespace is internal to dune-istl, and may change without warning */ +namespace Imp { + /** \brief A simple array container for objects of type B Implement. @@ -769,6 +772,8 @@ namespace Dune { size_type* j; // the index set }; +} // end namespace Imp + } // end namespace #endif diff --git a/dune/istl/bcrsmatrix.hh b/dune/istl/bcrsmatrix.hh index 727c83325..7e49b9c85 100644 --- a/dune/istl/bcrsmatrix.hh +++ b/dune/istl/bcrsmatrix.hh @@ -440,7 +440,7 @@ namespace Dune { typedef A allocator_type; //! implement row_type with compressed vector - typedef CompressedBlockVectorWindow<B,A> row_type; + typedef Imp::CompressedBlockVectorWindow<B,A> row_type; //! The type for the index access and the size typedef typename A::size_type size_type; diff --git a/dune/istl/bvector.hh b/dune/istl/bvector.hh index cd988809b..5899518fa 100644 --- a/dune/istl/bvector.hh +++ b/dune/istl/bvector.hh @@ -25,6 +25,8 @@ namespace Dune { +/** \brief Everything in this namespace is internal to dune-istl, and may change without warning */ +namespace Imp { /** \brief An unmanaged vector of blocks. @@ -290,6 +292,7 @@ namespace Dune { { } }; +} // end namespace Imp /** @addtogroup ISTL_SPMV @{ @@ -305,7 +308,7 @@ namespace Dune { enables error checking. */ template<class B, class A=std::allocator<B> > - class BlockVector : public block_vector_unmanaged<B,A> + class BlockVector : public Imp::block_vector_unmanaged<B,A> { public: @@ -330,15 +333,15 @@ namespace Dune { }; //! make iterators available as types - typedef typename block_vector_unmanaged<B,A>::Iterator Iterator; + typedef typename Imp::block_vector_unmanaged<B,A>::Iterator Iterator; //! make iterators available as types - typedef typename block_vector_unmanaged<B,A>::ConstIterator ConstIterator; + typedef typename Imp::block_vector_unmanaged<B,A>::ConstIterator ConstIterator; //===== constructors and such //! makes empty vector - BlockVector () : block_vector_unmanaged<B,A>(), + BlockVector () : Imp::block_vector_unmanaged<B,A>(), capacity_(0) {} @@ -432,7 +435,7 @@ namespace Dune { */ void reserve(size_type capacity, bool copyOldValues=true) { - if(capacity >= block_vector_unmanaged<B,A>::N() && capacity != capacity_) { + if(capacity >= Imp::block_vector_unmanaged<B,A>::N() && capacity != capacity_) { // save the old data B* pold = this->p; @@ -446,7 +449,7 @@ namespace Dune { B* to = this->p; B* from = pold; - for(size_type i=0; i < block_vector_unmanaged<B,A>::N(); ++i, ++from, ++to) + for(size_type i=0; i < Imp::block_vector_unmanaged<B,A>::N(); ++i, ++from, ++to) *to = *from; } if(capacity_ > 0) { @@ -494,7 +497,7 @@ namespace Dune { */ void resize(size_type size, bool copyOldValues=true) { - if(size > block_vector_unmanaged<B,A>::N()) + if (size > Imp::block_vector_unmanaged<B,A>::N()) if(capacity_ < size) this->reserve(size, copyOldValues); this->n = size; @@ -505,7 +508,7 @@ namespace Dune { //! copy constructor BlockVector (const BlockVector& a) : - block_vector_unmanaged<B,A>(a) + Imp::block_vector_unmanaged<B,A>(a) { // allocate memory with same size as a this->n = a.n; @@ -525,7 +528,7 @@ namespace Dune { } //! construct from base class object - BlockVector (const block_vector_unmanaged<B,A>& _a) + BlockVector (const Imp::block_vector_unmanaged<B,A>& _a) { // upcast, because protected data inaccessible const BlockVector& a = static_cast<const BlockVector&>(_a); @@ -592,7 +595,7 @@ namespace Dune { } //! assign from base class object - BlockVector& operator= (const block_vector_unmanaged<B,A>& a) + BlockVector& operator= (const Imp::block_vector_unmanaged<B,A>& a) { // forward to regular assignement operator return this->operator=(static_cast<const BlockVector&>(a)); @@ -602,7 +605,7 @@ namespace Dune { BlockVector& operator= (const field_type& k) { // forward to operator= in base class - (static_cast<block_vector_unmanaged<B,A>&>(*this)) = k; + (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k; return *this; } protected: @@ -639,6 +642,9 @@ namespace Dune { return s; } +/** \brief Everything in this namespace is internal to dune-istl, and may change without warning */ +namespace Imp { + /** BlockVectorWindow adds window manipulation functions to the block_vector_unmanaged template. @@ -656,7 +662,7 @@ namespace Dune { enables error checking. */ template<class B, class A=std::allocator<B> > - class BlockVectorWindow : public block_vector_unmanaged<B,A> + class BlockVectorWindow : public Imp::block_vector_unmanaged<B,A> { public: @@ -681,15 +687,15 @@ namespace Dune { }; //! make iterators available as types - typedef typename block_vector_unmanaged<B,A>::Iterator Iterator; + typedef typename Imp::block_vector_unmanaged<B,A>::Iterator Iterator; //! make iterators available as types - typedef typename block_vector_unmanaged<B,A>::ConstIterator ConstIterator; + typedef typename Imp::block_vector_unmanaged<B,A>::ConstIterator ConstIterator; //===== constructors and such //! makes empty array - BlockVectorWindow () : block_vector_unmanaged<B,A>() + BlockVectorWindow () : Imp::block_vector_unmanaged<B,A>() { } //! make array from given pointer and size @@ -707,7 +713,7 @@ namespace Dune { } //! construct from base class object with reference semantics! - BlockVectorWindow (const block_vector_unmanaged<B,A>& _a) + BlockVectorWindow (const Imp::block_vector_unmanaged<B,A>& _a) { // cast needed to access protected data const BlockVectorWindow& a = static_cast<const BlockVectorWindow&>(_a); @@ -735,7 +741,7 @@ namespace Dune { } //! assign from base class object - BlockVectorWindow& operator= (const block_vector_unmanaged<B,A>& a) + BlockVectorWindow& operator= (const Imp::block_vector_unmanaged<B,A>& a) { // forward to regular assignment operator return this->operator=(static_cast<const BlockVectorWindow&>(a)); @@ -744,7 +750,7 @@ namespace Dune { //! assign from scalar BlockVectorWindow& operator= (const field_type& k) { - (static_cast<block_vector_unmanaged<B,A>&>(*this)) = k; + (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k; return *this; } @@ -1201,6 +1207,8 @@ namespace Dune { } }; -} // end namespace +} // end namespace 'Imp' + +} // end namespace 'Dune' #endif diff --git a/dune/istl/matrix.hh b/dune/istl/matrix.hh index e8f8e1563..b474b63ac 100644 --- a/dune/istl/matrix.hh +++ b/dune/istl/matrix.hh @@ -31,7 +31,7 @@ namespace MatrixImp elegant solution. */ template<class B, class A=std::allocator<B> > - class DenseMatrixBase : public block_vector_unmanaged<B,A> + class DenseMatrixBase : public Imp::block_vector_unmanaged<B,A> // this derivation gives us all the blas level 1 and norms // on the large array. However, access operators have to be // overwritten. @@ -61,7 +61,7 @@ namespace MatrixImp typedef BlockVector<B,A> block_type; // just a shorthand - typedef BlockVectorWindow<B,A> window_type; + typedef Imp::BlockVectorWindow<B,A> window_type; typedef window_type reference; @@ -73,7 +73,7 @@ namespace MatrixImp /** constructor without arguments makes empty vector, object cannot be used yet */ - DenseMatrixBase () : block_vector_unmanaged<B,A>() + DenseMatrixBase () : Imp::block_vector_unmanaged<B,A>() { // nothing is known ... rows_ = 0; @@ -86,7 +86,7 @@ namespace MatrixImp \param _nblocks Number of blocks \param m Number of elements in each block */ - DenseMatrixBase (size_type rows, size_type columns) : block_vector_unmanaged<B,A>() + DenseMatrixBase (size_type rows, size_type columns) : Imp::block_vector_unmanaged<B,A>() { // and we can allocate the big array in the base class this->n = rows*columns; @@ -222,7 +222,7 @@ namespace MatrixImp //! assign from scalar DenseMatrixBase& operator= (const field_type& k) { - (static_cast<block_vector_unmanaged<B,A>&>(*this)) = k; + (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k; return *this; } diff --git a/dune/istl/test/basearraytest.cc b/dune/istl/test/basearraytest.cc index c7da73a57..65fa5aa42 100644 --- a/dune/istl/test/basearraytest.cc +++ b/dune/istl/test/basearraytest.cc @@ -8,11 +8,11 @@ using namespace Dune; int main() { - base_array<double> v1(10); - base_array<double> v2 = v1; + Imp::base_array<double> v1(10); + Imp::base_array<double> v2 = v1; // Test constructor from base_array_unmanaged - base_array<double> v3 = *(static_cast<base_array_unmanaged<double>*>(&v1)); + Imp::base_array<double> v3 = *(static_cast<Imp::base_array_unmanaged<double>*>(&v1)); v1.resize(20); diff --git a/dune/istl/test/bvectortest.cc b/dune/istl/test/bvectortest.cc index b250531d1..e47f81f4f 100644 --- a/dune/istl/test/bvectortest.cc +++ b/dune/istl/test/bvectortest.cc @@ -61,7 +61,7 @@ int testVector() for(typename Vector::size_type i=0; i < v.N(); ++i) assert(v[i] == w[i]); - w = static_cast<const Dune::block_vector_unmanaged<VectorBlock,Alloc>&>(v); + w = static_cast<const Dune::Imp::block_vector_unmanaged<VectorBlock,Alloc>&>(v); for(typename Vector::size_type i=0; i < w.N(); ++i) assert(v[i] == w[i]); @@ -74,7 +74,7 @@ int testVector() for(typename Vector::size_type i=0; i < w.N(); ++i) assert(z[i] == w[i]); - Vector z1(static_cast<const Dune::block_vector_unmanaged<VectorBlock,Alloc>&>(v2)); + Vector z1(static_cast<const Dune::Imp::block_vector_unmanaged<VectorBlock,Alloc>&>(v2)); assert(v2.N()==z1.N()); assert(v2.capacity()==z1.capacity()); diff --git a/dune/istl/vbvector.hh b/dune/istl/vbvector.hh index aa7779d3f..396d76a0c 100644 --- a/dune/istl/vbvector.hh +++ b/dune/istl/vbvector.hh @@ -34,13 +34,13 @@ namespace Dune { */ template<class B, class A=std::allocator<B> > - class VariableBlockVector : public block_vector_unmanaged<B,A> + class VariableBlockVector : public Imp::block_vector_unmanaged<B,A> // this derivation gives us all the blas level 1 and norms // on the large array. However, access operators have to be // overwritten. { // just a shorthand - typedef BlockVectorWindow<B,A> window_type; + typedef Imp::BlockVectorWindow<B,A> window_type; public: @@ -91,7 +91,7 @@ namespace Dune { /** constructor without arguments makes empty vector, object cannot be used yet */ - VariableBlockVector () : block_vector_unmanaged<B,A>() + VariableBlockVector () : Imp::block_vector_unmanaged<B,A>() { // nothing is known ... nblocks = 0; @@ -102,7 +102,7 @@ namespace Dune { /** make vector with given number of blocks, but size of each block is not yet known, object cannot be used yet */ - explicit VariableBlockVector (size_type _nblocks) : block_vector_unmanaged<B,A>() + explicit VariableBlockVector (size_type _nblocks) : Imp::block_vector_unmanaged<B,A>() { // we can allocate the windows now nblocks = _nblocks; @@ -128,7 +128,7 @@ namespace Dune { \param _nblocks Number of blocks \param m Number of elements in each block */ - VariableBlockVector (size_type _nblocks, size_type m) : block_vector_unmanaged<B,A>() + VariableBlockVector (size_type _nblocks, size_type m) : Imp::block_vector_unmanaged<B,A>() { // and we can allocate the big array in the base class this->n = _nblocks*m; @@ -392,7 +392,7 @@ namespace Dune { //! assign from scalar VariableBlockVector& operator= (const field_type& k) { - (static_cast<block_vector_unmanaged<B,A>&>(*this)) = k; + (static_cast<Imp::block_vector_unmanaged<B,A>&>(*this)) = k; return *this; } -- GitLab