*/
unsigned int max_level () const;
+ /**
+ * Apply the action @p action to every object stored in here. The
+ * parameter @p action is expected to be a function object that accepts
+ * the syntax
+ * <code>
+ * action(const unsigned int level, Object &object);
+ * </code>
+ * This means this function can accept a lambda, a std::function, or a plain
+ * function pointer.
+ */
+ template <typename ActionFunctionObjectType>
+ void apply (ActionFunctionObjectType action);
+
/**
* Memory used by this object.
*/
return minlevel + objects.size() - 1;
}
+template<class Object>
+template <typename ActionFunctionObjectType>
+void
+MGLevelObject<Object>::apply (ActionFunctionObjectType action)
+{
+ for (unsigned int lvl = min_level(); lvl <= max_level(); ++lvl)
+ {
+ action (lvl, (*this)[lvl]);
+ }
+}
+
template <class Object>
std::size_t
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 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.
+//
+// ---------------------------------------------------------------------
+
+
+// check MGLevelObject::apply()
+
+#include "../tests.h"
+#include <deal.II/base/mg_level_object.h>
+
+#include <fstream>
+#include <iomanip>
+#include <iomanip>
+#include <algorithm>
+
+using namespace std;
+
+
+template <class T>
+void check(MGLevelObject<T> &obj)
+{
+ obj.apply([&] (const unsigned int lvl, T & value)
+ {
+ value = (T)lvl;
+ });
+
+ obj.apply([&] (const unsigned int lvl, T & value)
+ {
+ deallog << "lvl: " << lvl << " value: " << value << std::endl;
+ });
+}
+
+int main()
+{
+ initlog();
+
+ MGLevelObject<double> o(2,4);
+ check(o);
+ o.resize(0,1);
+ check(o);
+}
--- /dev/null
+
+DEAL::lvl: 2 value: 2.00000
+DEAL::lvl: 3 value: 3.00000
+DEAL::lvl: 4 value: 4.00000
+DEAL::lvl: 0 value: 0.00000
+DEAL::lvl: 1 value: 1.00000