<h3>Specific improvements</h3>
<ol>
+ <li>
+ New: Patterns::List now accepts a string that denotes the separator
+ between entries of the list.
+ <br>
+ (Wolfgang Bangerth, 2013/08/21)
+ </li>
+
<li>
Fixed: Some operations in the MappingQ class are now done in higher
precision arithmetic to mitigate the ill-conditioning that appears
/**
- * This pattern matches a list of comma-separated values each of which
+ * This pattern matches a list of values separated by commas (or another
+ * string), each of which
* have to match a pattern given to the constructor. With two additional
* parameters, the number of elements this list has to have can be
* specified. If none is specified, the list may have zero or more
* Constructor. Take the given parameter as the specification of valid
* elements of the list.
*
- * The two other arguments can be used to denote minimal and maximal
- * allowable lengths of the list.
+ * The three other arguments can be used to denote minimal and maximal
+ * allowable lengths of the list, and the string that is used as a
+ * separator between elements of the list.
*/
List (const PatternBase &base_pattern,
const unsigned int min_elements = 0,
- const unsigned int max_elements = max_int_value);
+ const unsigned int max_elements = max_int_value,
+ const std::string &separator = ",");
/**
* Destructor.
*/
const unsigned int max_elements;
+ /**
+ * Separator between elements of the list.
+ */
+ const std::string separator;
+
/**
* Initial part of description
*/
List::List (const PatternBase &p,
const unsigned int min_elements,
- const unsigned int max_elements)
+ const unsigned int max_elements,
+ const std::string &separator)
:
pattern (p.clone()),
min_elements (min_elements),
- max_elements (max_elements)
+ max_elements (max_elements),
+ separator (separator)
{
Assert (min_elements <= max_elements,
ExcInvalidRange (min_elements, max_elements));
+ Assert (separator.size() > 0,
+ ExcMessage ("The separator must have a non-zero length."));
}
{
std::string tmp = test_string_list;
std::vector<std::string> split_list;
- split_list.reserve (std::count (tmp.begin(), tmp.end(), ',')+1);
// first split the input list
while (tmp.length() != 0)
std::string name;
name = tmp;
- if (name.find(",") != std::string::npos)
+ if (name.find(separator) != std::string::npos)
{
- name.erase (name.find(","), std::string::npos);
- tmp.erase (0, tmp.find(",")+1);
+ name.erase (name.find(separator), std::string::npos);
+ tmp.erase (0, tmp.find(separator)+separator.size());
}
else
tmp = "";
name.erase (name.length()-1, 1);
split_list.push_back (name);
- };
+ }
if ((split_list.size() < min_elements) ||
(split_list.size() > max_elements))
description << description_init
<< " list of <" << pattern->description() << ">"
<< " of length " << min_elements << "..." << max_elements
- << " (inclusive)"
- << "]";
+ << " (inclusive)";
+ if (separator != ",")
+ description << " separated by <" << separator << ">";
+ description << "]";
return description.str();
}
PatternBase *
List::clone () const
{
- return new List(*pattern, min_elements, max_elements);
+ return new List(*pattern, min_elements, max_elements, separator);
}
List::memory_consumption () const
{
return (sizeof(*this) +
- MemoryConsumption::memory_consumption(*pattern));
+ MemoryConsumption::memory_consumption(*pattern) +
+ MemoryConsumption::memory_consumption(separator));
}
if (!(is >> max_elements))
return new List(*base_pattern, min_elements);
- return new List(*base_pattern, min_elements, max_elements);
+ is.ignore(strlen(" separated by <"));
+ std::string separator;
+ if (!is)
+ std::getline(is, separator, '>');
+
+ return new List(*base_pattern, min_elements, max_elements, separator);
}
else
return 0;
--- /dev/null
+// ---------------------------------------------------------------------
+// $Id$
+//
+// Copyright (C) 2002 - 2013 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 the Patterns::List pattern
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/parameter_handler.h>
+#include <fstream>
+
+void check (const char *p)
+{
+ ParameterHandler prm;
+ prm.declare_entry ("test_1", "-1,0",
+ Patterns::List(Patterns::Integer(-1,1),2,3,"xyz"));
+
+ std::ifstream in(p);
+ prm.read_input (in);
+
+ deallog << "test_1=" << prm.get ("test_1") << std::endl;
+}
+
+
+int main ()
+{
+ std::ofstream logfile("parameter_handler_1a/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ check ("parameter_handler_1a/prm");
+
+ return 0;
+}
--- /dev/null
+
+DEAL::test_1=-1,0
--- /dev/null
+set test_1 = 1,0,1xyz1,0,-1