Loading...
Searching...
No Matches
dynvector.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_DYNVECTOR_HH
#define DUNE_DYNVECTOR_HH
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <complex>
#include <cstring>
#include <initializer_list>
#include <limits>
#include <utility>
#include "boundschecking.hh"
#include "exceptions.hh"
#include "genericiterator.hh"
#include <vector>
#include "densevector.hh"
namespace Dune {
template< class K, class Allocator > class DynamicVector;
template< class K, class Allocator >
struct DenseMatVecTraits< DynamicVector< K, Allocator > >
{
typedef DynamicVector< K, Allocator > derived_type;
typedef std::vector< K, Allocator > container_type;
typedef K value_type;
typedef typename container_type::size_type size_type;
};
template< class K, class Allocator >
struct FieldTraits< DynamicVector< K, Allocator > >
{
typedef typename FieldTraits< K >::field_type field_type;
typedef typename FieldTraits< K >::real_type real_type;
};
template< class K, class Allocator = std::allocator< K > >
class DynamicVector : public DenseVector< DynamicVector< K, Allocator > >
{
std::vector< K, Allocator > _data;
typedef DenseVector< DynamicVector< K, Allocator > > Base;
public:
typedef typename Base::size_type size_type;
typedef typename Base::value_type value_type;
typedef std::vector< K, Allocator > container_type;
typedef Allocator allocator_type;
explicit DynamicVector(const allocator_type &a = allocator_type() ) :
_data( a )
{}
explicit DynamicVector(size_type n, const allocator_type &a = allocator_type() ) :
_data( n, value_type(), a )
{}
DynamicVector( size_type n, value_type c, const allocator_type &a = allocator_type() ) :
_data( n, c, a )
{}
DynamicVector (std::initializer_list<K> const &l) :
_data(l)
{}
DynamicVector(const DynamicVector & x) :
Base(), _data(x._data)
{}
DynamicVector(DynamicVector && x) :
_data(std::move(x._data))
{}
template< class T >
DynamicVector(const DynamicVector< T, Allocator > & x) :
_data(x.begin(), x.end(), x.get_allocator())
{}
template< class X >
DynamicVector(const DenseVector< X > & x, const allocator_type &a = allocator_type() ) :
_data(a)
{
const size_type n = x.size();
_data.reserve(n);
for( size_type i =0; i<n ;++i)
_data.push_back( x[ i ] );
}
using Base::operator=;
DynamicVector &operator=(const DynamicVector &other)
{
_data = other._data;
return *this;
}
DynamicVector &operator=(DynamicVector &&other)
{
_data = std::move(other._data);
return *this;
}
//==== forward some methods of std::vector
size_type capacity() const
{
return _data.capacity();
}
void resize (size_type n, value_type c = value_type() )
{
_data.resize(n,c);
}
void reserve (size_type n)
{
_data.reserve(n);
}
//==== make this thing a vector
size_type size() const { return _data.size(); }
K & operator[](size_type i) {
DUNE_ASSERT_BOUNDS(i < size());
return _data[i];
}
const K & operator[](size_type i) const {
DUNE_ASSERT_BOUNDS(i < size());
return _data[i];
}
K* data() noexcept
{
return _data.data();
}
const K* data() const noexcept
{
return _data.data();
}
const container_type &container () const { return _data; }
container_type &container () { return _data; }
};
template< class K, class Allocator >
inline std::istream &operator>> ( std::istream &in,
DynamicVector< K, Allocator > &v )
{
DynamicVector< K, Allocator > w(v);
for( typename DynamicVector< K, Allocator >::size_type i = 0; i < w.size(); ++i )
in >> w[ i ];
if(in)
v = std::move(w);
return in;
}
} // end namespace
#endif
exceptions.hh
A few common exception classes.
boundschecking.hh
Macro for wrapping boundary checks.
genericiterator.hh
Implements a generic iterator class for writing stl conformant iterators.
densevector.hh
Implements the dense vector interface, with an exchangeable storage class.
Dune::operator>>
std::istream & operator>>(std::istream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition streamoperators.hh:43
DUNE_ASSERT_BOUNDS
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition boundschecking.hh:30
std
STL namespace.
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::DenseVector< DynamicVector< K, Allocator > >::value_type
Traits::value_type value_type
Definition densevector.hh:265
Dune::DynamicVector< K, Allocator >::end
constexpr Iterator end()
Definition densevector.hh:368
Dune::DenseVector< DynamicVector< K, Allocator > >::size_type
Traits::size_type size_type
Definition densevector.hh:274
Dune::DenseVector< DynamicVector< K, std::allocator< K > > >::DenseVector
constexpr DenseVector()=default
Dune::DynamicVector< K, Allocator >::begin
constexpr Iterator begin()
Definition densevector.hh:362
Dune::DenseVector::size
constexpr size_type size() const
size method
Definition densevector.hh:351
Dune::DynamicVector
Construct a vector with a dynamic size.
Definition dynvector.hh:59
Dune::DynamicVector::resize
void resize(size_type n, value_type c=value_type())
Definition dynvector.hh:141
Dune::DynamicVector::DynamicVector
DynamicVector(const DynamicVector &x)
Constructor making vector with identical coordinates.
Definition dynvector.hh:91
Dune::DynamicVector< K, Allocator >::size_type
Base::size_type size_type
Definition dynvector.hh:64
Dune::DynamicVector< K, Allocator >::container_type
std::vector< K, Allocator > container_type
Definition dynvector.hh:67
Dune::DynamicVector::size
size_type size() const
Definition dynvector.hh:151
Dune::DynamicVector::operator[]
K & operator[](size_type i)
Definition dynvector.hh:152
Dune::DynamicVector::container
container_type & container()
Definition dynvector.hh:174
Dune::DynamicVector< K, Allocator >::value_type
Base::value_type value_type
Definition dynvector.hh:65
Dune::DynamicVector::data
const K * data() const noexcept
return pointer to underlying array
Definition dynvector.hh:168
Dune::DynamicVector< K, Allocator >::allocator_type
Allocator allocator_type
Definition dynvector.hh:69
Dune::DynamicVector::DynamicVector
DynamicVector(const allocator_type &a=allocator_type())
Constructor making uninitialized vector.
Definition dynvector.hh:72
Dune::DynamicVector::DynamicVector
DynamicVector(DynamicVector &&x)
Move constructor.
Definition dynvector.hh:96
Dune::DynamicVector::data
K * data() noexcept
return pointer to underlying array
Definition dynvector.hh:162
Dune::DynamicVector::operator=
DynamicVector & operator=(DynamicVector &&other)
Move assignment operator.
Definition dynvector.hh:126
Dune::DynamicVector::operator=
DynamicVector & operator=(const DynamicVector &other)
Copy assignment operator.
Definition dynvector.hh:119
Dune::DynamicVector::capacity
size_type capacity() const
Number of elements for which memory has been allocated.
Definition dynvector.hh:137
Dune::DynamicVector::container
const container_type & container() const
Definition dynvector.hh:173
Dune::DynamicVector::DynamicVector
DynamicVector(size_type n, const allocator_type &a=allocator_type())
Definition dynvector.hh:76
Dune::DynamicVector::DynamicVector
DynamicVector(std::initializer_list< K > const &l)
Construct from a std::initializer_list.
Definition dynvector.hh:86
Dune::DynamicVector::DynamicVector
DynamicVector(const DynamicVector< T, Allocator > &x)
Definition dynvector.hh:101
Dune::DynamicVector::operator[]
const K & operator[](size_type i) const
Definition dynvector.hh:156
Dune::DynamicVector::reserve
void reserve(size_type n)
Definition dynvector.hh:145
Dune::DynamicVector::DynamicVector
DynamicVector(size_type n, value_type c, const allocator_type &a=allocator_type())
Constructor making vector with identical coordinates.
Definition dynvector.hh:81
Dune::DynamicVector::DynamicVector
DynamicVector(const DenseVector< X > &x, const allocator_type &a=allocator_type())
Copy constructor from another DenseVector.
Definition dynvector.hh:107
Dune::DenseMatVecTraits< DynamicVector< K, Allocator > >::value_type
K value_type
Definition dynvector.hh:40
Dune::DenseMatVecTraits< DynamicVector< K, Allocator > >::derived_type
DynamicVector< K, Allocator > derived_type
Definition dynvector.hh:38
Dune::DenseMatVecTraits< DynamicVector< K, Allocator > >::container_type
std::vector< K, Allocator > container_type
Definition dynvector.hh:39
Dune::DenseMatVecTraits< DynamicVector< K, Allocator > >::size_type
container_type::size_type size_type
Definition dynvector.hh:41
Dune::FieldTraits< DynamicVector< K, Allocator > >::real_type
FieldTraits< K >::real_type real_type
Definition dynvector.hh:48
Dune::FieldTraits< DynamicVector< K, Allocator > >::field_type
FieldTraits< K >::field_type field_type
Definition dynvector.hh:47
Dune::FieldTraits
Definition ftraits.hh:26
Dune::FieldTraits::field_type
T field_type
export the type representing the field
Definition ftraits.hh:28
Dune::FieldTraits::real_type
T real_type
export the type representing the real type of the field
Definition ftraits.hh:30
Dune::DenseMatVecTraits
Definition matvectraits.hh:31