dune-common  2.3.1
dynvector.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // $Id: fvector.hh 6105 2010-08-25 16:06:36Z christi $
4 #ifndef DUNE_DYNVECTOR_HH
5 #define DUNE_DYNVECTOR_HH
6 
7 #include <cmath>
8 #include <cstddef>
9 #include <cstdlib>
10 #include <complex>
11 #include <cstring>
12 #include <limits>
13 
14 #include "exceptions.hh"
15 #include "genericiterator.hh"
16 
17 #include <vector>
18 #include "densevector.hh"
19 
20 namespace Dune {
21 
30  template< class K > class DynamicVector;
31  template< class K >
33  {
35  typedef std::vector<K> container_type;
36  typedef K value_type;
37  typedef typename container_type::size_type size_type;
38  };
39 
40  template< class K >
42  {
45  };
46 
51  template< class K >
52  class DynamicVector : public DenseVector< DynamicVector<K> >
53  {
54  std::vector<K> _data;
55 
56  typedef DenseVector< DynamicVector<K> > Base;
57  public:
58  typedef typename Base::size_type size_type;
59  typedef typename Base::value_type value_type;
60 
63 
66  _data(n,c)
67  {}
68 
71  _data(x._data)
72  {}
73 
74  using Base::operator=;
75 
76  //==== forward some methods of std::vector
82  {
83  return _data.capacity();
84  }
86  {
87  _data.resize(n,c);
88  }
89  void reserve (size_type n)
90  {
91  _data.reserve(n);
92  }
93 
94  //==== make this thing a vector
95  size_type vec_size() const { return _data.size(); }
96  K & vec_access(size_type i) { return _data[i]; }
97  const K & vec_access(size_type i) const { return _data[i]; }
98  };
99 
111  template<class K>
112  inline std::istream &operator>> ( std::istream &in,
113  DynamicVector<K> &v )
114  {
115  DynamicVector<K> w(v);
116  for( typename DynamicVector<K>::size_type i = 0; i < w.size(); ++i )
117  in >> w[ i ];
118  if(in)
119  v = w;
120  return in;
121  }
122 
125 } // end namespace
126 
127 #endif
size_type capacity() const
Number of elements for which memory has been allocated.
Definition: dynvector.hh:81
char c
Definition: alignment.hh:37
std::istream & operator>>(std::istream &is, Pair< T1, T2 > &pair)
Read a pair or tuple.
Definition: tuples.hh:949
Definition: ftraits.hh:23
FieldTraits< K >::field_type field_type
Definition: dynvector.hh:43
Implements a generic iterator class for writing stl conformant iterators.
A few common exception classes.
DynamicVector< K > derived_type
Definition: dynvector.hh:34
DynamicVector(const DynamicVector &x)
Constructor making vector with identical coordinates.
Definition: dynvector.hh:70
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:254
container_type::size_type size_type
Definition: dynvector.hh:37
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:245
DynamicVector(size_type n, value_type c=value_type())
Constructor making vector with identical coordinates.
Definition: dynvector.hh:65
void resize(size_type n, value_type c=value_type())
Definition: dynvector.hh:85
size_type size() const
size method
Definition: densevector.hh:285
K value_type
Definition: dynvector.hh:36
size_type vec_size() const
Definition: dynvector.hh:95
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:17
Base::value_type value_type
Definition: dynvector.hh:59
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
Implements the dense vector interface, with an exchangeable storage class.
std::vector< K > container_type
Definition: dynvector.hh:35
T field_type
export the type representing the field
Definition: ftraits.hh:26
void reserve(size_type n)
Definition: dynvector.hh:89
DynamicVector()
Constructor making uninitialized vector.
Definition: dynvector.hh:62
FieldTraits< K >::real_type real_type
Definition: dynvector.hh:44
Base::size_type size_type
Definition: dynvector.hh:58
Construct a vector with a dynamic size.
Definition: dynvector.hh:30
const K & vec_access(size_type i) const
Definition: dynvector.hh:97
Definition: matvectraits.hh:30
K & vec_access(size_type i)
Definition: dynvector.hh:96