/usr/include/dune/common/fassign.hh is in libdune-common-dev 2.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set ts=8 sw=4 et sts=4:
#ifndef DUNE_ASSIGN_HH
#define DUNE_ASSIGN_HH
#include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh>
namespace Dune {
/**
* @file
* @brief Classes for implementing an assignment to FieldVector from a comma-separated list
*/
/** @addtogroup Common
*
* @{
*/
/**
* Emtpy namespace make this class and the object local to one object file
*/
namespace {
/**
* @brief Initializer class for
*
* overload operator <<= for FieldVector assignment from Dune::Zero
*/
struct Zero {
explicit Zero (int) {};
/** \brief Conversion operator to double */
operator double () { return 0.0; }
/** \brief Conversion operator to int */
operator int () { return 0; }
} zero(0);
/**
* @brief Marker class for next row
*
* overload operator <<= for FieldMatrix assignment
*/
struct NextRow {
explicit NextRow (int) {};
} nextRow(0);
} // end empty namespace
/**
* @brief fvector assignment operator
*
* overload operator <<= for fvector assignment from Dune::Zero
*
* after including fassing.hh you can easily assign data to a FieldVector
* using
*
* @code
* FieldVector<double, 4> x; x <<= 1.0, 4.0, 10.0, 11.0;
* @endcode
*
* The operator checks that the whole vector is initalized.
* In case you know that all following entries will be zero padded, you can use
*
* @code
* FieldVector<double, 40> x; x <<= 1.0, 4.0, 10.0, 11.0, zero;
* @endcode
*
*/
template <class T, int s>
class fvector_assigner
{
private:
FieldVector<T,s> & v;
int c;
bool temporary;
fvector_assigner();
public:
/*! @brief Copy Constructor */
fvector_assigner(fvector_assigner & a) : v(a.v), c(a.c), temporary(false)
{
}
/*! @brief Constructor from vector and temporary flag
\param _v vector which should be initialized
\param t bool indicating, that this is a temporary object (see ~fvector_assigner)
*/
fvector_assigner(FieldVector<T,s> & _v, bool t) : v(_v), c(0), temporary(t)
{
};
/*! @brief Destructor
checks for complete initialization of the vector.
The check is skipped, if this object is marked temporary.
*/
~fvector_assigner()
{
if (!temporary && c!=s)
DUNE_THROW(MathError, "Trying to assign " << c <<
" entries to a FieldVector of size " << s);
}
/*! @brief append data to this vector */
fvector_assigner & append (const T & t)
{
v[c++] = t;
return *this;
}
/*! @brief append zeros to this vector
*/
fvector_assigner & append (Zero z)
{
while (c!=s) v[c++] = 0;
return *this;
}
/*! @brief append data to this vector
the overloaded comma operator is used to assign a comma seperated list
of values to the vector
*/
fvector_assigner & operator , (const T & t)
{
return append(t);
}
/*! @brief append zeros to this vector
the overloaded comma operator is used to stop the assign of values
to the vector, all remaining entries are assigned 0.
*/
fvector_assigner & operator , (Zero z)
{
return append(z);
}
};
/**
* @brief fvector assignment operator
*
* overload operator <<= for fvector assignment
* from comma seperated list of values
*/
template <class T, class K, int s>
fvector_assigner<T,s> operator <<= (FieldVector<T,s> & v, const K & t)
{
return fvector_assigner<T,s>(v,true).append(t);
}
/**
* @brief fvector assignment operator
*
* overload operator <<= for fvector assignment from Dune::Zero
*/
template <class T, int s>
fvector_assigner<T,s> operator <<= (FieldVector<T,s> & v, Zero z)
{
return fvector_assigner<T,s>(v,true).append(z);
}
/**
* @brief fmatrix assignment operator
*
* overload operator <<= for fmatrix assignment from Dune::Zero
*
* after including fassing.hh you can easily assign data to a FieldMatrix
* using
*
* @code
* FieldMatrix<double, 2,2> x; x <<= 1.0, 4.0, nextRow, 10.0, 11.0;
* @endcode
*
* The operator checks that the whole matrix is initalized.
* In case you know that all following entries of a row will be zero padded, you can use
*
* @code
* FieldMatrix<double, 4, 4> x; x <<= 1.0, zero, nextRow, 10.0, 11.0;
* @endcode
*
*/
template <class T, int n, int m>
class fmatrix_assigner
{
private:
FieldMatrix<T,n,m> & A;
int c;
int r;
bool temporary;
bool thrown;
void end_row()
{
if (!temporary && c!=m && !thrown){
thrown=true;
DUNE_THROW(MathError, "Trying to assign " << c <<
" entries to a FieldMatrix row of size " << m);
}
c=0;
}
public:
/*! @brief Copy Constructor */
fmatrix_assigner(fmatrix_assigner & a) : A(a.A), c(a.c), r(a.r), temporary(false), thrown(a.thrown)
{
}
/*! @brief Constructor from matrix and temporary flag
\param _A matrix which should be initialized
\param t bool indicating, that this is a temporary object (see ~fmatrix_assigner)
*/
fmatrix_assigner(FieldMatrix<T,n,m> & _A, bool t) : A(_A), c(0), r(0), temporary(t),
thrown(false)
{
};
/*! @brief Destructor
checks for complete initialization of the matrix.
The check is skipped, if this object is marked temporary.
*/
~fmatrix_assigner()
{
end_row();
if (!temporary && r!=n-1 && !thrown){
thrown=true;
DUNE_THROW(MathError, "Trying to assign " << r <<
" rows to a FieldMatrix of size " << n << " x " << m);
}
}
/*! @brief append data to this matrix */
fmatrix_assigner & append (const T & t)
{
// Check whether we have passed the last row
if(r>=m){
thrown=true;
DUNE_THROW(MathError, "Trying to assign more than " << m <<
" rows to a FieldMatrix of size " << n << " x " << m);
}
A[r][c++] = t;
return *this;
}
/*! @brief append zeros to this matrix
*/
fmatrix_assigner & append (Zero z)
{
while (c!=m) A[r][c++] = 0;
return *this;
}
/*! @brief move to next row of the matrix
*/
fmatrix_assigner & append (NextRow nr)
{
end_row();
r++;
return *this;
}
/*! @brief append data to this matrix
the overloaded comma operator is used to assign a comma seperated list
of values to the matrix
*/
fmatrix_assigner & operator , (const T & t)
{
return append(t);
}
/*! @brief append zeros to this matrix
the overloaded comma operator is used to stop the assign of values
to the matrix, all remaining entries are assigned 0.
*/
fmatrix_assigner & operator , (Zero z)
{
return append(z);
}
/*! @brief append zeros to this matrix
the overloaded comma operator is used to stop the assign of values
to the current row, it will be checked whether all entries have been
assigned values.
*/
fmatrix_assigner & operator , (NextRow nr)
{
return append(nr);
}
};
/**
* @brief FieldMatrix assignment operator
*
* overload operator <<= for FieldMatrix assignment
* from comma seperated list of values
*/
template <class T, class K, int n, int m>
fmatrix_assigner<T,n,m> operator <<= (FieldMatrix<T,n,m> & v, const K & t)
{
return fmatrix_assigner<T,n,m>(v,true).append(t);
}
/**
* @brief FieldMatrix assignment operator
*
* overload operator <<= for FieldMatrix row assignment from Dune::Zero
*/
template <class T, int n, int m>
fmatrix_assigner<T,n,m> operator <<= (FieldMatrix<T,n,m> & v, Zero z)
{
return fmatrix_assigner<T,n,m>(v,true).append(z);
}
} // end namespace Dune
#endif // DUNE_ASSIGN_HH
|