#include <deal.II/base/subscriptor.h>
#include <deal.II/base/utilities.h>
#include <deal.II/base/std_cxx14/algorithm.h>
+#include <deal.II/base/template_constraints.h>
#include <boost/archive/basic_archive.hpp>
#include <boost/core/demangle.hpp>
{
public:
/**
- * Constructor. Specify each pattern that the Tuple should contain.
+ * Constructor. Use a vector of unique pointers to Patterns to construct
+ * the tuple.
*
- * Optionally specify a separator string.
- */
-
- /**
- * Constructor.
* @param patterns The pattern each object of the Tuple should match
* @param separator An optional string used to delimit each element
+ * Constructor.
*/
Tuple (const std::vector<std::unique_ptr<PatternBase> > &patterns,
const std::string &separator = ",");
+ /**
+ * Constructor. Creates a Tuple from more than one class derived from
+ * PatternBase.
+ *
+ * @param separator What separator to use.
+ * @param patterns The list of patterns to use
+ */
+ template<class... PatternTypes>
+ Tuple (const std::string &separator,
+ const PatternTypes &... patterns);
+
+ /**
+ * Constructor. This is needed to allow users to specify
+ * directly the separator without using std::string(";").
+ *
+ * Since we support a pure variadic templates version, without this
+ * specialization, the compiler will fail with criptic errors.
+ */
+ template<class... PatternTypes>
+ Tuple (const char *separator,
+ const PatternTypes &... patterns);
+
+ /**
+ * Constructor. Same as above, using the default separator.
+ *
+ * @param patterns The list of patterns to use
+ */
+ template<typename... Patterns>
+ Tuple (const Patterns &... patterns);
+
/**
* Copy constructor.
*/
const std::string separator;
/**
- * Initial part of description
+ * Initial part of description.
*/
static const char *description_init;
};
-
/**
* This class is much like the Selection class, but it allows the input to
* be a comma-separated list of values which each have to be given in the
// ---------------------- inline and template functions --------------------
namespace Patterns
{
+ template<class... PatternTypes>
+ Tuple::Tuple(const char *separator,
+ const PatternTypes &... ps) :
+ separator(separator)
+ {
+ static_assert(is_base_of_all<PatternBase, PatternTypes...>::value,
+ "Not all of the input arguments of this function "
+ "are derived from PatternBase");
+ std::initializer_list<const PatternBase *> pss = { &ps... };
+ for (auto p : pss)
+ patterns.push_back(p->clone());
+ }
+
+
+
+ template<class... PatternTypes>
+ Tuple::Tuple(const std::string &separator,
+ const PatternTypes &... ps) :
+ separator(separator)
+ {
+ static_assert(is_base_of_all<PatternBase, PatternTypes...>::value,
+ "Not all of the input arguments of this function "
+ "are derived from PatternBase");
+ std::initializer_list<const PatternBase *> pss = { &ps... };
+ for (auto p : pss)
+ patterns.push_back(p->clone());
+ }
+
+
+
+ template<class... PatternTypes>
+ Tuple::Tuple(const PatternTypes &... ps) :
+ separator(",")
+ {
+ static_assert(is_base_of_all<PatternBase, PatternTypes...>::value,
+ "Not all of the input arguments of this function "
+ "are derived from PatternBase");
+ std::initializer_list<const PatternBase *> pss = { &ps... };
+ for (auto p : pss)
+ patterns.push_back(p->clone());
+ }
+
+
+
namespace Tools
{
namespace internal
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2005 - 2015 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.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/base/parameter_handler.h>
+#include <deal.II/base/std_cxx14/memory.h>
+#include <memory>
+
+int main()
+{
+ initlog();
+
+ // create a pattern and match a string
+ const auto &pattern = Patterns::Tuple(";", Patterns::Integer(), Patterns::Double(), Patterns::Anything());
+ const std::string desc = pattern.description();
+
+ deallog << desc << std::endl;
+
+ std::string test = "5; 3.14; Ciao";
+
+ if (pattern.match(test))
+ deallog << "OK" << std::endl;
+ else
+ deallog << "Not OK" << std::endl;
+}
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2005 - 2015 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.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/base/parameter_handler.h>
+#include <deal.II/base/std_cxx14/memory.h>
+#include <memory>
+
+int main()
+{
+ initlog();
+
+ // create a pattern and match a string
+ const auto &pattern = Patterns::Tuple(Patterns::Double(), Patterns::Anything());
+ const std::string desc = pattern.description();
+
+ deallog << desc << std::endl;
+
+ std::string test = "3.14, Ciao";
+
+ if (pattern.match(test))
+ deallog << "OK" << std::endl;
+ else
+ deallog << "Not OK" << std::endl;
+}