16 #ifndef dealii_any_data_h 17 #define dealii_any_data_h 19 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/subscriptor.h> 24 #include <boost/any.hpp> 30 DEAL_II_NAMESPACE_OPEN
48 template <
typename type>
66 template <
typename type>
78 template <
typename type>
93 template <
typename type>
106 template <
typename type>
114 template <
typename type>
125 template <
typename type>
132 template <
typename type>
134 entry(
const unsigned int i);
137 template <
typename type>
139 entry(
const unsigned int i)
const;
142 template <
typename type>
144 read(
const unsigned int i)
const;
147 template <
typename type>
149 read_ptr(
const unsigned int i)
const;
152 template <
typename type>
157 template <
typename type>
159 try_read(
const unsigned int i)
const;
163 name(
const unsigned int i)
const;
172 find(
const std::string &
name)
const;
184 template <
typename type>
186 is_type(
const unsigned int i)
const;
189 template <
class StreamType>
191 list(StreamType &os)
const;
196 <<
"No entry with the name " << arg1 <<
" exists.");
202 <<
"The requested type " << arg1 <<
" and the stored type " 203 << arg2 <<
" must coincide.");
212 <<
"Name at position " << arg1 <<
" is not equal to " << arg2
230 template <
typename type>
235 type *p = boost::any_cast<type>(&
data[i]);
242 template <
typename type>
247 const type *p = boost::any_cast<type>(&
data[i]);
249 p = boost::any_cast<
const type>(&
data[i]);
256 template <
typename type>
261 const type *p = boost::any_cast<type>(&
data[i]);
263 p = boost::any_cast<
const type>(&
data[i]);
270 template <
typename type>
275 const type *
const *p = boost::any_cast<type *>(&
data[i]);
277 p = boost::any_cast<
const type *>(&
data[i]);
284 template <
typename type>
289 const type *
const *p = boost::any_cast<type *>(&
data[i]);
291 p = boost::any_cast<
const type *>(&
data[i]);
298 template <
typename type>
303 const type *p = boost::any_cast<type>(&
data[i]);
305 p = boost::any_cast<
const type>(&
data[i]);
310 inline const std::string &
321 std::vector<std::string>::const_iterator it =
324 if (it ==
names.end())
327 return it -
names.begin();
341 template <
typename type>
345 return data[i].type() ==
typeid(type);
349 template <
typename type>
353 const unsigned int i =
find(n);
354 type * p = boost::any_cast<type>(&
data[i]);
360 template <
typename type>
364 const unsigned int i =
find(n);
365 const type * p = boost::any_cast<type>(&
data[i]);
372 template <
typename type>
376 const unsigned int i =
find(n);
377 const type * p = boost::any_cast<type>(&
data[i]);
383 template <
typename type>
387 const unsigned int i =
find(n);
388 const type *
const *p = boost::any_cast<type *>(&
data[i]);
390 p = boost::any_cast<
const type *>(&
data[i]);
397 template <
typename type>
405 const type *
const *p = boost::any_cast<type *>(&
data[i]);
407 p = boost::any_cast<
const type *>(&
data[i]);
412 template <
typename type>
417 std::vector<std::string>::const_iterator it =
420 if (it ==
names.end())
424 unsigned int i = it -
names.begin();
425 const type * p = boost::any_cast<type>(&
data[i]);
430 template <
typename type>
443 for (
unsigned int i = 0; i < other.
size(); ++i)
451 template <
class StreamType>
455 for (
unsigned int i = 0; i <
names.size(); ++i)
457 os << i <<
'\t' <<
names[i] <<
'\t' <<
data[i].type().name() << std::endl;
466 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)
static ::ExceptionBase & ExcTypeMismatch(std::string arg1, std::string arg2)
The requested type and the stored type are different.
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.
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.