Skip to content
Snippets Groups Projects
Commit b34fb142 authored by Simon Praetorius's avatar Simon Praetorius
Browse files

Cleanup the constructors

parent b2fdc57a
Branches cherry-pick-3d1b5105
No related tags found
1 merge request!463Cleanup the VariableBlockVector implementation
...@@ -46,6 +46,8 @@ namespace Dune { ...@@ -46,6 +46,8 @@ namespace Dune {
// on the large array. However, access operators have to be // on the large array. However, access operators have to be
// overwritten. // overwritten.
{ {
using Base = Imp::block_vector_unmanaged<B,typename A::size_type>;
// just a shorthand // just a shorthand
using window_type = Imp::BlockVectorWindow<B,A>; using window_type = Imp::BlockVectorWindow<B,A>;
...@@ -95,7 +97,7 @@ namespace Dune { ...@@ -95,7 +97,7 @@ namespace Dune {
* \note object cannot be used yet. The size and block sizes need to be initialized. * \note object cannot be used yet. The size and block sizes need to be initialized.
*/ */
VariableBlockVector () : VariableBlockVector () :
Imp::block_vector_unmanaged<B,size_type>() Base()
{} {}
/** /**
...@@ -105,11 +107,9 @@ namespace Dune { ...@@ -105,11 +107,9 @@ namespace Dune {
* `createbegin()` and `createend()` create-iterators to fill the block sizes. * `createbegin()` and `createend()` create-iterators to fill the block sizes.
*/ */
explicit VariableBlockVector (size_type numBlocks) : explicit VariableBlockVector (size_type numBlocks) :
Imp::block_vector_unmanaged<B,size_type>() Base(),
{ block(numBlocks)
// we can allocate the windows now {}
block.resize(numBlocks);
}
/** /**
* \brief Construct a vector with given number of blocks each having a * \brief Construct a vector with given number of blocks each having a
...@@ -120,14 +120,13 @@ namespace Dune { ...@@ -120,14 +120,13 @@ namespace Dune {
* \param blockSize Number of elements in each block * \param blockSize Number of elements in each block
*/ */
VariableBlockVector (size_type numBlocks, size_type blockSize) : VariableBlockVector (size_type numBlocks, size_type blockSize) :
Imp::block_vector_unmanaged<B,size_type>() Base(),
block(numBlocks),
storage_(numBlocks*blockSize)
{ {
// and we can allocate the big array in the base class // and we can allocate the big array in the base class
storage_.resize(numBlocks*blockSize);
syncBaseArray(); syncBaseArray();
block.resize(numBlocks);
// set the windows into the big array // set the windows into the big array
for (size_type i=0; i<numBlocks; ++i) for (size_type i=0; i<numBlocks; ++i)
block[i].set(blockSize,this->p+(i*blockSize)); block[i].set(blockSize,this->p+(i*blockSize));
...@@ -138,6 +137,7 @@ namespace Dune { ...@@ -138,6 +137,7 @@ namespace Dune {
//! Copy constructor, has copy semantics //! Copy constructor, has copy semantics
VariableBlockVector (const VariableBlockVector& a) : VariableBlockVector (const VariableBlockVector& a) :
Base(static_cast<const Base&>(a)),
block(a.block), block(a.block),
storage_(a.storage_) storage_(a.storage_)
{ {
...@@ -154,15 +154,16 @@ namespace Dune { ...@@ -154,15 +154,16 @@ namespace Dune {
initialized = a.initialized; initialized = a.initialized;
} }
~VariableBlockVector () = default;
//! Move constructor: //! Move constructor:
VariableBlockVector (VariableBlockVector&& tmp) : VariableBlockVector (VariableBlockVector&& tmp) :
VariableBlockVector() Base()
{ {
tmp.swap(*this); tmp.swap(*this);
} }
~VariableBlockVector () = default;
//! Copy and move assignment //! Copy and move assignment
VariableBlockVector& operator= (VariableBlockVector tmp) VariableBlockVector& operator= (VariableBlockVector tmp)
{ {
...@@ -375,7 +376,7 @@ namespace Dune { ...@@ -375,7 +376,7 @@ namespace Dune {
#ifdef DUNE_ISTL_WITH_CHECKING #ifdef DUNE_ISTL_WITH_CHECKING
if (initialized) DUNE_THROW(ISTLError,"no CreateIterator in initialized state"); if (initialized) DUNE_THROW(ISTLError,"no CreateIterator in initialized state");
#endif #endif
return CreateIterator(*this,0, false); return CreateIterator(*this, 0, false);
} }
//! get create iterator pointing to one after the last block //! get create iterator pointing to one after the last block
...@@ -540,8 +541,8 @@ namespace Dune { ...@@ -540,8 +541,8 @@ namespace Dune {
this->n = storage_.size(); this->n = storage_.size();
} }
VectorWindows block; // vector of blocks pointing to the array in the base class VectorWindows block = {}; // vector of blocks pointing to the array in the base class
std::vector<B, A> storage_; std::vector<B, A> storage_ = {};
bool initialized = false; // true if vector has been initialized bool initialized = false; // true if vector has been initialized
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment