Dune Core Modules (2.4.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#ifndef DUNE_DYNVECTOR_HH
4#define DUNE_DYNVECTOR_HH
5
6#include <cmath>
7#include <cstddef>
8#include <cstdlib>
9#include <complex>
10#include <cstring>
11#include <limits>
12#include <utility>
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 Allocator > class DynamicVector;
31 template< class K, class Allocator >
32 struct DenseMatVecTraits< DynamicVector< K, Allocator > >
33 {
34 typedef DynamicVector< K, Allocator > derived_type;
35 typedef std::vector< K, Allocator > container_type;
36 typedef K value_type;
37 typedef typename container_type::size_type size_type;
38 };
39
40 template< class K, class Allocator >
41 struct FieldTraits< DynamicVector< K, Allocator > >
42 {
43 typedef typename FieldTraits< K >::field_type field_type;
44 typedef typename FieldTraits< K >::real_type real_type;
45 };
46
53 template< class K, class Allocator = std::allocator< K > >
54 class DynamicVector : public DenseVector< DynamicVector< K, Allocator > >
55 {
56 std::vector< K, Allocator > _data;
57
59 public:
60 typedef typename Base::size_type size_type;
61 typedef typename Base::value_type value_type;
62
63 typedef Allocator allocator_type;
64
66 explicit DynamicVector(const allocator_type &a = allocator_type() ) :
67 _data( a )
68 {}
69
70 explicit DynamicVector(size_type n, const allocator_type &a = allocator_type() ) :
71 _data( n, value_type(), a )
72 {}
73
75 DynamicVector( size_type n, value_type c, const allocator_type &a = allocator_type() ) :
76 _data( n, c, a )
77 {}
78
81 Base(), _data(x._data)
82 {}
83
86 _data(std::move(x._data))
87 {}
88
89 template< class T >
91 _data(x.begin(), x.end(), x.get_allocator())
92 {}
93
95 template< class X >
96 DynamicVector(const DenseVector< X > & x, const allocator_type &a = allocator_type() ) :
97 _data(a)
98 {
99 const size_type n = x.size();
100 _data.reserve(n);
101 for( size_type i =0; i<n ;++i)
102 _data.push_back( x[ i ] );
103 }
104
105 using Base::operator=;
106
109 {
110 _data = other._data;
111 return *this;
112 }
113
116 {
117 _data = std::move(other._data);
118 return *this;
119 }
120
121 //==== forward some methods of std::vector
126 size_type capacity() const
127 {
128 return _data.capacity();
129 }
130 void resize (size_type n, value_type c = value_type() )
131 {
132 _data.resize(n,c);
133 }
134 void reserve (size_type n)
135 {
136 _data.reserve(n);
137 }
138
139 //==== make this thing a vector
140 size_type vec_size() const { return _data.size(); }
141 K & vec_access(size_type i) { return _data[i]; }
142 const K & vec_access(size_type i) const { return _data[i]; }
143 };
144
156 template< class K, class Allocator >
157 inline std::istream &operator>> ( std::istream &in,
159 {
161 for( typename DynamicVector< K, Allocator >::size_type i = 0; i < w.size(); ++i )
162 in >> w[ i ];
163 if(in)
164 v = std::move(w);
165 return in;
166 }
167
170} // end namespace
171
172#endif
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:234
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:256
Iterator begin()
begin iterator
Definition: densevector.hh:307
size_type size() const
size method
Definition: densevector.hh:296
Iterator end()
end iterator
Definition: densevector.hh:313
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:265
Construct a vector with a dynamic size.
Definition: dynvector.hh:55
DynamicVector(const DynamicVector &x)
Constructor making vector with identical coordinates.
Definition: dynvector.hh:80
DynamicVector(const allocator_type &a=allocator_type())
Constructor making uninitialized vector.
Definition: dynvector.hh:66
DynamicVector(DynamicVector &&x)
Move constructor.
Definition: dynvector.hh:85
DynamicVector & operator=(DynamicVector &&other)
Move assignment operator.
Definition: dynvector.hh:115
DynamicVector & operator=(const DynamicVector &other)
Copy assignment operator.
Definition: dynvector.hh:108
size_type capacity() const
Number of elements for which memory has been allocated.
Definition: dynvector.hh:126
DynamicVector(size_type n, value_type c, const allocator_type &a=allocator_type())
Constructor making vector with identical coordinates.
Definition: dynvector.hh:75
DynamicVector(const DenseVector< X > &x, const allocator_type &a=allocator_type())
Copy constructor from another DenseVector.
Definition: dynvector.hh:96
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, tuple< T1 > &t)
Read a tuple.
Definition: tuples.hh:203
Dune namespace.
Definition: alignment.hh:10
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)