* for long enough, then change to a map.
*/
class AnyData :
- public Subscriptor
+ public Subscriptor
{
- public:
- /// Default constructor for empty object
- AnyData();
-
- /// Number of stored data objects.
- unsigned int size() const;
-
- /// Add a new data object
- template <typename type>
- void add(type entry, const std::string& name);
-
- /**
- * @brief Merge the data of another NamedData to the end of this object.
- */
- void merge(const AnyData& other);
-
- /**
- * @brief Access to stored data object by name.
- *
- * Find the object with given name, try to convert it to
- * <tt>type</tt> and return it. This function throws an exception
- * if either the name does not exist or if the conversion
- * fails. If such an exception is not desired, use try_read()
- * instead.
- */
- template <typename type>
- type entry (const std::string& name);
-
- /**
- * @brief Read-only access to stored data object by name.
- *
- * Find the object with given name, try to convert it to
- * <tt>type</tt> and return it. This function throws an exception
- * if either the name does not exist or if the conversion
- * fails. If such an exception is not desired, use try_read()
- * instead.
- */
- template <typename type>
- const type entry (const std::string& name) const;
-
- /**
- * @brief Dedicated read only access by name.
- *
- * For a constant object, this function equals entry(). For a
- * non-const object, it forces read only access to the data. In
- * particular, it throws an exception if the object is not found
- * or cannot be converted to type. If such an exception is not
- * desired, use try_read() instead.
- *
- * @warning Do not use this function for stored objects which are
- * pointers. Use read_ptr() instead!
- */
- template <typename type>
- const type read (const std::string& name) const;
-
- /**
- * @brief Dedicated read only access by name for pointer data.
- *
- * If the stored data object is a pointer to a constant object, the logic
- * of access becomes fairly complicated. Namely, the standard read
- * function may fail, depending on whether it was a const pointer
- * or a regular pointer. This function fixes the logic and
- * ascertains that the object does not become mutable by accident.
- */
- template <typename type>
- const type* read_ptr (const std::string& name) const;
-
- /**
- * Perform the same action as read_ptr(), but do not throw an
- * exception if the pointer does not exist. Return a null pointer
- * instead.
- */
- template <typename type>
- const type* try_read_ptr (const std::string& name) const;
-
- /**
- * @brief Dedicated read only access by name without exceptions.
- *
- * This function tries to find the name in the list and return a
- * pointer to the associated object. If either the name is not
- * found or the object cannot be converted to the return type, a
- * null pointer is returned.
- */
- template <typename type>
- const type * try_read (const std::string& name) const;
-
+public:
+ /// Default constructor for empty object
+ AnyData();
+
+ /// Number of stored data objects.
+ unsigned int size() const;
+
+ /// Add a new data object
+ template <typename type>
+ void add(type entry, const std::string &name);
+
+ /**
+ * @brief Merge the data of another NamedData to the end of this object.
+ */
+ void merge(const AnyData &other);
+
+ /**
+ * @brief Access to stored data object by name.
+ *
+ * Find the object with given name, try to convert it to
+ * <tt>type</tt> and return it. This function throws an exception
+ * if either the name does not exist or if the conversion
+ * fails. If such an exception is not desired, use try_read()
+ * instead.
+ */
+ template <typename type>
+ type entry (const std::string &name);
+
+ /**
+ * @brief Read-only access to stored data object by name.
+ *
+ * Find the object with given name, try to convert it to
+ * <tt>type</tt> and return it. This function throws an exception
+ * if either the name does not exist or if the conversion
+ * fails. If such an exception is not desired, use try_read()
+ * instead.
+ */
+ template <typename type>
+ const type entry (const std::string &name) const;
+
+ /**
+ * @brief Dedicated read only access by name.
+ *
+ * For a constant object, this function equals entry(). For a
+ * non-const object, it forces read only access to the data. In
+ * particular, it throws an exception if the object is not found
+ * or cannot be converted to type. If such an exception is not
+ * desired, use try_read() instead.
+ *
+ * @warning Do not use this function for stored objects which are
+ * pointers. Use read_ptr() instead!
+ */
+ template <typename type>
+ const type read (const std::string &name) const;
+
+ /**
+ * @brief Dedicated read only access by name for pointer data.
+ *
+ * If the stored data object is a pointer to a constant object, the logic
+ * of access becomes fairly complicated. Namely, the standard read
+ * function may fail, depending on whether it was a const pointer
+ * or a regular pointer. This function fixes the logic and
+ * ascertains that the object does not become mutable by accident.
+ */
+ template <typename type>
+ const type *read_ptr (const std::string &name) const;
+
+ /**
+ * Perform the same action as read_ptr(), but do not throw an
+ * exception if the pointer does not exist. Return a null pointer
+ * instead.
+ */
+ template <typename type>
+ const type *try_read_ptr (const std::string &name) const;
+
+ /**
+ * @brief Dedicated read only access by name without exceptions.
+ *
+ * This function tries to find the name in the list and return a
+ * pointer to the associated object. If either the name is not
+ * found or the object cannot be converted to the return type, a
+ * null pointer is returned.
+ */
+ template <typename type>
+ const type *try_read (const std::string &name) const;
+
/**
* Access to stored data object by index.
*/
- template <typename type>
- type entry (const unsigned int i);
-
- /// Read-only access to stored data object by index.
- template <typename type>
- const type entry (const unsigned int i) const;
-
- /// Dedicated read only access.
- template <typename type>
- const type read (const unsigned int i) const;
-
- /// Dedicated read only access to pointer object.
- template <typename type>
- const type* read_ptr (const unsigned int i) const;
-
- /// Dedicated read only access to pointer object without exception.
- template <typename type>
- const type* try_read_ptr (const unsigned int i) const;
-
- /// Dedicated read only access without exception.
- template <typename type>
- const type* try_read (const unsigned int i) const;
-
- /// Name of object at index.
- const std::string &name(const unsigned int i) const;
-
- /**
- * @brief Find index of a named object
- *
- * Try to find the objecty and return its index in the list. Throw
- * an exception if the object has not been found.
- */
- unsigned int find(const std::string &name) const;
-
- /**
- * @brief Try to find index of a named object
- *
- * Try to find the objecty and return its index in the
- * list. returns numbers::invalid_unsigned_int if the name was not
- * found.
- */
- unsigned int try_find(const std::string &name) const;
-
- /// Find out if object is of a certain type
- template <typename type>
- bool is_type(const unsigned int i) const;
-
- /// Conversion from old NamedData
- template <typename type>
- AnyData(const NamedData<type>&);
-
- /// An entry with this name does not exist in the AnyData object.
- DeclException1(ExcNameNotFound, std::string&,
- << "No entry with the name " << arg1 << " exists");
-
- /// The requested type and the stored type are different
- DeclException2(ExcTypeMismatch,
- char*, char*,
- << "The requested type " << arg1
- << " and the stored type " << arg2
- << " must coincide");
-
+ template <typename type>
+ type entry (const unsigned int i);
+
+ /// Read-only access to stored data object by index.
+ template <typename type>
+ const type entry (const unsigned int i) const;
+
+ /// Dedicated read only access.
+ template <typename type>
+ const type read (const unsigned int i) const;
+
+ /// Dedicated read only access to pointer object.
+ template <typename type>
+ const type *read_ptr (const unsigned int i) const;
+
+ /// Dedicated read only access to pointer object without exception.
+ template <typename type>
+ const type *try_read_ptr (const unsigned int i) const;
+
+ /// Dedicated read only access without exception.
+ template <typename type>
+ const type *try_read (const unsigned int i) const;
+
+ /// Name of object at index.
+ const std::string &name(const unsigned int i) const;
+
+ /**
+ * @brief Find index of a named object
+ *
+ * Try to find the objecty and return its index in the list. Throw
+ * an exception if the object has not been found.
+ */
+ unsigned int find(const std::string &name) const;
+
+ /**
+ * @brief Try to find index of a named object
+ *
+ * Try to find the objecty and return its index in the
+ * list. returns numbers::invalid_unsigned_int if the name was not
+ * found.
+ */
+ unsigned int try_find(const std::string &name) const;
+
+ /// Find out if object is of a certain type
+ template <typename type>
+ bool is_type(const unsigned int i) const;
+
+ /// Conversion from old NamedData
+ template <typename type>
+ AnyData(const NamedData<type> &);
+
+ /// An entry with this name does not exist in the AnyData object.
+ DeclException1(ExcNameNotFound, std::string &,
+ << "No entry with the name " << arg1 << " exists");
+
+ /// The requested type and the stored type are different
+ DeclException2(ExcTypeMismatch,
+ char *, char *,
+ << "The requested type " << arg1
+ << " and the stored type " << arg2
+ << " must coincide");
+
/**
* Exception indicating that a function expected a vector to have a
* certain name, but NamedData had a different name in that
*/
DeclException2(ExcNameMismatch, int, std::string,
<< "Name at position " << arg1 << " is not equal to " << arg2);
- private:
- /// The stored data
- std::vector<boost::any> data;
- /// The names of the stored data
- std::vector<std::string> names;
+private:
+ /// The stored data
+ std::vector<boost::any> data;
+ /// The names of the stored data
+ std::vector<std::string> names;
};
template <typename type>
inline
-AnyData::AnyData(const NamedData<type>& other)
+AnyData::AnyData(const NamedData<type> &other)
{
- for (unsigned int i=0;i<other.size();++i)
+ for (unsigned int i=0; i<other.size(); ++i)
add(other(i), other.name(i));
}
AnyData::entry (const unsigned int i)
{
AssertIndexRange(i, size());
- type* p = boost::any_cast<type>(&data[i]);
+ type *p = boost::any_cast<type>(&data[i]);
Assert(p != 0,
- ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
+ ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
return *p;
}
AnyData::entry (const unsigned int i) const
{
AssertIndexRange(i, size());
- const type* p = boost::any_cast<type>(&data[i]);
+ const type *p = boost::any_cast<type>(&data[i]);
if (p==0 )
p = boost::any_cast<const type>(&data[i]);
Assert(p != 0,
- ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
+ ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
return *p;
}
AnyData::read(const unsigned int i) const
{
AssertIndexRange(i, size());
- const type* p = boost::any_cast<type>(&data[i]);
+ const type *p = boost::any_cast<type>(&data[i]);
if (p==0)
p = boost::any_cast<const type>(&data[i]);
Assert(p != 0,
- ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
+ ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
return *p;
}
template <typename type>
inline
-const type*
+const type *
AnyData::read_ptr(const unsigned int i) const
{
AssertIndexRange(i, size());
- const type* const * p = boost::any_cast<type*>(&data[i]);
+ const type *const *p = boost::any_cast<type *>(&data[i]);
if (p==0)
- p = boost::any_cast<const type*>(&data[i]);
+ p = boost::any_cast<const type *>(&data[i]);
Assert(p != 0,
- ExcTypeMismatch(typeid(type*).name(),data[i].type().name()));
+ ExcTypeMismatch(typeid(type *).name(),data[i].type().name()));
return *p;
}
template <typename type>
inline
-const type*
+const type *
AnyData::try_read_ptr(const unsigned int i) const
{
AssertIndexRange(i, size());
- const type* const * p = boost::any_cast<type*>(&data[i]);
+ const type *const *p = boost::any_cast<type *>(&data[i]);
if (p==0)
- p = boost::any_cast<const type*>(&data[i]);
+ p = boost::any_cast<const type *>(&data[i]);
return *p;
}
template <typename type>
inline
-const type*
+const type *
AnyData::try_read(const unsigned int i) const
{
AssertIndexRange(i, size());
- const type* p = boost::any_cast<type>(&data[i]);
+ const type *p = boost::any_cast<type>(&data[i]);
if (p==0)
p = boost::any_cast<const type>(&data[i]);
return p;
inline
-const std::string&
+const std::string &
AnyData::name(const unsigned int i) const
{
AssertIndexRange(i, size());
inline
unsigned int
-AnyData::try_find(const std::string& n) const
+AnyData::try_find(const std::string &n) const
{
std::vector<std::string>::const_iterator it =
std::find(names.begin(), names.end(), n);
-
+
if (it == names.end())
return numbers::invalid_unsigned_int;
-
+
return it - names.begin();
}
inline
unsigned int
-AnyData::find(const std::string& n) const
+AnyData::find(const std::string &n) const
{
const unsigned int i = try_find(n);
Assert(i != numbers::invalid_unsigned_int, ExcNameNotFound(n));
-
+
return i;
}
template <typename type>
inline
type
-AnyData::entry (const std::string& n)
+AnyData::entry (const std::string &n)
{
const unsigned int i = find(n);
- type* p = boost::any_cast<type>(&data[i]);
+ type *p = boost::any_cast<type>(&data[i]);
Assert(p != 0,
- ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
+ ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
return *p;
}
template <typename type>
inline
const type
-AnyData::entry (const std::string& n) const
+AnyData::entry (const std::string &n) const
{
const unsigned int i = find(n);
- const type* p = boost::any_cast<type>(&data[i]);
+ const type *p = boost::any_cast<type>(&data[i]);
Assert(p != 0,
- ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
+ ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
return *p;
}
template <typename type>
inline
const type
-AnyData::read(const std::string& n) const
+AnyData::read(const std::string &n) const
{
const unsigned int i = find(n);
- const type* p = boost::any_cast<type>(&data[i]);
+ const type *p = boost::any_cast<type>(&data[i]);
Assert(p != 0,
- ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
+ ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
return *p;
}
template <typename type>
inline
-const type*
-AnyData::read_ptr(const std::string& n) const
+const type *
+AnyData::read_ptr(const std::string &n) const
{
const unsigned int i = find(n);
- const type* const * p = boost::any_cast<type*>(&data[i]);
+ const type *const *p = boost::any_cast<type *>(&data[i]);
if (p==0)
- p = boost::any_cast<const type*>(&data[i]);
+ p = boost::any_cast<const type *>(&data[i]);
Assert(p != 0,
- ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
+ ExcTypeMismatch(typeid(type).name(),data[i].type().name()));
return *p;
}
template <typename type>
inline
-const type*
-AnyData::try_read_ptr(const std::string& n) const
+const type *
+AnyData::try_read_ptr(const std::string &n) const
{
const unsigned int i = try_find(n);
if (i == numbers::invalid_unsigned_int)
return 0;
-
- const type* const * p = boost::any_cast<type*>(&data[i]);
+
+ const type *const *p = boost::any_cast<type *>(&data[i]);
if (p==0)
- p = boost::any_cast<const type*>(&data[i]);
+ p = boost::any_cast<const type *>(&data[i]);
return *p;
}
template <typename type>
inline
-const type*
-AnyData::try_read(const std::string& n) const
+const type *
+AnyData::try_read(const std::string &n) const
{
// Try to find name
std::vector<std::string>::const_iterator it =
// Compute index and return casted pointer
unsigned int i=it-names.begin();
- const type* p = boost::any_cast<type>(&data[i]);
+ const type *p = boost::any_cast<type>(&data[i]);
return p;
}
template <typename type>
inline
void
-AnyData::add(type ent, const std::string& n)
+AnyData::add(type ent, const std::string &n)
{
boost::any e = ent;
data.push_back(e);
inline
void
-AnyData::merge(const AnyData& other)
+AnyData::merge(const AnyData &other)
{
for (unsigned int i=0; i<other.size(); ++i)
{
{
template <class VECTOR>
Operator<VECTOR>::Operator()
- : silent_compatibility(false), compatibility_flag(false)
+ : silent_compatibility(false), compatibility_flag(false)
{}
template <class VECTOR>
void
- Operator<VECTOR>::operator() (AnyData& out, const AnyData& in)
+ Operator<VECTOR>::operator() (AnyData &out, const AnyData &in)
{
// Had this function been overloaded in a derived clas, it would
// not have been called. Therefore, we have to start the
// compatibility engine. But before, we have to avoid an endless loop.
Assert(!compatibility_flag, ExcMessage("Compatibility resolution of Operator generates and endless loop\n"
- "Please provide an operator() in a derived class"));
+ "Please provide an operator() in a derived class"));
compatibility_flag = true;
-
- NamedData<VECTOR*> new_out;
- for (unsigned int i=0;i<out.size();++i)
+
+ NamedData<VECTOR *> new_out;
+ for (unsigned int i=0; i<out.size(); ++i)
{
- if (out.is_type<VECTOR*>(i))
- new_out.add(out.entry<VECTOR*>(i), out.name(i));
- else
- if (!silent_compatibility)
- deallog << "Cannot convert AnyData argument " << out.name(i) << " to NamedData"
- << std::endl;
+ if (out.is_type<VECTOR *>(i))
+ new_out.add(out.entry<VECTOR *>(i), out.name(i));
+ else if (!silent_compatibility)
+ deallog << "Cannot convert AnyData argument " << out.name(i) << " to NamedData"
+ << std::endl;
}
-
- NamedData<VECTOR*> new_in;
- for (unsigned int i=0;i<in.size();++i)
+
+ NamedData<VECTOR *> new_in;
+ for (unsigned int i=0; i<in.size(); ++i)
{
- // deallog << "Convert " << in.name(i) << std::endl;
- if (in.is_type<VECTOR*>(i))
- {
- // This const cast is due to the wrong constness handling
- // in NamedData. As soon as NamedData is gone, this code
- // will not be necessary anymore. And deprecating begins
- // now.
- VECTOR* p = const_cast<VECTOR*> (in.entry<VECTOR*>(i));
- new_in.add(p, in.name(i));
- }
- else if (in.is_type<const VECTOR*>(i))
- {
- // This const cast is due to the wrong constness handling
- // in NamedData. As soon as NamedData is gone, this code
- // will not be necessary anymore. And deprecating begins
- // now.
- VECTOR* p = const_cast<VECTOR*> (in.entry<const VECTOR*>(i));
- new_in.add(p, in.name(i));
- }
- else
- if (!silent_compatibility)
- deallog << "Cannot convert AnyData argument " << in.name(i)
- << " to NamedData" << std::endl;
+ // deallog << "Convert " << in.name(i) << std::endl;
+ if (in.is_type<VECTOR *>(i))
+ {
+ // This const cast is due to the wrong constness handling
+ // in NamedData. As soon as NamedData is gone, this code
+ // will not be necessary anymore. And deprecating begins
+ // now.
+ VECTOR *p = const_cast<VECTOR *> (in.entry<VECTOR *>(i));
+ new_in.add(p, in.name(i));
+ }
+ else if (in.is_type<const VECTOR *>(i))
+ {
+ // This const cast is due to the wrong constness handling
+ // in NamedData. As soon as NamedData is gone, this code
+ // will not be necessary anymore. And deprecating begins
+ // now.
+ VECTOR *p = const_cast<VECTOR *> (in.entry<const VECTOR *>(i));
+ new_in.add(p, in.name(i));
+ }
+ else if (!silent_compatibility)
+ deallog << "Cannot convert AnyData argument " << in.name(i)
+ << " to NamedData" << std::endl;
}
this->operator() (new_out, new_in);
compatibility_flag = false;
template <class VECTOR>
void
- Operator<VECTOR>::operator() (NamedData<VECTOR*>& out, const NamedData<VECTOR*>& in)
+ Operator<VECTOR>::operator() (NamedData<VECTOR *> &out, const NamedData<VECTOR *> &in)
{
// Had this function been overloaded in a derived clas, it would
// not have been called. Therefore, we have to start the
// compatibility engine. But before, we have to avoid an endless loop.
Assert(!compatibility_flag, ExcMessage("Compatibility resolution of Operator generates and endless loop\n"
- "Please provide an operator() in a derived class"));
+ "Please provide an operator() in a derived class"));
compatibility_flag = true;
-
+
AnyData new_out;
- for (unsigned int i=0;i<out.size();++i)
+ for (unsigned int i=0; i<out.size(); ++i)
new_out.add(out(i), out.name(i));
AnyData new_in;
- for (unsigned int i=0;i<in.size();++i)
+ for (unsigned int i=0; i<in.size(); ++i)
new_in.add(in(i), in.name(i));
this->operator() (new_out, new_in);
template <class VECTOR>
OutputOperator<VECTOR> &
- OutputOperator<VECTOR>::operator<< (const AnyData& vectors)
+ OutputOperator<VECTOR>::operator<< (const AnyData &vectors)
{
if (os == 0)
{
deallog << "Step " << step << std::endl;
for (unsigned int i=0; i<vectors.size(); ++i)
- {
- const VECTOR* v = vectors.try_read_ptr<VECTOR>(i);
- if (v == 0) continue;
- for (unsigned int j=0; j<v->size(); ++j)
- (*os) << ' ' << (*v)(j);
- deallog << std::endl;
- }
+ {
+ const VECTOR *v = vectors.try_read_ptr<VECTOR>(i);
+ if (v == 0) continue;
+ for (unsigned int j=0; j<v->size(); ++j)
+ (*os) << ' ' << (*v)(j);
+ deallog << std::endl;
+ }
deallog << std::endl;
}
else
{
(*os) << ' ' << step;
for (unsigned int i=0; i<vectors.size(); ++i)
- {
- const VECTOR* v = vectors.try_read_ptr<VECTOR>(i);
- if (v == 0) continue;
- for (unsigned int j=0; j<v->size(); ++j)
- (*os) << ' ' << (*v)(j);
- (*os) << std::endl;
- }
+ {
+ const VECTOR *v = vectors.try_read_ptr<VECTOR>(i);
+ if (v == 0) continue;
+ for (unsigned int j=0; j<v->size(); ++j)
+ (*os) << ' ' << (*v)(j);
+ (*os) << std::endl;
+ }
(*os) << std::endl;
}
return *this;
}
-
+
template <class VECTOR>
OutputOperator<VECTOR> &