13 #ifndef __STOUT_BYTES_HPP__ 14 #define __STOUT_BYTES_HPP__ 33 static constexpr uint64_t
BYTES = 1;
43 while (index < s.size()) {
44 if (isdigit(s[index])) {
47 }
else if (s[index] ==
'.') {
48 return Error(
"Fractional bytes '" + s +
"'");
61 }
else if (unit ==
"KB") {
63 }
else if (unit ==
"MB") {
65 }
else if (unit ==
"GB") {
67 }
else if (unit ==
"TB") {
70 return Error(
"Unknown bytes unit '" + unit +
"'");
73 return Error(
"Invalid bytes '" + s +
"'");
77 constexpr
Bytes(uint64_t _value, uint64_t _unit) : value(_value * _unit) {}
79 uint64_t
bytes()
const {
return value; }
144 if (bytes.
bytes() == 0) {
145 return stream <<
"0B";
147 return stream << bytes.
bytes() <<
"B";
179 result *= multiplier;
191 #endif // __STOUT_BYTES_HPP__ constexpr Bytes Terabytes(uint64_t value)
Definition: bytes.hpp:135
static constexpr uint64_t MEGABYTES
Definition: bytes.hpp:35
Bytes operator+(const Bytes &lhs, const Bytes &rhs)
Definition: bytes.hpp:160
Bytes & operator/=(uint64_t divisor)
Definition: bytes.hpp:106
Definition: errorbase.hpp:36
T & get()&
Definition: try.hpp:80
bool operator!=(const Bytes &that) const
Definition: bytes.hpp:86
constexpr Bytes Megabytes(uint64_t value)
Definition: bytes.hpp:123
Bytes operator*(const Bytes &lhs, uint64_t multiplier)
Definition: bytes.hpp:176
bool operator<(const Bytes &that) const
Definition: bytes.hpp:81
bool operator>(const Bytes &that) const
Definition: bytes.hpp:83
static Try< Bytes > parse(const std::string &s)
Definition: bytes.hpp:39
std::ostream & operator<<(std::ostream &stream, const Bytes &bytes)
Definition: bytes.hpp:141
static constexpr uint64_t GIGABYTES
Definition: bytes.hpp:36
bool operator==(const Bytes &that) const
Definition: bytes.hpp:85
Result< int > index(const std::string &link)
bool operator>=(const Bytes &that) const
Definition: bytes.hpp:84
Option< std::string > diff(const FrameworkInfo &left, const FrameworkInfo &right)
Bytes operator/(const Bytes &lhs, uint64_t divisor)
Definition: bytes.hpp:184
constexpr Bytes(uint64_t _value, uint64_t _unit)
Definition: bytes.hpp:77
Bytes & operator*=(uint64_t multiplier)
Definition: bytes.hpp:100
constexpr Bytes(uint64_t bytes=0)
Definition: bytes.hpp:76
static Try error(const E &e)
Definition: try.hpp:43
std::string upper(const std::string &s)
Definition: strings.hpp:437
bool isError() const
Definition: try.hpp:78
constexpr Bytes Gigabytes(uint64_t value)
Definition: bytes.hpp:129
uint64_t bytes() const
Definition: bytes.hpp:79
static constexpr uint64_t BYTES
Definition: bytes.hpp:33
Bytes operator-(const Bytes &lhs, const Bytes &rhs)
Definition: bytes.hpp:168
static constexpr uint64_t TERABYTES
Definition: bytes.hpp:37
constexpr Bytes Kilobytes(uint64_t value)
Definition: bytes.hpp:117
Bytes & operator+=(const Bytes &that)
Definition: bytes.hpp:88
bool operator<=(const Bytes &that) const
Definition: bytes.hpp:82
static constexpr uint64_t KILOBYTES
Definition: bytes.hpp:34
Bytes & operator-=(const Bytes &that)
Definition: bytes.hpp:94