00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013
00014 #include "zypp/ByteCount.h"
00015
00016 using std::endl;
00017
00019 namespace zypp
00020 {
00021
00022 const ByteCount::Unit ByteCount::B( 1LL, "B", 0 );
00023 const ByteCount::Unit ByteCount::K( 1024LL, "K", 1 );
00024 const ByteCount::Unit ByteCount::M( 1048576LL, "M", 1 );
00025 const ByteCount::Unit ByteCount::G( 1073741824LL, "G", 2 );
00026 const ByteCount::Unit ByteCount::T( 1099511627776LL, "T", 3 );
00027
00028 const ByteCount::Unit ByteCount::kB( 1000LL, "kB", 1 );
00029 const ByteCount::Unit ByteCount::MB( 1000000LL, "MB", 1 );
00030 const ByteCount::Unit ByteCount::GB( 1000000000LL, "GB", 2 );
00031 const ByteCount::Unit ByteCount::TB( 1000000000000LL, "TB", 3 );
00032
00034
00035
00036
00037
00038 ByteCount & ByteCount::fillBlock( ByteCount blocksize_r )
00039 {
00040 if ( _count && blocksize_r )
00041 {
00042 SizeType diff = _count % blocksize_r;
00043 if ( diff )
00044 {
00045 if ( _count > 0 )
00046 {
00047 _count += blocksize_r;
00048 _count -= diff;
00049 }
00050 else
00051 {
00052 _count -= blocksize_r;
00053 _count += diff;
00054 }
00055 }
00056 }
00057 return *this;
00058 }
00059
00061
00062
00063
00064
00065 const ByteCount::Unit & ByteCount::bestUnit() const
00066 {
00067 SizeType usize( _count < 0 ? -_count : _count );
00068 if ( usize < K.factor() )
00069 return B;
00070 if ( usize < M.factor() )
00071 return K;
00072 if ( usize < G.factor() )
00073 return M;
00074 if ( usize < T.factor() )
00075 return G;
00076 return T;
00077 }
00078
00080
00081
00082
00083
00084 const ByteCount::Unit & ByteCount::bestUnit1000() const
00085 {
00086 SizeType usize( _count < 0 ? -_count : _count );
00087 if ( usize < kB.factor() )
00088 return B;
00089 if ( usize < MB.factor() )
00090 return kB;
00091 if ( usize < GB.factor() )
00092 return MB;
00093 if ( usize < TB.factor() )
00094 return GB;
00095 return TB;
00096 }
00097
00099 }