Dune Core Modules (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
20namespace Dune {
21
30 template< class K > class DynamicVector;
31 template< class K >
32 struct DenseMatVecTraits< DynamicVector<K> >
33 {
34 typedef DynamicVector<K> derived_type;
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 >
41 struct FieldTraits< DynamicVector<K> >
42 {
43 typedef typename FieldTraits<K>::field_type field_type;
44 typedef typename FieldTraits<K>::real_type real_type;
45 };
46
51 template< class K >
52 class DynamicVector : public DenseVector< DynamicVector<K> >
53 {
54 std::vector<K> _data;
55
57 public:
58 typedef typename Base::size_type size_type;
59 typedef typename Base::value_type value_type;
60
63
65 explicit DynamicVector (size_type n, value_type c = value_type() ) :
66 _data(n,c)
67 {}
68
71 _data(x._data)
72 {}
73
74 using Base::operator=;
75
76 //==== forward some methods of std::vector
81 size_type capacity() const
82 {
83 return _data.capacity();
84 }
85 void resize (size_type n, value_type c = value_type() )
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,
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
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:223
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:245
size_type size() const
size method
Definition: densevector.hh:285
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:254
Construct a vector with a dynamic size.
Definition: dynvector.hh:53
DynamicVector(const DynamicVector &x)
Constructor making vector with identical coordinates.
Definition: dynvector.hh:70
DynamicVector()
Constructor making uninitialized vector.
Definition: dynvector.hh:62
DynamicVector(size_type n, value_type c=value_type())
Constructor making vector with identical coordinates.
Definition: dynvector.hh:65
size_type capacity() const
Number of elements for which memory has been allocated.
Definition: dynvector.hh:81
Implements the dense vector interface, with an exchangeable storage class.
Implements a generic iterator class for writing stl conformant iterators.
std::istream & operator>>(std::istream &is, Pair< T1, T2 > &pair)
Read a pair or tuple.
Definition: tuples.hh:949
Dune namespace.
Definition: alignment.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)