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>
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>
106 template <
typename type>
116 template <
typename type>
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;
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 <<
".");
206 template <
typename type>
212 type *p = boost::any_cast<type>(&
data[i]);
219 template <
typename type>
225 const type *p = boost::any_cast<type>(&
data[i]);
227 p = boost::any_cast<
const type>(&
data[i]);
234 template <
typename type>
240 const type *p = boost::any_cast<type>(&
data[i]);
242 p = boost::any_cast<
const type>(&
data[i]);
249 template <
typename type>
255 const type *
const *p = boost::any_cast<type *>(&
data[i]);
257 p = boost::any_cast<
const type *>(&
data[i]);
264 template <
typename type>
270 const type *
const *p = boost::any_cast<type *>(&
data[i]);
272 p = boost::any_cast<
const type *>(&
data[i]);
279 template <
typename type>
285 const type *p = boost::any_cast<type>(&
data[i]);
287 p = boost::any_cast<
const type>(&
data[i]);
305 std::vector<std::string>::const_iterator it =
308 if (it ==
names.end())
311 return it -
names.begin();
326 template <
typename type>
331 return data[i].type() ==
typeid(type);
335 template <
typename type>
340 const unsigned int i =
find(n);
341 type *p = boost::any_cast<type>(&
data[i]);
348 template <
typename type>
353 const unsigned int i =
find(n);
354 const type *p = boost::any_cast<type>(&
data[i]);
361 template <
typename type>
366 const unsigned int i =
find(n);
367 const type *p = boost::any_cast<type>(&
data[i]);
374 template <
typename type>
379 const unsigned int i =
find(n);
380 const type *
const *p = boost::any_cast<type *>(&
data[i]);
382 p = boost::any_cast<
const type *>(&
data[i]);
389 template <
typename type>
398 const type *
const *p = boost::any_cast<type *>(&
data[i]);
400 p = boost::any_cast<
const type *>(&
data[i]);
405 template <
typename type>
411 std::vector<std::string>::const_iterator it =
414 if (it ==
names.end())
418 unsigned int i=it-
names.begin();
419 const type *p = boost::any_cast<type>(&
data[i]);
424 template <
typename type>
439 for (
unsigned int i=0; i<other.
size(); ++i)
447 template <
class StreamType>
451 for (
unsigned int i=0; i<
names.size(); ++i)
455 <<
'\t' <<
data[i].type().name()
465 DEAL_II_NAMESPACE_CLOSE
bool is_type(const unsigned int i) const
Find out if object is of a certain type.
AnyData()=default
Default constructor for empty object.
static ::ExceptionBase & ExcNameNotFound(std::string arg1)
An entry with this name does not exist in the AnyData object.
static const unsigned int invalid_unsigned_int
type entry(const std::string &name)
Access to stored data object by name.
#define DeclException2(Exception2, type1, type2, outsequence)
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.
#define AssertIndexRange(index, range)
#define DeclException1(Exception1, type1, outsequence)
#define Assert(cond, exc)
const type * try_read_ptr(const std::string &name) const
static ::ExceptionBase & ExcTypeMismatch(char *arg1, char *arg2)
The requested type and the stored type are different.
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.
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.
static ::ExceptionBase & ExcNameMismatch(int arg1, std::string arg2)
const std::string & name(const unsigned int i) const
Name of object at index.