Dune Core Modules (2.4.1)

fassign.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_ASSIGN_HH
4#define DUNE_ASSIGN_HH
5
6#warning The header <dune/common/fassign.hh> is deprecated and will be removed after the\
7 release of dune-common-2.4. Please use C++11 initializer lists instead.
8
11#include <dune/common/unused.hh>
12
13namespace Dune {
14
27 namespace {
28
34 struct Zero {
35 explicit Zero (int) {};
37 operator double () { return 0.0; }
39 operator int () { return 0; }
40 } zero(0);
41
47 struct NextRow {
48 explicit NextRow (int) {};
49 } nextRow(0);
50 } // end empty namespace
51
72 template <class T, int s>
74 {
75 private:
77 int c;
78 bool temporary;
80 public:
82 fvector_assigner(fvector_assigner & a) : v(a.v), c(a.c), temporary(false)
83 {}
88 fvector_assigner(FieldVector<T,s> & _v, bool t) : v(_v), c(0), temporary(t)
89 {};
95 {
96 if (!temporary && c!=s)
97 DUNE_THROW(MathError, "Trying to assign " << c <<
98 " entries to a FieldVector of size " << s);
99 }
101 fvector_assigner & append (const T & t)
102 {
103 v[c++] = t;
104 return *this;
105 }
109 {
111 while (c!=s) v[c++] = 0;
112 return *this;
113 }
119 {
120 return append(t);
121 }
127 {
128 return append(z);
129 }
130 };
131
138 template <class T, class K, int s>
139 fvector_assigner<T,s> operator <<= (FieldVector<T,s> & v, const K & t)
140 {
141 return fvector_assigner<T,s>(v,true).append(t);
142 }
143
149 template <class T, int s>
150 fvector_assigner<T,s> operator <<= (FieldVector<T,s> & v, Zero z)
151 {
152 return fvector_assigner<T,s>(v,true).append(z);
153 }
154
175 template <class T, int n, int m>
177 {
178 private:
180 int c;
181 int r;
182 bool temporary;
183 bool thrown;
184
185 void end_row()
186 {
187 if (!temporary && c!=m && !thrown) {
188 thrown=true;
189 DUNE_THROW(MathError, "Trying to assign " << c <<
190 " entries to a FieldMatrix row of size " << m);
191 }
192 c=0;
193 }
194 public:
196 fmatrix_assigner(fmatrix_assigner & a) : A(a.A), c(a.c), r(a.r), temporary(false), thrown(a.thrown)
197 {}
202 fmatrix_assigner(FieldMatrix<T,n,m> & _A, bool t) : A(_A), c(0), r(0), temporary(t),
203 thrown(false)
204 {};
210 {
211 end_row();
212 if (!temporary && r!=n-1 && !thrown) {
213 thrown=true;
214 DUNE_THROW(MathError, "Trying to assign " << r <<
215 " rows to a FieldMatrix of size " << n << " x " << m);
216 }
217 }
219 fmatrix_assigner & append (const T & t)
220 {
221 // Check whether we have passed the last row
222 if(r>=m) {
223 thrown=true;
224 DUNE_THROW(MathError, "Trying to assign more than " << m <<
225 " rows to a FieldMatrix of size " << n << " x " << m);
226 }
227 A[r][c++] = t;
228 return *this;
229 }
233 {
235 while (c!=m) A[r][c++] = 0;
236 return *this;
237 }
241 {
243 end_row();
244 r++;
245 return *this;
246 }
252 {
253 return append(t);
254 }
260 {
261 return append(z);
262 }
269 {
270 return append(nr);
271 }
272 };
273
280 template <class T, class K, int n, int m>
281 fmatrix_assigner<T,n,m> operator <<= (FieldMatrix<T,n,m> & v, const K & t)
282 {
283 return fmatrix_assigner<T,n,m>(v,true).append(t);
284 }
285
291 template <class T, int n, int m>
292 fmatrix_assigner<T,n,m> operator <<= (FieldMatrix<T,n,m> & v, Zero z)
293 {
294 return fmatrix_assigner<T,n,m>(v,true).append(z);
295 }
296
297} // end namespace Dune
298
299#endif // DUNE_ASSIGN_HH
Default exception class for mathematical errors.
Definition: exceptions.hh:266
fmatrix assignment operator
Definition: fassign.hh:177
fvector assignment operator
Definition: fassign.hh:74
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
fvector_assigner(fvector_assigner &a)
Copy Constructor.
Definition: fassign.hh:82
fmatrix_assigner & append(NextRow nr)
move to next row of the matrix
Definition: fassign.hh:240
fmatrix_assigner & append(Zero z)
append zeros to this matrix
Definition: fassign.hh:232
fmatrix_assigner & append(const T &t)
append data to this matrix
Definition: fassign.hh:219
fvector_assigner & append(Zero z)
append zeros to this vector
Definition: fassign.hh:108
~fmatrix_assigner()
Destructor checks for complete initialization of the matrix. The check is skipped,...
Definition: fassign.hh:209
fvector_assigner(FieldVector< T, s > &_v, bool t)
Constructor from vector and temporary flag.
Definition: fassign.hh:88
fmatrix_assigner(fmatrix_assigner &a)
Copy Constructor.
Definition: fassign.hh:196
~fvector_assigner()
Destructor checks for complete initialization of the vector. The check is skipped,...
Definition: fassign.hh:94
fmatrix_assigner & operator,(const T &t)
append data to this matrix the overloaded comma operator is used to assign a comma separated list of ...
Definition: fassign.hh:251
fvector_assigner & operator,(const T &t)
append data to this vector the overloaded comma operator is used to assign a comma separated list of ...
Definition: fassign.hh:118
fvector_assigner< T, s > operator<<=(FieldVector< T, s > &v, const K &t)
fvector assignment operator
Definition: fassign.hh:139
fmatrix_assigner(FieldMatrix< T, n, m > &_A, bool t)
Constructor from matrix and temporary flag.
Definition: fassign.hh:202
fvector_assigner & append(const T &t)
append data to this vector
Definition: fassign.hh:101
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
Dune namespace.
Definition: alignment.hh:10
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)