ByteCount Class Reference

A class to handle parsing + converting byte counts. More...

#include <Util/ByteCount.H>

List of all members.

Public Member Functions

 ByteCount (size_t nbytes=0)
 Construct with a number of bytes.
 ByteCount (const std::string &str)
 Construct by parsing a string: format is "<float>[<B|KiB|MiB|GiB>]".
std::string prettyPrint () const
 Return a pretty-printed string using the highest possible suffix.
size_t bytes () const
 number of bytes represented
double kibibytes () const
 Returns bytes()/1024.0.
double mebibytes () const
 Returns bytes()/(1024.0*1024.0).
double gibibytes () const
 Returns bytes()/(1024.0*1024.0*1024.0).
size_t B () const
 synonym for bytes()
double KiB () const
 synonym for kibibytes()
double MiB () const
 synonym for mebibytes()
double GiB () const
 synonym for gibibytes()
bool operator== (const ByteCount &that) const
 Equality operator.
bool operator!= (const ByteCount &that) const
 Inequality operator.

Detailed Description

A class to handle parsing + converting byte counts.

Definition at line 48 of file ByteCount.H.


Constructor & Destructor Documentation

ByteCount::ByteCount ( size_t  nbytes = 0  )  [inline]

Construct with a number of bytes.

Definition at line 52 of file ByteCount.H.

ByteCount::ByteCount ( const std::string str  ) 

Construct by parsing a string: format is "<float>[<B|KiB|MiB|GiB>]".

If there is no suffix, we assume that the value is a literal byte count. Otherwise, the suffix can be B, KiB, MiB, GiB to specify a multiplier of 1, 2^10, 2^20, or 2^30, respectively.

Definition at line 48 of file ByteCount.C.

References prettyPrint(), and sformat().


Member Function Documentation

size_t ByteCount::B (  )  const [inline]

synonym for bytes()

Definition at line 95 of file ByteCount.H.

References bytes().

size_t ByteCount::bytes (  )  const [inline]

number of bytes represented

Definition at line 71 of file ByteCount.H.

Referenced by B(), and convertToString().

double ByteCount::GiB (  )  const [inline]

synonym for gibibytes()

Definition at line 104 of file ByteCount.H.

References gibibytes().

double ByteCount::gibibytes (  )  const [inline]

Returns bytes()/(1024.0*1024.0*1024.0).

To avoid confusion we use gibibytes (GiB) instead of gigabytes, since 'giga' strictly means 10^9 but is often also used to refer to 2^30. On the other hand, 'gibi' unequivocally refers to 2^30.

Definition at line 92 of file ByteCount.H.

Referenced by GiB().

double ByteCount::KiB (  )  const [inline]

synonym for kibibytes()

Definition at line 98 of file ByteCount.H.

References kibibytes().

double ByteCount::kibibytes (  )  const [inline]

Returns bytes()/1024.0.

To avoid confusion we use kibibytes (KiB) instead of kilobytes, since 'kilo' strictly means 10^3 but is often also used to refer to 2^10. On the other hand, 'kibi' unequivocally refers to 2^10.

Definition at line 78 of file ByteCount.H.

Referenced by KiB().

double ByteCount::mebibytes (  )  const [inline]

Returns bytes()/(1024.0*1024.0).

To avoid confusion we use mebibytes (MiB) instead of megabytes, since 'mega' strictly means 10^6 but is often also used to refer to 2^20. On the other hand, 'mebi' unequivocally refers to 2^20.

Definition at line 85 of file ByteCount.H.

Referenced by MiB().

double ByteCount::MiB (  )  const [inline]

synonym for mebibytes()

Definition at line 101 of file ByteCount.H.

References mebibytes().

bool ByteCount::operator!= ( const ByteCount that  )  const [inline]

Inequality operator.

Definition at line 111 of file ByteCount.H.

bool ByteCount::operator== ( const ByteCount that  )  const [inline]

Equality operator.

Definition at line 107 of file ByteCount.H.

std::string ByteCount::prettyPrint (  )  const

Return a pretty-printed string using the highest possible suffix.

NOTE that if you convert to string using prettyPrint() and then rescan that string back into a ByteCount, there will almost certainly be inaccuracy due to floating point roundoff.

Definition at line 110 of file ByteCount.C.

References sformat().

Referenced by ByteCount().


The documentation for this class was generated from the following files:
Generated on Sun May 8 08:43:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3