libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 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 00024 const ByteCount::Unit ByteCount::K( 1024LL, "KiB", 1 ); 00025 const ByteCount::Unit ByteCount::KiB( K ); 00026 const ByteCount::Unit ByteCount::M( 1048576LL, "MiB", 1 ); 00027 const ByteCount::Unit ByteCount::MiB( M ); 00028 const ByteCount::Unit ByteCount::G( 1073741824LL, "GiB", 2 ); 00029 const ByteCount::Unit ByteCount::GiB( G ); 00030 const ByteCount::Unit ByteCount::T( 1099511627776LL, "TiB", 3 ); 00031 const ByteCount::Unit ByteCount::TiB( T ); 00032 00033 const ByteCount::Unit ByteCount::kB( 1000LL, "kB", 1 ); 00034 const ByteCount::Unit ByteCount::MB( 1000000LL, "MB", 1 ); 00035 const ByteCount::Unit ByteCount::GB( 1000000000LL, "GB", 2 ); 00036 const ByteCount::Unit ByteCount::TB( 1000000000000LL, "TB", 3 ); 00037 00039 // 00040 // METHOD NAME : ByteCount::fillBlock 00041 // METHOD TYPE : ByteCount & 00042 // 00043 ByteCount & ByteCount::fillBlock( ByteCount blocksize_r ) 00044 { 00045 if ( _count && blocksize_r ) 00046 { 00047 SizeType diff = _count % blocksize_r; 00048 if ( diff ) 00049 { 00050 if ( _count > 0 ) 00051 { 00052 _count += blocksize_r; 00053 _count -= diff; 00054 } 00055 else 00056 { 00057 _count -= blocksize_r; 00058 _count += diff; 00059 } 00060 } 00061 } 00062 return *this; 00063 } 00064 00066 // 00067 // METHOD NAME : ByteCount::bestUnit 00068 // METHOD TYPE : ByteCount::Unit 00069 // 00070 const ByteCount::Unit & ByteCount::bestUnit() const 00071 { 00072 SizeType usize( _count < 0 ? -_count : _count ); 00073 if ( usize < K.factor() ) 00074 return B; 00075 if ( usize < M.factor() ) 00076 return K; 00077 if ( usize < G.factor() ) 00078 return M; 00079 if ( usize < T.factor() ) 00080 return G; 00081 return T; 00082 } 00083 00085 // 00086 // METHOD NAME : ByteCount::bestUnit1000 00087 // METHOD TYPE : ByteCount::Unit 00088 // 00089 const ByteCount::Unit & ByteCount::bestUnit1000() const 00090 { 00091 SizeType usize( _count < 0 ? -_count : _count ); 00092 if ( usize < kB.factor() ) 00093 return B; 00094 if ( usize < MB.factor() ) 00095 return kB; 00096 if ( usize < GB.factor() ) 00097 return MB; 00098 if ( usize < TB.factor() ) 00099 return GB; 00100 return TB; 00101 } 00102 00104 } // namespace zypp