dune-fem  2.4.1-rc
referencevector.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_COMMON_REFERENCEVECTOR_HH
2 #define DUNE_FEM_COMMON_REFERENCEVECTOR_HH
3 
4 #include <cmath>
5 #include <complex>
6 #include <cstddef>
7 #include <cstdlib>
8 #include <cstring>
9 #include <limits>
10 #include <utility>
11 #include <vector>
12 
13 #include <dune/common/exceptions.hh>
14 #include <dune/common/densevector.hh>
15 #include <dune/common/nullptr.hh>
16 
17 namespace Dune
18 {
19 
20  namespace Fem
21  {
22  template< class K, class A = std::allocator< K* > >
24  }
25 
26 
27  template< class K, class A >
28  struct DenseMatVecTraits< Fem::DynamicReferenceVector< K, A > >
29  {
31  typedef std::vector< K*, typename A::template rebind< K* >::other > container_type;
32 
33  typedef K value_type;
34  typedef typename container_type::size_type size_type;
35  };
36 
37  template< class K, class A >
38  struct FieldTraits< Fem::DynamicReferenceVector< K, A > >
39  {
40  typedef typename FieldTraits< K >::field_type field_type;
41  typedef typename FieldTraits< K >::real_type real_type;
42  };
43 
44  namespace Fem
45  {
46 
60  template< class K, class A >
61  class DynamicReferenceVector : public DenseVector< DynamicReferenceVector< K, A > >
62  {
63  typedef DynamicReferenceVector< K, A > This;
64  typedef DenseVector< DynamicReferenceVector < K, A > > Base;
65 
66  typename DenseMatVecTraits< This > :: container_type data_;
67  public:
68  typedef typename Base::size_type size_type;
69  typedef typename Base::value_type value_type;
70 
72  explicit DynamicReferenceVector ( const A &a = A() )
73  : data_( a )
74  {}
75 
77  explicit DynamicReferenceVector ( size_type n, const A &a = A() )
78  : data_( n, nullptr, a )
79  {}
80 
81  DynamicReferenceVector ( const This &other )
82  : data_( other.data_ )
83  {}
84 
85  DynamicReferenceVector ( This &&other )
86  : data_( std::move( other.data_ ) )
87  {}
88 
90  using Base::operator=;
91 
92  template< class V >
93  This & operator= ( const DenseVector< V > &other )
94  {
95  assert( data_.size() == other.size() );
96  std::copy( other.begin(), other.end(), Base::begin() );
97  return *this;
98  }
99 
100  This & operator= ( const This &other )
101  {
102  assert( data_.size() == other.size() );
103  std::copy( other.begin(), other.end(), Base::begin() );
104  return *this;
105  }
106 
107  This & operator= ( This &&other )
108  {
109  data_ = std::move( other.data_ );
110  return *this;
111  }
112 
113  //==== forward some methods of std::vector
118  size_type capacity () const { return data_.capacity(); }
119 
120  void resize ( size_type n ) { data_.resize( n, nullptr ); }
121  void reserve ( size_type n ) { data_.reserve( n ); }
122 
124  void bind ( size_type i, K& u ) { assert( i < data_.size() ); data_[ i ] = &u; }
125  void unbind ( size_type i ) { asssert( i < data_.size() ); data_[ i ] = nullptr; }
126 
127  //==== make this thing a vector
128  size_type vec_size () const { return data_.size(); }
129 
130  K &vec_access ( size_type i ) { return *data_[ i ]; }
131  const K &vec_access ( size_type i ) const { return *data_[ i ]; }
132  };
133 
136  } // namespace Fem
137 
138 
139 } // namespace Dune
140 
141 #endif //#ifndef DUNE_FEM_COMMON_REFERENCEVECTOR_HH
const K & vec_access(size_type i) const
Definition: referencevector.hh:131
Base::size_type size_type
Definition: referencevector.hh:68
Fem::DynamicReferenceVector< K, A > derived_type
Definition: referencevector.hh:30
container_type::size_type size_type
Definition: referencevector.hh:34
K & vec_access(size_type i)
Definition: referencevector.hh:130
DynamicReferenceVector(This &&other)
Definition: referencevector.hh:85
size_type vec_size() const
Definition: referencevector.hh:128
DynamicReferenceVector(const A &a=A())
Constructor making uninitialized vector.
Definition: referencevector.hh:72
Construct a vector with a dynamic size.
Definition: referencevector.hh:23
DynamicReferenceVector(const This &other)
Definition: referencevector.hh:81
Base::value_type value_type
Definition: referencevector.hh:69
void unbind(size_type i)
Definition: referencevector.hh:125
std::vector< K *, typename A::template rebind< K * >::other > container_type
Definition: referencevector.hh:31
void reserve(size_type n)
Definition: referencevector.hh:121
FieldTraits< K >::real_type real_type
Definition: referencevector.hh:41
Definition: coordinate.hh:4
void resize(size_type n)
Definition: referencevector.hh:120
STL namespace.
FieldTraits< K >::field_type field_type
Definition: referencevector.hh:40
size_type capacity() const
Number of elements for which memory has been allocated.
Definition: referencevector.hh:118
DynamicReferenceVector(size_type n, const A &a=A())
Constructor making vector with identical coordinates.
Definition: referencevector.hh:77
void move(ArrayInterface< T > &array, const unsigned int oldOffset, const unsigned int newOffset, const unsigned int length)
Definition: array_inline.hh:38
void bind(size_type i, K &u)
bind i-th entry to a reference
Definition: referencevector.hh:124