ByteCount.cc

Go to the documentation of this file.
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   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   //    METHOD NAME : ByteCount::fillBlock
00036   //    METHOD TYPE : ByteCount &
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   //    METHOD NAME : ByteCount::bestUnit
00063   //    METHOD TYPE : ByteCount::Unit
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   //    METHOD NAME : ByteCount::bestUnit1000
00082   //    METHOD TYPE : ByteCount::Unit
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 } // namespace zypp

Generated on Thu Jul 6 00:07:20 2006 for zypp by  doxygen 1.4.6