/usr/include/deal.II/base/named_data.h is in libdeal.ii-dev 8.1.0-4.
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 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | // ---------------------------------------------------------------------
// $Id: named_data.h 30036 2013-07-18 16:55:32Z maier $
//
// Copyright (C) 2000 - 2013 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 __deal2__named_data_h
#define __deal2__named_data_h
#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/subscriptor.h>
#include <vector>
#include <algorithm>
DEAL_II_NAMESPACE_OPEN
/**
* This class is a collection of DATA objects. Each of the pointers
* has a name associated, enabling identification by this name rather
* than the index in the vector only.
*
* Note that it is the actual data stored in this object. Therefore,
* for storing vectors and other large objects, it should be
* considered to use SmartPointer or boost::shared_ptr for DATA.
*
* Objects of this kind have a smart way of treating constness: if a
* const data object is added or a const NamedData is supplied with
* merge(), the object will henceforth consider itself as const
* (#is_constant will be true). Thus, any subsequent modification will
* be illegal and ExcConstantObject will be raised in debug mode.
*
* @author Guido Kanschat, 2007, 2008, 2009
*/
template <typename DATA>
class NamedData : public Subscriptor
{
public:
/** Standard constructor creating
* an empty object.
*/
NamedData();
/**
* Assignment operator, copying
* conversible data from another
* object.
*/
template <typename DATA2>
NamedData<DATA> &operator = (const NamedData<DATA2> &other);
/**
* \name Adding members
*/
//@{
/**
* Add a new data item to the end
* of the collection.
*/
void add(DATA &v, const std::string &name);
/**
* Add a new constant data item
* to the end of the collection
* and make the collection
* constant.
*/
void add(const DATA &v, const std::string &name);
/**
* Merge the data of another
* NamedData to the end of this
* object.
*
* If the other object had
* #is_constant set, so will have
* this object after merge.
*/
template <typename DATA2>
void merge(NamedData<DATA2> &);
/**
* Merge the data of another
* NamedData to the end of this
* object.
*
* After this operation, all
* data in this object will be
* treated as const.
*/
template <typename DATA2>
void merge(const NamedData<DATA2> &);
//@}
/**
* \name Accessing and querying
* contents
*/
//@{
/// Number of stored data objects.
unsigned int size() const;
/**
* @brief Access to stored data
* object by index.
*
* @note This function throws an
* exception, if is_const()
* returns <tt>true</tt>. In such
* a case, either cast the
* NamedData object to a const
* reference, or use the function
* read() instead of this operator.
*/
DATA &operator() (unsigned int i);
/// Read-only access to stored data object by index.
const DATA &operator() (unsigned int i) const;
/// Read only access for a non-const object.
const DATA &read (unsigned int i) const;
/// Name of object at index.
const std::string &name(unsigned int i) const;
/// Find index of a named object
unsigned int find(const std::string &name) const;
/// Returns true if this object contains constant data
bool is_const () const;
/// List names of stored objects
template <class OUT>
void print(OUT &o) const;
//@}
/**
* Exception indicating that a
* function expected a vector
* to have a certain name, but
* NamedData had a different
* name in that position.
*/
DeclException2(ExcNameMismatch, int, std::string,
<< "Name at position " << arg1 << " is not equal to " << arg2);
/**
* Exception indicating that read
* access to stored data was
* attempted although the
* NamedData object contains
* const data and #is_constant
* was true.
*/
DeclException0(ExcConstantObject);
private:
/// True if the object is to be treated constant
bool is_constant;
/// The actual data stored
std::vector<DATA> data;
/// Names for the data
std::vector<std::string> names;
};
/**
* Select data from NamedData corresponding to the attached name.
*
* Given a list of names to search for (provided by add()), objects of
* this class provide an index list of the selected data.
*
* @author Guido Kanschat, 2009
*/
class NamedSelection
{
public:
/**
* Add a new name to be searched
* for in NamedData.
*
* @note Names will be added to
* the end of the current list.
*/
void add (const std::string &name);
/**
* Create the index vector
* pointing into the NamedData
* object.
*/
template <typename DATA>
void initialize(const NamedData<DATA> &data);
/**
* The number of names in this
* object. This function may be
* used whether initialize() was
* called before or not.
*/
unsigned int size() const;
/**
* Return the corresponding index
* in the NamedData object
* supplied to the last
* initialize(). It is an error
* if initialize() has not been
* called before.
*
* Indices are in the same order
* as the calls to add().
*/
unsigned int operator() (unsigned int i) const;
private:
/**
* The selected names.
*/
std::vector<std::string> names;
/**
* The index map generated by
* initialize() and accessed by
* operator().
*/
std::vector<unsigned int> indices;
};
//----------------------------------------------------------------------//
template<typename DATA>
inline
NamedData<DATA>::NamedData()
:
is_constant(false)
{}
template<typename DATA>
inline
void
NamedData<DATA>::add(DATA &v, const std::string &n)
{
Assert(!is_constant, ExcConstantObject());
names.push_back(n);
data.push_back(v);
}
template<typename DATA>
inline
void
NamedData<DATA>::add(const DATA &v, const std::string &n)
{
Assert(!is_constant, ExcConstantObject());
DATA &aux = const_cast<DATA &>(v);
data.push_back(aux);
names.push_back(n);
is_constant = true;
}
template<typename DATA>
template<typename DATA2>
inline
void
NamedData<DATA>::merge(NamedData<DATA2> &other)
{
Assert(!is_constant, ExcConstantObject());
for (unsigned int i=0; i<other.size(); ++i)
{
names.push_back(other.name(i));
data.push_back(other.read(i));
}
is_constant = other.is_const();
}
template<typename DATA>
template<typename DATA2>
inline
void
NamedData<DATA>::merge(const NamedData<DATA2> &other)
{
Assert(!is_constant, ExcConstantObject());
for (unsigned int i=0; i<other.size(); ++i)
{
names.push_back(other.name(i));
data.push_back(other(i));
}
is_constant = true;
}
template<typename DATA>
template<typename DATA2>
inline
NamedData<DATA> &
NamedData<DATA>::operator= (const NamedData<DATA2> &other)
{
is_constant = false;
merge(other);
is_constant = other.is_const();
return *this;
}
template<typename DATA>
inline
unsigned int
NamedData<DATA>::size() const
{
return data.size();
}
template<typename DATA>
inline
bool
NamedData<DATA>::is_const() const
{
return is_constant;
}
template<typename DATA>
inline
DATA &
NamedData<DATA>::operator() (unsigned int i)
{
Assert(!is_constant, ExcConstantObject());
AssertIndexRange(i, size());
return data[i];
}
template<typename DATA>
inline
const DATA &
NamedData<DATA>::operator() (unsigned int i) const
{
AssertIndexRange(i, size());
return data[i];
}
template<typename DATA>
inline
const DATA &
NamedData<DATA>::read (unsigned int i) const
{
AssertIndexRange(i, size());
return data[i];
}
template<typename DATA>
inline
const std::string &
NamedData<DATA>::name(unsigned int i) const
{
AssertIndexRange(i, size());
return names[i];
}
template<typename DATA>
inline
unsigned int
NamedData<DATA>::find (const std::string &name) const
{
const std::vector<std::string>::const_iterator
i = std::find(names.begin(), names.end(), name);
if (i == names.end())
return deal_II_numbers::invalid_unsigned_int;
return i - names.begin();
}
template<typename DATA>
template<class OUT>
inline
void
NamedData<DATA>::print(OUT &o) const
{
o << "NamedData:";
for (unsigned int i=0; i<size(); ++i)
o << ' ' << '\"' << names[i] << '\"';
o << std::endl;
}
inline
void
NamedSelection::add(const std::string &s)
{
names.push_back(s);
}
template <typename DATA>
inline void
NamedSelection::initialize(const NamedData<DATA> &data)
{
indices.resize(names.size());
for (unsigned int i=0; i<names.size(); ++i)
indices[i] = data.find(names[i]);
}
inline
unsigned int
NamedSelection::size() const
{
return names.size();
}
inline
unsigned int
NamedSelection::operator() (unsigned int i) const
{
Assert (indices.size() == names.size(), ExcNotInitialized());
AssertIndexRange(i, size());
return indices[i];
}
DEAL_II_NAMESPACE_CLOSE
#endif
|