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