Commit d6472906 authored by Max Kellermann's avatar Max Kellermann

config/Parser: use std::size_t

parent ab318200
......@@ -70,28 +70,28 @@ ParsePositive(const char *s)
return (unsigned)value;
}
template<size_t OPERAND>
static size_t
Multiply(size_t value)
template<std::size_t OPERAND>
static std::size_t
Multiply(std::size_t value)
{
static constexpr size_t MAX_VALUE = SIZE_MAX / OPERAND;
static constexpr std::size_t MAX_VALUE = SIZE_MAX / OPERAND;
if (value > MAX_VALUE)
throw std::runtime_error("Value too large");
return value * OPERAND;
}
size_t
ParseSize(const char *s, size_t default_factor)
std::size_t
ParseSize(const char *s, std::size_t default_factor)
{
char *endptr;
size_t value = strtoul(s, &endptr, 10);
std::size_t value = strtoul(s, &endptr, 10);
if (endptr == s)
throw std::runtime_error("Failed to parse integer");
static constexpr size_t KILO = 1024;
static constexpr size_t MEGA = 1024 * KILO;
static constexpr size_t GIGA = 1024 * MEGA;
static constexpr std::size_t KILO = 1024;
static constexpr std::size_t MEGA = 1024 * KILO;
static constexpr std::size_t GIGA = 1024 * MEGA;
s = StripLeft(endptr);
......
......@@ -51,7 +51,7 @@ ParsePositive(const char *s);
*
* Throws on error.
*/
size_t
ParseSize(const char *s, size_t default_factor=1);
std::size_t
ParseSize(const char *s, std::size_t default_factor=1);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment