const std::unique_ptr<Patterns::PatternBase>
&p = Convert<T>::to_pattern())
{
- std::string str;
- if (std::is_same<T, unsigned char>() || std::is_same<T, signed char>())
- str = std::to_string((int)value);
+ std::stringstream str;
+ if (std::is_same<T, unsigned char>::value ||
+ std::is_same<T, signed char>::value ||
+ std::is_same<T, char>::value)
+ str << (int)value;
else if (std::is_same<T,bool>::value)
- str = value ? "true" : "false";
+ str << (value ? "true" : "false");
else
- str = std::to_string(value);
- AssertThrow(p->match(str), ExcNoMatch(str, *p));
- return str;
+ str << value;
+ AssertThrow(p->match(str.str()), ExcNoMatch(str.str(), *p));
+ return str.str();
}
static T to_value(const std::string &s,
else
{
std::istringstream is(s);
- if (std::is_same<T, unsigned char>::value || std::is_same<T, signed char>::value)
+ if (std::is_same<T, unsigned char>::value ||
+ std::is_same<T, signed char>::value ||
+ std::is_same<T, char>::value)
{
int i;
is >> i;
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2005 - 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 Convert<...>::to_string() for small numbers, and make sure
+// we don't break anything for integral types
+
+#include "../tests.h"
+#include <deal.II/base/parameter_handler.h>
+#include <deal.II/base/std_cxx14/memory.h>
+#include <memory>
+#include <tuple>
+
+int main()
+{
+ initlog();
+
+ double a = 1e-12;
+ int i = -1;
+ unsigned int j = 3;
+ unsigned char c = 3;
+ signed char c1 = -3;
+ char c2 = -3;
+ bool b = false;
+
+ auto t = std::make_tuple(a,i,j,c,c1,c2,b);
+
+ auto s = Patterns::Tools::Convert<decltype(t)>::to_string(t);
+ auto tt = Patterns::Tools::Convert<decltype(t)>::to_value(s);
+ auto r = Patterns::Tools::Convert<decltype(t)>::to_string(tt);
+
+ deallog << "String: " << s
+ << ", roundtrip: " << r << std::endl;
+}