lib45d
45Drives C++ Library API Documentation
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ffd::Bytes Class Reference

Use this class for byte-formatted values. e.g.: "123 KiB". More...

#include <45d/Bytes.hpp>

Inheritance diagram for ffd::Bytes:
Inheritance graph
[legend]

Public Types

enum  PrefixType { BINARY, SI }
 
typedef off64_t bytes_type
 Type to store number of bytes.
 

Public Member Functions

 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.
 
virtual bytes_type get (void) const
 Get value in bytes. More...
 
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)
 

Protected Member Functions

bytes_type parse_bytes (const std::string &str) const
 Parse bytes from string. More...
 

Protected Attributes

bytes_type bytes_
 The actual value.
 

Friends

std::ostream & operator<< (std::ostream &os, Bytes const &bytes)
 Stream insertion operator. More...
 
std::istream & operator>> (std::istream &is, Bytes &bytes)
 Stream extraction operator. More...
 
Bytes operator+ (const Bytes &a, const Bytes &b)
 
Bytes operator- (const Bytes &a, const Bytes &b)
 
Bytes operator* (const Bytes &a, int b)
 
Bytes operator* (int a, const Bytes &b)
 
Bytes operator/ (const Bytes &a, int b)
 
double operator/ (const Bytes &a, const Bytes &b)
 
bool operator== (const Bytes &a, const Bytes &b)
 
bool operator!= (const Bytes &a, const Bytes &b)
 
bool operator< (const Bytes &a, const Bytes &b)
 
bool operator> (const Bytes &a, const Bytes &b)
 
bool operator<= (const Bytes &a, const Bytes &b)
 
bool operator>= (const Bytes &a, const Bytes &b)
 

Detailed Description

Use this class for byte-formatted values. e.g.: "123 KiB".

Constructor & Destructor Documentation

◆ Bytes() [1/5]

ffd::Bytes::Bytes ( const std::string &  str)

Construct a new Bytes object from formatted string.

Parameters
strformatted string for bytes

◆ Bytes() [2/5]

ffd::Bytes::Bytes ( bytes_type  bytes)
inline

Construct a new Bytes object from integral type.

Parameters
bytes

◆ Bytes() [3/5]

ffd::Bytes::Bytes ( void  )
inline

Construct a new empty Bytes object.

◆ Bytes() [4/5]

ffd::Bytes::Bytes ( const Bytes other)
inline

Copy construct a new Bytes object.

Parameters
otherBytes to be copied

◆ Bytes() [5/5]

ffd::Bytes::Bytes ( Bytes &&  other)
inline

Move constructor.

Parameters
otherBytes to be moved

Member Function Documentation

◆ get()

virtual bytes_type ffd::Bytes::get ( void  ) const
inlinevirtual

Get value in bytes.

Returns
bytes_type

Reimplemented in ffd::Quota.

◆ get_str()

std::string ffd::Bytes::get_str ( enum PrefixType  prefix_type = BINARY,
int  precision = 2 
) const

Get value as formatted string.

Parameters
prefix_typeffd::Bytes::PrefixType::BINARY for multiples of 1024, ffd::Bytes::PrefixType::SI for multiples of 1000.
Returns
std::string

◆ operator=() [1/2]

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

Assignment move constructor.

Parameters
otherBytes to be moved
Returns
Bytes& *this

◆ operator=() [2/2]

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

Copy assignment.

Parameters
otherBytes to be copied
Returns
Bytes& *this

◆ parse_bytes()

ffd::Bytes::bytes_type ffd::Bytes::parse_bytes ( const std::string &  str) const
protected

Parse bytes from string.

Parameters
strString to parse
Returns
bytes_type Bytes to return

◆ set() [1/2]

void ffd::Bytes::set ( bytes_type  val)
inline

Set value from integral type.

Parameters
val

◆ set() [2/2]

void ffd::Bytes::set ( const std::string &  str)
inline

Set value from formatted string /\d+(.\d*)?\s*[kmgtpezy]?i?b/i.

Parameters
str

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
Bytes const &  bytes 
)
friend

Stream insertion operator.

Parameters
os
bytes
Returns
std::ostream&

◆ operator>>

std::istream& operator>> ( std::istream &  is,
Bytes bytes 
)
friend

Stream extraction operator.

Parameters
is
bytes
Returns
std::istream&

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