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
Try< Diff > diff(const std::string &from, const std::string &to)
Definition: svn.hpp:72
static constexpr uint64_t MEGABYTES
Definition: bytes.hpp:35
Bytes & operator/=(uint64_t divisor)
Definition: bytes.hpp:106
Definition: errorbase.hpp:35
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
Resources operator-(const google::protobuf::RepeatedPtrField< Resource > &left, const Resources &right)
Definition: resources.hpp:660
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
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:42
Resources operator+(const google::protobuf::RepeatedPtrField< Resource > &left, const Resources &right)
Definition: resources.hpp:652
std::string upper(const std::string &s)
Definition: strings.hpp:420
bool isError() const
Definition: try.hpp:71
std::ostream & operator<<(std::ostream &stream, const Call::Type &type)
Definition: agent.hpp:28
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
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
const T & get() const
Definition: try.hpp:73
static constexpr uint64_t KILOBYTES
Definition: bytes.hpp:34
Bytes & operator-=(const Bytes &that)
Definition: bytes.hpp:94