* class template for particular kinds of template arguments @p T.
*/
static std::string
- to_string(const T & s,
- const std::unique_ptr<Patterns::PatternBase> &p =
- Convert<T>::to_pattern()) = delete;
+ to_string(const T & s,
+ const Patterns::PatternBase &p = *Convert<T>::to_pattern()) =
+ delete;
/**
* Convert a string to a value, using the given pattern. Use the pattern
* class template for particular kinds of template arguments @p T.
*/
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &p =
- Convert<T>::to_pattern()) = delete;
+ to_value(const std::string & s,
+ const Patterns::PatternBase &p = *Convert<T>::to_pattern()) =
+ delete;
};
/**
}
static std::string
- to_string(const T & value,
- const std::unique_ptr<Patterns::PatternBase> &p =
- Convert<T>::to_pattern())
+ to_string(const T & value,
+ const Patterns::PatternBase &p = *Convert<T>::to_pattern())
{
std::stringstream str;
if (std::is_same<T, unsigned char>::value ||
str << (static_cast<bool>(value) ? "true" : "false");
else
str << value;
- AssertThrow(p->match(str.str()),
- ExcNoMatch(str.str(), p->description()));
+ AssertThrow(p.match(str.str()), ExcNoMatch(str.str(), p.description()));
return str.str();
}
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &p =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &p = *Convert<T>::to_pattern())
{
- AssertThrow(p->match(s), ExcNoMatch(s, p->description()));
+ AssertThrow(p.match(s), ExcNoMatch(s, p.description()));
T value;
if (std::is_same<T, bool>::value)
value = (s == "true");
}
static std::string
- to_string(const T & t,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_string(
+ const T & t,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- auto p = dynamic_cast<const Patterns::List *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::List *>(&pattern);
AssertThrow(p,
ExcMessage("I need a List pattern to convert a "
"string to a List type."));
std::transform(
t.cbegin(), t.cend(), vec.begin(), [&base_p](const auto &entry) {
- return Convert<typename T::value_type>::to_string(entry, base_p);
+ return Convert<typename T::value_type>::to_string(entry, *base_p);
});
std::string s;
for (unsigned int i = 1; i < vec.size(); ++i)
s += p->get_separator() + " " + vec[i];
- AssertThrow(pattern->match(s), ExcNoMatch(s, p->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
return s;
}
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- AssertThrow(pattern->match(s), ExcNoMatch(s, pattern->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
- auto p = dynamic_cast<const Patterns::List *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::List *>(&pattern);
AssertThrow(p,
ExcMessage("I need a List pattern to convert a string "
"to a List type."));
auto v = Utilities::split_string_list(s, p->get_separator());
for (const auto &str : v)
t.insert(t.end(),
- Convert<typename T::value_type>::to_value(str, base_p));
+ Convert<typename T::value_type>::to_value(str, *base_p));
return t;
}
}
static std::string
- to_string(const T & t,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_string(
+ const T & t,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- auto p = dynamic_cast<const Patterns::Map *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::Map *>(&pattern);
AssertThrow(p,
ExcMessage("I need a Map pattern to convert a string to "
"a Map compatible type."));
unsigned int i = 0;
for (const auto &ti : t)
vec[i++] =
- Convert<typename T::key_type>::to_string(ti.first, key_p) +
+ Convert<typename T::key_type>::to_string(ti.first, *key_p) +
p->get_key_value_separator() +
- Convert<typename T::mapped_type>::to_string(ti.second, val_p);
+ Convert<typename T::mapped_type>::to_string(ti.second, *val_p);
std::string s;
if (vec.size() > 0)
}
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- AssertThrow(pattern->match(s), ExcNoMatch(s, pattern->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
- auto p = dynamic_cast<const Patterns::Map *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::Map *>(&pattern);
AssertThrow(p,
ExcMessage("I need a Map pattern to convert a "
"string to a Map compatible type."));
Utilities::split_string_list(str, p->get_key_value_separator());
AssertDimension(key_val.size(), 2);
t.insert(std::make_pair(
- Convert<typename T::key_type>::to_value(key_val[0], key_p),
+ Convert<typename T::key_type>::to_value(key_val[0], *key_p),
Convert<typename T::mapped_type>::to_value(key_val[1])));
}
}
static std::string
- to_string(const T & t,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_string(
+ const T & t,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- auto p = dynamic_cast<const Patterns::List *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::List *>(&pattern);
AssertThrow(p,
ExcMessage("I need a List pattern to convert a string "
"to a List compatible type."));
std::vector<std::string> vec(dim);
for (unsigned int i = 0; i < dim; ++i)
- vec[i] = Convert<typename T::value_type>::to_string(t[i], base_p);
+ vec[i] = Convert<typename T::value_type>::to_string(t[i], *base_p);
std::string s;
if (vec.size() > 0)
}
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- AssertThrow(pattern->match(s), ExcNoMatch(s, pattern->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
- auto p = dynamic_cast<const Patterns::List *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::List *>(&pattern);
AssertThrow(p,
ExcMessage("I need a List pattern to convert a string "
"to a List compatible type."));
auto v = Utilities::split_string_list(s, p->get_separator());
unsigned int i = 0;
for (const auto &str : v)
- t[i++] = Convert<typename T::value_type>::to_value(str, base_p);
+ t[i++] = Convert<typename T::value_type>::to_value(str, *base_p);
return t;
}
}
static std::string
- to_string(const T & t,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_string(
+ const T & t,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
return Convert<Tensor<1, dim, Number>>::to_string(
Tensor<1, dim, Number>(t), pattern);
}
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
return T(Convert<Tensor<1, dim, Number>>::to_value(s, pattern));
}
}
static std::string
- to_string(const T & t,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_string(
+ const T & t,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- auto p = dynamic_cast<const Patterns::List *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::List *>(&pattern);
AssertThrow(p,
ExcMessage("I need a List pattern to convert a string "
"to a List compatible type."));
for (unsigned int i = 1; i < expressions.size(); ++i)
s = s + p->get_separator() + expressions[i];
- AssertThrow(pattern->match(s), ExcNoMatch(s, p->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
return s;
}
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- AssertThrow(pattern->match(s), ExcNoMatch(s, pattern->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
- auto p = dynamic_cast<const Patterns::List *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::List *>(&pattern);
AssertThrow(p,
ExcMessage("I need a List pattern to convert a string "
"to a List compatible type."));
}
static std::string
- to_string(const T & t,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_string(
+ const T & t,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
std::vector<bool> mask(t.size());
for (unsigned int i = 0; i < t.size(); ++i)
}
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
const auto mask = Convert<std::vector<bool>>::to_value(s, pattern);
return ComponentMask(mask);
}
static std::string
- to_string(const T & t,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_string(
+ const T & t,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- auto p = dynamic_cast<const Patterns::List *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::List *>(&pattern);
AssertThrow(p,
ExcMessage("I need a List pattern to convert a string "
"to a List compatible type."));
auto base_p = p->get_base_pattern().clone();
std::string s =
- Convert<typename T::value_type>::to_string(t.real(), base_p) +
+ Convert<typename T::value_type>::to_string(t.real(), *base_p) +
p->get_separator() + " " +
- Convert<typename T::value_type>::to_string(t.imag(), base_p);
+ Convert<typename T::value_type>::to_string(t.imag(), *base_p);
- AssertThrow(pattern->match(s), ExcNoMatch(s, p->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, p->description()));
return s;
}
* Convert a string to a value, using the given pattern, or a default one.
*/
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- AssertThrow(pattern->match(s), ExcNoMatch(s, pattern->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
- auto p = dynamic_cast<const Patterns::List *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::List *>(&pattern);
AssertThrow(p,
ExcMessage("I need a List pattern to convert a string "
"to a List compatible type."));
auto v = Utilities::split_string_list(s, p->get_separator());
AssertDimension(v.size(), 2);
- T t(Convert<typename T::value_type>::to_value(v[0], base_p),
- Convert<typename T::value_type>::to_value(v[1], base_p));
+ T t(Convert<typename T::value_type>::to_value(v[0], *base_p),
+ Convert<typename T::value_type>::to_value(v[1], *base_p));
return t;
}
};
}
static std::string
- to_string(const T & t,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_string(
+ const T & t,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- AssertThrow(pattern->match(t), ExcNoMatch(t, pattern->description()));
+ AssertThrow(pattern.match(t), ExcNoMatch(t, pattern.description()));
return t;
}
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- AssertThrow(pattern->match(s), ExcNoMatch(s, pattern->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
return s;
}
};
}
static std::string
- to_string(const T & t,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_string(
+ const T & t,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
std::tuple<Key, Value> m(t);
std::string s = Convert<decltype(m)>::to_string(m, pattern);
- AssertThrow(pattern->match(s), ExcNoMatch(s, pattern->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
return s;
}
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
std::tuple<Key, Value> m;
m = Convert<decltype(m)>::to_value(s, pattern);
}
static std::string
- to_string(const T & t,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_string(
+ const T & t,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- auto p = dynamic_cast<const Patterns::Tuple *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::Tuple *>(&pattern);
AssertThrow(p,
ExcMessage("I need a Tuple pattern to convert a tuple "
"to a string."));
}
static T
- to_value(const std::string & s,
- const std::unique_ptr<Patterns::PatternBase> &pattern =
- Convert<T>::to_pattern())
+ to_value(const std::string & s,
+ const Patterns::PatternBase &pattern = *Convert<T>::to_pattern())
{
- AssertThrow(pattern->match(s), ExcNoMatch(s, pattern->description()));
+ AssertThrow(pattern.match(s), ExcNoMatch(s, pattern.description()));
- auto p = dynamic_cast<const Patterns::Tuple *>(pattern.get());
+ auto p = dynamic_cast<const Patterns::Tuple *>(&pattern);
AssertThrow(p,
ExcMessage("I need a Tuple pattern to convert a string "
"to a tuple type."));
{
std::array<std::string, std::tuple_size<T>::value> a = {
{Convert<typename std::tuple_element<U, T>::type>::to_string(
- std::get<U>(t), pattern.get_pattern(U).clone())...}};
+ std::get<U>(t), *pattern.get_pattern(U).clone())...}};
return a;
}
{
return std::make_tuple(
Convert<typename std::tuple_element<U, T>::type>::to_value(
- s[U], pattern.get_pattern(U).clone())...);
+ s[U], *pattern.get_pattern(U).clone())...);
}
static T