3 #include <boost/any.hpp>
4 #include <boost/program_options.hpp>
5 #include <boost/spirit/include/qi.hpp>
11 namespace pov = boost::program_options::validators;
12 namespace qi = boost::spirit::qi;
14 std::string s(pov::get_single_string(values));
17 std::chrono::nanoseconds factor;
18 qi::symbols<char, std::chrono::nanoseconds> unit;
20 (
"ns", std::chrono::nanoseconds(1))
21 (
"µs", std::chrono::microseconds(1))
22 (
"us", std::chrono::microseconds(1))
23 (
"ms", std::chrono::milliseconds(1))
24 (
"s", std::chrono::seconds(1))
25 (
"m", std::chrono::minutes(1))
26 (
"h", std::chrono::hours(1))
28 if (
qi::parse(s.begin(), s.end(), qi::long_ >> unit >> qi::eoi, value, factor)) {
31 throw boost::program_options::invalid_option_value(s);
36 namespace pov = boost::program_options::validators;
37 namespace qi = boost::spirit::qi;
39 std::string s(pov::get_single_string(values));
41 std::size_t value = 0;
42 std::size_t factor = 1;
43 qi::symbols<char, std::size_t> unit;
45 (
"K",
static_cast<std::size_t
>(1) << 10U)
46 (
"Ki",
static_cast<std::size_t
>(1) << 10U)
47 (
"M",
static_cast<std::size_t
>(1) << 20U)
48 (
"Mi",
static_cast<std::size_t
>(1) << 20U)
49 (
"G",
static_cast<std::size_t
>(1) << 30U)
50 (
"Gi",
static_cast<std::size_t
>(1) << 30U)
51 (
"T",
static_cast<std::size_t
>(1) << 40U)
52 (
"Ti",
static_cast<std::size_t
>(1) << 40U)
53 (
"P",
static_cast<std::size_t
>(1) << 50U)
54 (
"Pi",
static_cast<std::size_t
>(1) << 50U)
55 (
"E",
static_cast<std::size_t
>(1) << 60U)
56 (
"Ei",
static_cast<std::size_t
>(1) << 60U)
58 if (
qi::parse(s.begin(), s.end(), qi::ulong_long >> -unit >> qi::eoi, value, factor)) {
61 throw boost::program_options::invalid_option_value(s);
66 namespace pov = boost::program_options::validators;
67 namespace qi = boost::spirit::qi;
69 std::string s(pov::get_single_string(values));
71 std::size_t value = 0;
72 std::size_t factor = 1;
73 qi::symbols<char, std::size_t> unit;
79 (
"P", 1000000000000000)
80 (
"E", 1000000000000000000)
82 if (
qi::parse(s.begin(), s.end(), qi::ulong_long >> -unit >> qi::eoi, value, factor)) {
85 throw boost::program_options::invalid_option_value(s);
T parse(const std::string &n)
void validate(boost::any &v, const std::vector< std::string > &values, carl::settings::duration *, int)
Custom validator for duration that wraps some std::chrono::duration.
std::chrono::duration< std::size_t, std::milli > duration
The duration type used here.
Helper type to parse duration as std::chrono values with boost::program_options.
Helper type to parse quantities with binary SI-style suffixes.
Helper type to parse quantities with SI-style suffixes.