6 #include <boost/spirit/include/classic.hpp> 7 #include <boost/spirit/include/phoenix_core.hpp> 8 #include <boost/spirit/include/phoenix_operator.hpp> 9 #include <boost/spirit/include/qi.hpp> 18 std::tuple<uint64_t, bool>
parseMemory(
const std::string& memory)
20 using boost::phoenix::ref;
21 using boost::spirit::qi::_1;
22 using boost::spirit::qi::double_;
23 using boost::spirit::qi::no_case;
24 using boost::spirit::qi::phrase_parse;
26 struct bytes_decades_ : boost::spirit::qi::symbols<char, uint64_t>
29 add(
"kB", 1e3)(
"mB", 1e6)(
"gB", 1e9)(
"tB", 1e12)(
"KB", 1e3)(
"MB", 1e6)(
"GB", 1e9)(
30 "TB", 1e12)(
"B", 1)(
"KiB",
static_cast<uint64_t
>(1ull<<10))(
"MiB",
31 static_cast<uint64_t
>(1ull<<20))(
"GiB",
static_cast<uint64_t
>(1ull<<30))(
"TiB",
32 static_cast<uint64_t
>(1ull<<40));
36 auto it = memory.begin();
38 bool ok = phrase_parse(it, memory.end(),
39 (double_[ref(res) = _1] >> -(byte_decades[ref(res) *= _1])),
40 boost::spirit::ascii::space
43 return std::make_tuple(static_cast<uint64_t>(res), ok);
std::tuple< uint64_t, bool > parseMemory(const std::string &memory)