lib45d
45Drives C++ Library Development Documentation
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ffd::Quota Class Reference

This class extends ffd::Bytes to specify percents of an amount of bytes. More...

#include <45d/Quota.hpp>

Inheritance diagram for ffd::Quota:
Inheritance graph
[legend]
Collaboration diagram for ffd::Quota:
Collaboration graph
[legend]

Public Types

enum  RoundingMethod { NEAREST, DOWN, UP }
 Rounding method enum. More...
 
- Public Types inherited from ffd::Bytes
enum  PrefixType { BINARY, SI }
 
typedef off64_t bytes_type
 Type to store number of bytes.
 

Public Member Functions

 Quota (const Bytes &max, const std::string &str, RoundingMethod method=NEAREST)
 Construct a new Quota object. More...
 
 Quota (const Bytes &max, double fraction=1.0, RoundingMethod method=NEAREST)
 Construct a new Quota object. More...
 
 Quota (const Bytes &max, const Bytes &allotted, RoundingMethod method=NEAREST)
 
 Quota (void)
 Construct a new empty Quota object. More...
 
 Quota (const Quota &other)
 Copy constructor. More...
 
 Quota (Quota &&other)
 Move constructor. More...
 
Quotaoperator= (const Quota &other)
 Copy assignment. More...
 
Quotaoperator= (Quota &&other)
 Assignment move constructor. More...
 
 ~Quota ()=default
 Destroy the Quota object.
 
void set_rounding_method (RoundingMethod method)
 
bytes_type get (void) const
 Get value in bytes equal to total bytes_ * fraction_. More...
 
bytes_type get_max (void) const
 Get the max number of bytes from parent. More...
 
double get_fraction (void) const
 Get just the fraction as a double. More...
 
void set_fraction (double fraction)
 Set the fraction. More...
 
void set_fraction (const std::string &str)
 Set fraction from formatted string /\d+(.\d*)?\s*%?/. More...
 
double parse_fraction (const std::string &str)
 Parse str from a percentage to a decimal fraction. More...
 
- Public Member Functions inherited from ffd::Bytes
 Bytes (const std::string &str)
 Construct a new Bytes object from formatted string. More...
 
 Bytes (bytes_type bytes)
 Construct a new Bytes object from integral type. More...
 
 Bytes (void)
 Construct a new empty Bytes object. More...
 
 Bytes (const Bytes &other)
 Copy construct a new Bytes object. More...
 
 Bytes (Bytes &&other)
 Move constructor. More...
 
Bytesoperator= (const Bytes &other)
 Copy assignment. More...
 
Bytesoperator= (Bytes &&other)
 Assignment move constructor. More...
 
 ~Bytes ()=default
 Destroy the Bytes object.
 
std::string get_str (enum PrefixType prefix_type=BINARY, int precision=2) const
 Get value as formatted string. More...
 
void set (bytes_type val)
 Set value from integral type. More...
 
void set (const std::string &str)
 Set value from formatted string /\d+(.\d*)?\s*[kmgtpezy]?i?b/i. More...
 
Bytesoperator+= (const Bytes &other)
 
Bytesoperator-= (const Bytes &other)
 

Private Member Functions

bytes_type round (double x) const
 Round a double according to rounding_method_, called by get() More...
 

Private Attributes

double fraction_
 The percent of bytes_ to report with get() and get_str()
 
RoundingMethod rounding_method_
 Rounding method to use when reporing bytes.
 

Additional Inherited Members

- Protected Member Functions inherited from ffd::Bytes
bytes_type parse_bytes (const std::string &str) const
 Parse bytes from string. More...
 
- Protected Attributes inherited from ffd::Bytes
bytes_type bytes_
 The actual value.
 

Detailed Description

This class extends ffd::Bytes to specify percents of an amount of bytes.

Member Enumeration Documentation

◆ RoundingMethod

Rounding method enum.

Enumerator
NEAREST 

Round to nearest whole byte.

DOWN 

Floor.

UP 

Ceiling.

Constructor & Destructor Documentation

◆ Quota() [1/5]

ffd::Quota::Quota ( const Bytes max,
const std::string &  str,
RoundingMethod  method = NEAREST 
)

Construct a new Quota object.

Parameters
maxBytes to set maximum amount
strString to be parsed into fraction

◆ Quota() [2/5]

ffd::Quota::Quota ( const Bytes max,
double  fraction = 1.0,
RoundingMethod  method = NEAREST 
)
inline

Construct a new Quota object.

Parameters
maxBytes to set maximum amount
fractionFraction of max to represent
methodRounding nearest, down, or up

◆ Quota() [3/5]

ffd::Quota::Quota ( void  )
inline

Construct a new empty Quota object.

◆ Quota() [4/5]

ffd::Quota::Quota ( const Quota other)
inline

Copy constructor.

Parameters
other

◆ Quota() [5/5]

ffd::Quota::Quota ( Quota &&  other)
inline

Move constructor.

Parameters
otherQuota to be moved

Member Function Documentation

◆ get()

bytes_type ffd::Quota::get ( void  ) const
inlinevirtual

Get value in bytes equal to total bytes_ * fraction_.

Returns
bytes_type

Reimplemented from ffd::Bytes.

◆ get_fraction()

double ffd::Quota::get_fraction ( void  ) const
inline

Get just the fraction as a double.

Returns
double

◆ get_max()

bytes_type ffd::Quota::get_max ( void  ) const
inline

Get the max number of bytes from parent.

Returns
bytes_type

◆ operator=() [1/2]

Quota& ffd::Quota::operator= ( const Quota other)
inline

Copy assignment.

Parameters
otherQuota to be copied
Returns
Quota& *this

◆ operator=() [2/2]

Quota& ffd::Quota::operator= ( Quota &&  other)
inline

Assignment move constructor.

Parameters
otherQuota to be moved
Returns
Quota& *this

◆ parse_fraction()

double ffd::Quota::parse_fraction ( const std::string &  str)

Parse str from a percentage to a decimal fraction.

Parameters
strString to parse
Returns
double Fraction to return

◆ round()

bytes_type ffd::Quota::round ( double  x) const
inlineprivate

Round a double according to rounding_method_, called by get()

Parameters
xThe number to round, most likely double(bytes_) * fraction_
Returns
bytes_type

◆ set_fraction() [1/2]

void ffd::Quota::set_fraction ( const std::string &  str)
inline

Set fraction from formatted string /\d+(.\d*)?\s*%?/.

Parameters
str

◆ set_fraction() [2/2]

void ffd::Quota::set_fraction ( double  fraction)
inline

Set the fraction.

Parameters
fractionnew value for fraction_

The documentation for this class was generated from the following files: