7 #ifndef __FWMEMORY_BYTESIZE_HPP__ 8 #define __FWMEMORY_BYTESIZE_HPP__ 10 #include "fwMemory/config.hpp" 12 #include <fwCore/base.hpp> 34 FWMEMORY_API
static const std::uint64_t Bytes;
37 FWMEMORY_API
static const std::uint64_t KB;
38 FWMEMORY_API
static const std::uint64_t MB;
39 FWMEMORY_API
static const std::uint64_t GB;
40 FWMEMORY_API
static const std::uint64_t TB;
41 FWMEMORY_API
static const std::uint64_t PB;
44 FWMEMORY_API
static const std::uint64_t KiB;
45 FWMEMORY_API
static const std::uint64_t MiB;
46 FWMEMORY_API
static const std::uint64_t GiB;
47 FWMEMORY_API
static const std::uint64_t TiB;
48 FWMEMORY_API
static const std::uint64_t PiB;
50 typedef std::uint64_t SizeType;
51 typedef std::uint64_t UnitType;
62 FWMEMORY_API ByteSize ( SizeType size, UnitType unit = Bytes );
67 this->setSize( SizeType(size), unit);
74 FWMEMORY_API ByteSize (
double size, UnitType unit = Bytes );
79 FWMEMORY_API ByteSize (
const std::string& size );
88 FWMEMORY_API std::string getSizeAsString( UnitType unit = Bytes );
99 FWMEMORY_API std::string getHumanReadableSize( StandardType standard = IEC );
113 FWMEMORY_API
void setSize( SizeType size, UnitType unit = Bytes );
116 template <
typename T>
119 this->setSize(SizeType(size), unit);
126 FWMEMORY_API
void setSize(
double size, UnitType unit = Bytes );
130 FWMEMORY_API
void setSize(
const std::string& size );
132 FWMEMORY_API ByteSize& operator= ( SizeType size );
133 FWMEMORY_API ByteSize& operator= (
double size );
134 FWMEMORY_API ByteSize& operator= (
const std::string& size );
137 template <
typename T>
138 ByteSize& operator= ( T size )
140 return this->operator=( SizeType(size) );
143 operator SizeType() {
146 operator std::string() {
147 return getHumanReadableSize();
150 FWMEMORY_API
static bool parseSize(
const std::string& s, std::uint64_t& size);
151 FWMEMORY_API
static std::string unitToString( UnitType unit );
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)
The namespace fwMemory contains tools to manage memory. Use for dump.
void setSize(T size, UnitType unit=Bytes)
Build a ByteSize object from given size and unit.
ByteSize(T size, UnitType unit=Bytes)
Build a ByteSize object from given size and unit.
SizeType getSize()
Returns size in bytes.