16 #ifndef dealii__any_data_h 17 #define dealii__any_data_h 19 #include <deal.II/base/config.h> 20 #include <deal.II/base/exceptions.h> 21 #include <deal.II/base/subscriptor.h> 23 #include <boost/any.hpp> 28 DEAL_II_NAMESPACE_OPEN
43 unsigned int size()
const;
46 template <
typename type>
62 template <
typename type>
63 type
entry (
const std::string &name);
73 template <
typename type>
74 const type
entry (
const std::string &name)
const;
87 template <
typename type>
88 const type
read (
const std::string &name)
const;
99 template <
typename type>
100 const type *
read_ptr (
const std::string &name)
const;
106 template <
typename type>
107 const type *
try_read_ptr (
const std::string &name)
const;
116 template <
typename type>
117 const type *
try_read (
const std::string &name)
const;
122 template <
typename type>
123 type
entry (
const unsigned int i);
126 template <
typename type>
127 const type
entry (
const unsigned int i)
const;
130 template <
typename type>
131 const type
read (
const unsigned int i)
const;
134 template <
typename type>
135 const type *
read_ptr (
const unsigned int i)
const;
138 template <
typename type>
142 template <
typename type>
143 const type *
try_read (
const unsigned int i)
const;
146 const std::string &
name(
const unsigned int i)
const;
154 unsigned int find(
const std::string &name)
const;
162 unsigned int try_find(
const std::string &name)
const;
165 template <
typename type>
166 bool is_type(
const unsigned int i)
const;
169 template <
class StreamType>
170 void list (StreamType &os)
const;
174 <<
"No entry with the name " << arg1 <<
" exists.");
179 <<
"The requested type " << arg1
180 <<
" and the stored type " << arg2
181 <<
" must coincide");
188 <<
"Name at position " << arg1 <<
" is not equal to " << arg2);
211 template <
typename type>
217 type *p = boost::any_cast<type>(&
data[i]);
219 ExcTypeMismatch(
typeid(type).
name(),
data[i].type().
name()));
224 template <
typename type>
230 const type *p = boost::any_cast<type>(&
data[i]);
232 p = boost::any_cast<
const type>(&
data[i]);
234 ExcTypeMismatch(
typeid(type).
name(),
data[i].type().
name()));
239 template <
typename type>
245 const type *p = boost::any_cast<type>(&
data[i]);
247 p = boost::any_cast<
const type>(&
data[i]);
249 ExcTypeMismatch(
typeid(type).
name(),
data[i].type().
name()));
254 template <
typename type>
260 const type *
const *p = boost::any_cast<type *>(&
data[i]);
262 p = boost::any_cast<
const type *>(&
data[i]);
264 ExcTypeMismatch(
typeid(type *).
name(),
data[i].type().
name()));
269 template <
typename type>
275 const type *
const *p = boost::any_cast<type *>(&
data[i]);
277 p = boost::any_cast<
const type *>(&
data[i]);
282 template <
typename type>
288 const type *p = boost::any_cast<type>(&
data[i]);
290 p = boost::any_cast<
const type>(&
data[i]);
308 std::vector<std::string>::const_iterator it =
311 if (it ==
names.end())
314 return it -
names.begin();
329 template <
typename type>
334 return data[i].type() ==
typeid(type);
338 template <
typename type>
343 const unsigned int i =
find(n);
344 type *p = boost::any_cast<type>(&
data[i]);
346 ExcTypeMismatch(
typeid(type).
name(),
data[i].type().
name()));
351 template <
typename type>
356 const unsigned int i =
find(n);
357 const type *p = boost::any_cast<type>(&
data[i]);
359 ExcTypeMismatch(
typeid(type).
name(),
data[i].type().
name()));
364 template <
typename type>
369 const unsigned int i =
find(n);
370 const type *p = boost::any_cast<type>(&
data[i]);
372 ExcTypeMismatch(
typeid(type).
name(),
data[i].type().
name()));
377 template <
typename type>
382 const unsigned int i =
find(n);
383 const type *
const *p = boost::any_cast<type *>(&
data[i]);
385 p = boost::any_cast<
const type *>(&
data[i]);
387 ExcTypeMismatch(
typeid(type).
name(),
data[i].type().
name()));
392 template <
typename type>
401 const type *
const *p = boost::any_cast<type *>(&
data[i]);
403 p = boost::any_cast<
const type *>(&
data[i]);
408 template <
typename type>
414 std::vector<std::string>::const_iterator it =
417 if (it ==
names.end())
421 unsigned int i=it-
names.begin();
422 const type *p = boost::any_cast<type>(&
data[i]);
427 template <
typename type>
442 for (
unsigned int i=0; i<other.
size(); ++i)
450 template <
class StreamType>
454 for (
unsigned int i=0; i<
names.size(); ++i)
458 <<
'\t' <<
data[i].type().name()
468 DEAL_II_NAMESPACE_CLOSE
bool is_type(const unsigned int i) const
Find out if object is of a certain type.
static const unsigned int invalid_unsigned_int
type entry(const std::string &name)
Access to stored data object by name.
void merge(const AnyData &other)
Merge the data of another AnyData to the end of this object.
#define AssertDimension(dim1, dim2)
const type read(const std::string &name) const
Dedicated read only access by name.
AnyData()
Default constructor for empty object.
#define AssertIndexRange(index, range)
#define Assert(cond, exc)
const type * try_read_ptr(const std::string &name) const
std::vector< boost::any > data
The stored data.
const type * read_ptr(const std::string &name) const
Dedicated read only access by name for pointer data.
const type * try_read(const std::string &name) const
Dedicated read only access by name without exceptions.
unsigned int find(const std::string &name) const
Find index of a named object.
DeclException1(ExcNameNotFound, std::string,<< "No entry with the name "<< arg1<< " exists.")
An entry with this name does not exist in the AnyData object.
void add(type entry, const std::string &name)
Add a new data object.
unsigned int size() const
Number of stored data objects.
std::vector< std::string > names
The names of the stored data.
void list(StreamType &os) const
List the contents to a stream.
unsigned int try_find(const std::string &name) const
Try to find index of a named object.
DeclException2(ExcTypeMismatch, char *, char *,<< "The requested type "<< arg1<< " and the stored type "<< arg2<< " must coincide")
The requested type and the stored type are different.
const std::string & name(const unsigned int i) const
Name of object at index.