35 : _size( atoll( sizeStr.c_str() ) * factor( unit_r ) )
48 if ( _size && blocksize_r ) {
49 long long diff = _size % blocksize_r;
68 long long usize( _size < 0 ? -_size : _size );
87 std::string
FSize::form(
const Unit unit_r,
unsigned fw,
unsigned prec,
const bool showunit )
const 92 case T: prec = 3;
break;
93 case G: prec = 2;
break;
94 case M: prec = 1;
break;
95 case K: prec = 1;
break;
96 case B: prec = 0;
break;
98 }
else if ( unit_r == B )
102 snprintf( buffer,
sizeof( buffer ),
104 fw, prec, (
double( _size ) /
factor( unit_r ) ) );
106 std::string ret( buffer );
109 ret += std::string(
" ") +
unit( unit_r );
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).
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.