46 enum Unit { B = 0, K, M, G, T };
57 static const long long KB = 1024;
58 static const long long MB = 1024 * KB;
59 static const long long GB = 1024 * MB;
60 static const long long TB = 1024 * GB;
79 static const char *
unit(
const Unit unit_r ) {
95 FSize(
const long long size_r = 0 )
104 : _size( size_r *
factor( unit_r ) )
110 FSize(
const std::string &sizeStr,
const Unit unit_r = B );
115 operator long long()
const {
return _size; }
117 FSize & operator+=(
const long long rhs ) { _size += rhs;
return *
this; }
118 FSize & operator-=(
const long long rhs ) { _size -= rhs;
return *
this; }
119 FSize & operator*=(
const long long rhs ) { _size *= rhs;
return *
this; }
120 FSize & operator/=(
const long long rhs ) { _size /= rhs;
return *
this; }
122 FSize & operator++() { _size += 1;
return *
this; }
123 FSize & operator--() { _size -= 1;
return *
this; }
125 FSize operator++(
int) {
return _size++; }
126 FSize operator--(
int) {
return _size--; }
164 std::string
form(
const Unit unit_r,
unsigned fw = 0,
unsigned prec = bestPrec,
const bool showunit =
true )
const;
169 std::string
form(
unsigned fw = 0,
unsigned prec = bestPrec,
const bool showunit =
true )
const {
static long long factor(const Unit unit_r)
Return ammount of Byte in Unit.
static const char * unit(const Unit unit_r)
String representation of Unit.
std::string asString() const
Default string representation (precision 1 and unit appended).
FSize fullBlock(FSize blocksize_r=KB) const
Return size adjusted to multiple of blocksize_r
std::string form(unsigned fw=0, unsigned prec=bestPrec, const bool showunit=true) const
Return string representation in bestUnit.
FSize(const long long size_r, const Unit unit_r)
Construct from size in certain unit.
Store and operate on (file/package/partition) sizes (long long).
FSize(const long long size_r=0)
Construct from size in Byte.
FSize & fillBlock(FSize blocksize_r=KB)
Adjust size to multiple of blocksize_r
static const unsigned bestPrec
Used as precision argument to form(), the 'best' precision according to Unist is chosen.
std::string form(const Unit unit_r, unsigned fw=0, unsigned prec=bestPrec, const bool showunit=true) const
Return string representation in given Unit.
Unit bestUnit() const
Return the best unit for string representation.
long long operator()(const Unit unit_r) const
Return size in Unit ( not rounded )