lib45d
45Drives C++ Library API Documentation
|
23 #include <45d/Bytes.hpp>
58 , rounding_method_(method) {}
61 , fraction_(allotted / max)
62 , rounding_method_(method) {}
75 , fraction_(other.fraction_)
76 , rounding_method_(other.rounding_method_) {}
83 :
Bytes(std::move(other))
84 , fraction_(std::move(other.fraction_))
85 , rounding_method_(std::move(other.rounding_method_)) {}
94 fraction_ = other.fraction_;
95 rounding_method_ = other.rounding_method_;
105 bytes_ = std::move(other.bytes_);
106 fraction_ = std::move(other.fraction_);
107 rounding_method_ = std::move(other.rounding_method_);
115 rounding_method_ = method;
123 return round(
double(
bytes_) * fraction_);
147 fraction_ = fraction;
174 switch (rounding_method_) {
175 case RoundingMethod::NEAREST:
177 case RoundingMethod::DOWN:
179 case RoundingMethod::UP:
void set_fraction(double fraction)
Set the fraction.
Definition: Quota.hpp:146
Quota(Quota &&other)
Move constructor.
Definition: Quota.hpp:82
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
bytes_type get_max(void) const
Get the max number of bytes from parent.
Definition: Quota.hpp:130
bytes_type get(void) const
Get value in bytes equal to total bytes_ * fraction_.
Definition: Quota.hpp:122
This class extends ffd::Bytes to specify percents of an amount of bytes.
Definition: Quota.hpp:30
Quota(const Quota &other)
Copy constructor.
Definition: Quota.hpp:73
Quota & operator=(const Quota &other)
Copy assignment.
Definition: Quota.hpp:92
@ NEAREST
Round to nearest whole byte.
Definition: Quota.hpp:37
45Drives namespace
Definition: Bytes.hpp:27
off64_t bytes_type
Type to store number of bytes.
Definition: Bytes.hpp:34
double parse_fraction(const std::string &str)
Parse str from a percentage to a decimal fraction.
Definition: quota.cpp:33
~Quota()=default
Destroy the Quota object.
@ DOWN
Floor.
Definition: Quota.hpp:38
@ UP
Ceiling.
Definition: Quota.hpp:39
Quota(void)
Construct a new empty Quota object.
Definition: Quota.hpp:67
Quota & operator=(Quota &&other)
Assignment move constructor.
Definition: Quota.hpp:104
Quota(const Bytes &max, double fraction=1.0, RoundingMethod method=NEAREST)
Construct a new Quota object.
Definition: Quota.hpp:55
double get_fraction(void) const
Get just the fraction as a double.
Definition: Quota.hpp:138
void set_fraction(const std::string &str)
Set fraction from formatted string /\d+(.\d*)?\s*%?/.
Definition: Quota.hpp:154
RoundingMethod
Rounding method enum.
Definition: Quota.hpp:36