fw4spl
fwMemory::ByteSize Class Reference

Conversion helper for size in bytes Converts string to number of bytes and vice-versa. This class is also able to manage conversions between units standards (IEC, SI) More...

#include <ByteSize.hpp>

+ Collaboration diagram for fwMemory::ByteSize:

Public Types

enum  StandardType { SI, IEC }
 
typedef std::uint64_t SizeType
 
typedef std::uint64_t UnitType
 

Public Member Functions

FWMEMORY_API ByteSize ()
 Default constructor.
 
FWMEMORY_API ByteSize (double size, UnitType unit=Bytes)
 Build a ByteSize object from given size and unit.
 
FWMEMORY_API ByteSize (const std::string &size)
 Build a ByteSize object from given string.
 
FWMEMORY_API std::string getSizeAsString (UnitType unit=Bytes)
 Convert this size to a string with specified unit. More...
 
FWMEMORY_API std::string getHumanReadableSize (StandardType standard=IEC)
 Convert this size to a human readable string in the required Convert this size to a human readable string in the required standard. The unit will be chosen to make the numeric value fit in [0; 1024[ when possible. More...
 
SizeType getSize ()
 Returns size in bytes.
 
FWMEMORY_API void setSize (double size, UnitType unit=Bytes)
 Build a ByteSize object from given size and unit.
 
FWMEMORY_API void setSize (const std::string &size)
 Build a ByteSize object from given string.
 
FWMEMORY_API ByteSizeoperator= (SizeType size)
 
FWMEMORY_API ByteSizeoperator= (double size)
 
FWMEMORY_API ByteSizeoperator= (const std::string &size)
 
template<typename T >
ByteSizeoperator= (T size)
 
 operator SizeType ()
 
 operator std::string ()
 
FWMEMORY_API ByteSize (SizeType size, UnitType unit=Bytes)
 Build a ByteSize object from given size and unit.
 
template<typename T >
 ByteSize (T size, UnitType unit=Bytes)
 Build a ByteSize object from given size and unit.
 
FWMEMORY_API void setSize (SizeType size, UnitType unit=Bytes)
 Build a ByteSize object from given size and unit.
 
template<typename T >
void setSize (T size, UnitType unit=Bytes)
 Build a ByteSize object from given size and unit.
 

Static Public Member Functions

static FWMEMORY_API bool parseSize (const std::string &s, std::uint64_t &size)
 
static FWMEMORY_API std::string unitToString (UnitType unit)
 

Static Public Attributes

static FWMEMORY_API const std::uint64_t Bytes = 1
 
static FWMEMORY_API const std::uint64_t KB = 1000LL
 
static FWMEMORY_API const std::uint64_t MB = 1000000LL
 
static FWMEMORY_API const std::uint64_t GB = 1000000000LL
 
static FWMEMORY_API const std::uint64_t TB = 1000000000000LL
 
static FWMEMORY_API const std::uint64_t PB = 1000000000000000LL
 
static FWMEMORY_API const std::uint64_t KiB = 1LL << 10
 
static FWMEMORY_API const std::uint64_t MiB = 1LL << 20
 
static FWMEMORY_API const std::uint64_t GiB = 1LL << 30
 
static FWMEMORY_API const std::uint64_t TiB = 1LL << 40
 
static FWMEMORY_API const std::uint64_t PiB = 1LL << 50
 

Protected Attributes

SizeType m_size
 

Detailed Description

Conversion helper for size in bytes Converts string to number of bytes and vice-versa. This class is also able to manage conversions between units standards (IEC, SI)

Definition at line 25 of file ByteSize.hpp.

Member Function Documentation

std::string fwMemory::ByteSize::getHumanReadableSize ( StandardType  standard = IEC)

Convert this size to a human readable string in the required Convert this size to a human readable string in the required standard. The unit will be chosen to make the numeric value fit in [0; 1024[ when possible.

Parameters
standardWanted set of unit
Returns
std::string representing the size

Definition at line 278 of file ByteSize.cpp.

References getSizeAsString().

+ Here is the call graph for this function:

std::string fwMemory::ByteSize::getSizeAsString ( UnitType  unit = Bytes)

Convert this size to a string with specified unit.

Parameters
unitUnit to convert this size to.
Returns
std::string representing the size

Definition at line 255 of file ByteSize.cpp.

References SLM_ASSERT.

Referenced by getHumanReadableSize().

+ Here is the caller graph for this function:


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