14 #include <boost/lexical_cast.hpp>
15 #include <range/v3/view/transform.hpp>
19 #include <experimental/filesystem>
24 namespace hipipe::utility {
36 return boost::lexical_cast<T>(str);
37 }
catch(
const boost::bad_lexical_cast &) {
38 throw std::ios_base::failure{std::string{
"Failed to read type <"} +
typeid(T).name() +
39 "> from string \"" + str +
"\"."};
45 inline std::string string_to<std::string>(
const std::string& str)
52 inline std::experimental::filesystem::path
53 string_to<std::experimental::filesystem::path>(
const std::string& str)
61 const std::set<std::string> true_set =
62 {
"true ",
"True ",
"TRUE ",
"1",
"y",
"Y",
"yes",
"Yes",
"YES",
"on ",
"On ",
"ON"};
64 const std::set<std::string> false_set =
65 {
"false",
"False",
"FALSE",
"0",
"n",
"N",
"no ",
"No ",
"NO ",
"off",
"Off",
"OFF"};
77 inline bool string_to<bool>(
const std::string& str)
79 if (detail::true_set.count(str))
return true;
80 if (detail::false_set.count(str))
return false;
81 throw std::ios_base::failure{
"Failed to convert string \"" + str +
"\" to bool."};
94 return boost::lexical_cast<std::string>(value);
95 }
catch(
const boost::bad_lexical_cast &) {
96 throw std::ios_base::failure{std::string{
"Failed to read string from type <"}
97 +
typeid(T).name() +
">."};
102 inline std::string
to_string(
const std::experimental::filesystem::path& path)
104 return path.string();
108 inline std::string
to_string(
const std::string& str)
114 inline std::string
to_string(
const char*
const& str)
122 inline std::string
to_string(
const bool& b)
124 return b ?
"true" :
"false";