/usr/include/deal.II/base/table_indices.h is in libdeal.ii-dev 8.4.2-2+b1.
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 | // ---------------------------------------------------------------------
//
// Copyright (C) 2005 - 2016 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#ifndef dealii__table_indices_h
#define dealii__table_indices_h
#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/std_cxx11/iterator.h>
#include <algorithm>
#include <ostream>
DEAL_II_NAMESPACE_OPEN
/**
* A class representing a fixed size array of indices.
*
* It is used in tensorial objects like the TableBase and SymmetricTensor
* classes to represent a nested choice of indices.
*
* @ingroup data
* @author Wolfgang Bangerth, Matthias Maier, 2002, 2015
*/
template <int N>
class TableIndices
{
public:
/**
* Default constructor. It sets all indices to zero.
*/
TableIndices();
/**
* Convenience constructor that takes up to 9 arguments. It can be used to
* populate a TableIndices object upon creation, either completely, or
* partially.
*
* Index entries that are not set by these arguments (either because they
* are omitted, or because $N > 9$) are set to
* numbers::invalid_unsigned_int.
*
* Note that only the first <tt>N</tt> arguments are actually used.
*
* @tparam N The number of indices stored in each object.
*/
TableIndices (const unsigned int index0,
const unsigned int index1 = numbers::invalid_unsigned_int,
const unsigned int index2 = numbers::invalid_unsigned_int,
const unsigned int index3 = numbers::invalid_unsigned_int,
const unsigned int index4 = numbers::invalid_unsigned_int,
const unsigned int index5 = numbers::invalid_unsigned_int,
const unsigned int index6 = numbers::invalid_unsigned_int,
const unsigned int index7 = numbers::invalid_unsigned_int,
const unsigned int index8 = numbers::invalid_unsigned_int);
/**
* Read-only access the value of the <tt>i</tt>th index.
*/
unsigned int operator[] (const unsigned int i) const;
/**
* Write access the value of the <tt>i</tt>th index.
*/
unsigned int &operator[] (const unsigned int i);
/**
* Compare two index fields for equality.
*/
bool operator == (const TableIndices<N> &other) const;
/**
* Compare two index fields for inequality.
*/
bool operator != (const TableIndices<N> &other) const;
/**
* Sort the indices in ascending order. While this operation is not very
* useful for Table objects, it is used for the SymmetricTensor class.
*/
void sort ();
/**
* Write or read the data of this object to or from a stream for the purpose
* of serialization.
*/
template <class Archive>
void serialize (Archive &ar, const unsigned int version);
protected:
/**
* Store the indices in an array.
*/
unsigned int indices[N];
};
/* --------------------- Template and inline functions ---------------- */
template <int N>
TableIndices<N>::TableIndices()
{
Assert (N > 0, ExcMessage("Cannot create a TableIndices object of size 0"));
for (unsigned int i=0; i<N; ++i)
indices[i] = 0;
}
template <int N>
TableIndices<N>::TableIndices(const unsigned int index0,
const unsigned int index1,
const unsigned int index2,
const unsigned int index3,
const unsigned int index4,
const unsigned int index5,
const unsigned int index6,
const unsigned int index7,
const unsigned int index8)
{
Assert (N > 0, ExcMessage("Cannot create a TableIndices object of size 0"));
switch (N)
{
case 1: // fallthrough
Assert (index1 == numbers::invalid_unsigned_int, ExcMessage("more than N index values provided"));
case 2: // fallthrough
Assert (index2 == numbers::invalid_unsigned_int, ExcMessage("more than N index values provided"));
case 3: // fallthrough
Assert (index3 == numbers::invalid_unsigned_int, ExcMessage("more than N index values provided"));
case 4: // fallthrough
Assert (index4 == numbers::invalid_unsigned_int, ExcMessage("more than N index values provided"));
case 5: // fallthrough
Assert (index5 == numbers::invalid_unsigned_int, ExcMessage("more than N index values provided"));
case 6: // fallthrough
Assert (index6 == numbers::invalid_unsigned_int, ExcMessage("more than N index values provided"));
case 7: // fallthrough
Assert (index7 == numbers::invalid_unsigned_int, ExcMessage("more than N index values provided"));
case 8: // fallthrough
Assert (index8 == numbers::invalid_unsigned_int, ExcMessage("more than N index values provided"));
default:
;
}
// Always access "indices" with indices modulo N to avoid bogus compiler
// warnings (although such access is always in dead code...
switch (N)
{
default:
// For TableIndices of size 10 or larger als default initialize the
// remaining indices to numbers::invalid_unsigned_int:
for (unsigned int i=0; i<N; ++i)
indices[i] = numbers::invalid_unsigned_int;
case 9: // fallthrough
indices[8 % N] = index8;
case 8: // fallthrough
indices[7 % N] = index7;
case 7: // fallthrough
indices[6 % N] = index6;
case 6: // fallthrough
indices[5 % N] = index5;
case 5: // fallthrough
indices[4 % N] = index4;
case 4: // fallthrough
indices[3 % N] = index3;
case 3: // fallthrough
indices[2 % N] = index2;
case 2: // fallthrough
indices[1 % N] = index1;
case 1: // fallthrough
indices[0 % N] = index0;
}
}
template <int N>
inline
unsigned int
TableIndices<N>::operator [] (const unsigned int i) const
{
Assert (i < N, ExcIndexRange (i, 0, N));
return indices[i];
}
template <int N>
inline
unsigned int &
TableIndices<N>::operator [] (const unsigned int i)
{
Assert (i < N, ExcIndexRange (i, 0, N));
return indices[i];
}
template <int N>
inline
bool
TableIndices<N>::operator == (const TableIndices<N> &other) const
{
for (unsigned int i=0; i<N; ++i)
if (indices[i] != other.indices[i])
return false;
return true;
}
template <int N>
inline
bool
TableIndices<N>::operator != (const TableIndices<N> &other) const
{
return !(*this == other);
}
template <int N>
inline
void
TableIndices<N>::sort ()
{
std::sort(std_cxx11::begin(indices), std_cxx11::end(indices));
}
template <int N>
template <class Archive>
inline
void
TableIndices<N>::serialize (Archive &ar, const unsigned int)
{
ar &indices;
}
/**
* Output operator for TableIndices objects; reports them in a list like this:
* <code>[i1,i2,...]</code>.
*
* @relates TableIndices
*/
template <int N>
std::ostream &
operator << (std::ostream &out,
const TableIndices<N> &indices)
{
out << '[';
for (unsigned int i=0; i<N; ++i)
{
out << indices[i];
if (i+1 != N)
out << ',';
}
out << ']';
return out;
}
DEAL_II_NAMESPACE_CLOSE
#endif
|