1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/ByteCount.cc
14 #include "zypp/ByteCount.h"
18 ///////////////////////////////////////////////////////////////////
20 { /////////////////////////////////////////////////////////////////
22 const ByteCount::Unit ByteCount::B( 1LL, "B", 0 );
23 const ByteCount::Unit ByteCount::K( 1024LL, "KiB", 1 );
24 const ByteCount::Unit ByteCount::M( 1048576LL, "MiB", 1 );
25 const ByteCount::Unit ByteCount::G( 1073741824LL, "GiB", 2 );
26 const ByteCount::Unit ByteCount::T( 1099511627776LL, "TiB", 3 );
28 const ByteCount::Unit ByteCount::kB( 1000LL, "kB", 1 );
29 const ByteCount::Unit ByteCount::MB( 1000000LL, "MB", 1 );
30 const ByteCount::Unit ByteCount::GB( 1000000000LL, "GB", 2 );
31 const ByteCount::Unit ByteCount::TB( 1000000000000LL, "TB", 3 );
33 ///////////////////////////////////////////////////////////////////
35 // METHOD NAME : ByteCount::fillBlock
36 // METHOD TYPE : ByteCount &
38 ByteCount & ByteCount::fillBlock( ByteCount blocksize_r )
40 if ( _count && blocksize_r )
42 SizeType diff = _count % blocksize_r;
47 _count += blocksize_r;
52 _count -= blocksize_r;
60 ///////////////////////////////////////////////////////////////////
62 // METHOD NAME : ByteCount::bestUnit
63 // METHOD TYPE : ByteCount::Unit
65 const ByteCount::Unit & ByteCount::bestUnit() const
67 SizeType usize( _count < 0 ? -_count : _count );
68 if ( usize < K.factor() )
70 if ( usize < M.factor() )
72 if ( usize < G.factor() )
74 if ( usize < T.factor() )
79 ///////////////////////////////////////////////////////////////////
81 // METHOD NAME : ByteCount::bestUnit1000
82 // METHOD TYPE : ByteCount::Unit
84 const ByteCount::Unit & ByteCount::bestUnit1000() const
86 SizeType usize( _count < 0 ? -_count : _count );
87 if ( usize < kB.factor() )
89 if ( usize < MB.factor() )
91 if ( usize < GB.factor() )
93 if ( usize < TB.factor() )
98 /////////////////////////////////////////////////////////////////
100 ///////////////////////////////////////////////////////////////////