lib45d
45Drives C++ Library Development Documentation
|
35 enum PrefixType { BINARY, SI };
41 Bytes(
const std::string &str);
82 bytes_ = std::move(other.bytes_);
105 std::string
get_str(
enum PrefixType prefix_type = BINARY,
int precision = 2)
const;
119 void set(
const std::string &str) {
141 std::getline(is, str);
154 return Bytes(a.get() + b.get());
157 return Bytes(a.get() - b.get());
159 friend Bytes operator*(
const Bytes &a,
int b) {
160 return Bytes(a.get() * b);
162 friend Bytes operator*(
int a,
const Bytes &b) {
165 friend Bytes operator/(
const Bytes &a,
int b) {
166 return Bytes(a.get() / b);
168 friend double operator/(
const Bytes &a,
const Bytes &b) {
169 return double(a.get()) / double(b.get());
171 friend bool operator==(
const Bytes &a,
const Bytes &b) {
172 return a.get() == b.get();
174 friend bool operator!=(
const Bytes &a,
const Bytes &b) {
175 return !(operator==(a, b));
177 friend bool operator<(
const Bytes &a,
const Bytes &b) {
178 return a.get() < b.get();
180 friend bool operator>(
const Bytes &a,
const Bytes &b) {
181 return b.get() < a.get();
183 friend bool operator<=(
const Bytes &a,
const Bytes &b) {
184 return !(operator>(a, b));
186 friend bool operator>=(
const Bytes &a,
const Bytes &b) {
187 return !(operator<(a, b));
Bytes & operator=(const Bytes &other)
Copy assignment.
Definition: Bytes.hpp:71
Bytes(bytes_type bytes)
Construct a new Bytes object from integral type.
Definition: Bytes.hpp:47
Bytes(const Bytes &other)
Copy construct a new Bytes object.
Definition: Bytes.hpp:58
Bytes & operator=(Bytes &&other)
Assignment move constructor.
Definition: Bytes.hpp:81
Use this class for byte-formatted values. e.g.: "123 KiB".
Definition: Bytes.hpp:32
bytes_type bytes_
The actual value.
Definition: Bytes.hpp:190
friend std::istream & operator>>(std::istream &is, Bytes &bytes)
Stream extraction operator.
Definition: Bytes.hpp:139
virtual bytes_type get(void) const
Get value in bytes.
Definition: Bytes.hpp:94
45Drives namespace
Definition: Bytes.hpp:27
off64_t bytes_type
Type to store number of bytes.
Definition: Bytes.hpp:34
std::string get_str(enum PrefixType prefix_type=BINARY, int precision=2) const
Get value as formatted string.
Definition: bytes.cpp:33
~Bytes()=default
Destroy the Bytes object.
bytes_type parse_bytes(const std::string &str) const
Parse bytes from string.
Definition: bytes.cpp:63
void set(bytes_type val)
Set value from integral type.
Definition: Bytes.hpp:111
void set(const std::string &str)
Set value from formatted string /\d+(.\d*)?\s*[kmgtpezy]?i?b/i.
Definition: Bytes.hpp:119
Bytes(void)
Construct a new empty Bytes object.
Definition: Bytes.hpp:52
Bytes(Bytes &&other)
Move constructor.
Definition: Bytes.hpp:64
friend std::ostream & operator<<(std::ostream &os, Bytes const &bytes)
Stream insertion operator.
Definition: Bytes.hpp:129