libzypp: zypp-core/ByteCount.cc Source File

libzypp 17.38.13

ByteCount.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13
14#include <zypp-core/ByteCount.h>
15
16using std::endl;
17
19namespace zypp
20{
21
22 const ByteCount::Unit ByteCount::B( 1LL, "B", 0 );
23
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 );
32
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 );
37
39 //
40 // METHOD NAME : ByteCount::fillBlock
41 // METHOD TYPE : ByteCount &
42 //
43 ByteCount & ByteCount::fillBlock( ByteCount blocksize_r )
44 {
45 if ( _count && blocksize_r )
46 {
47 SizeType diff = _count % blocksize_r;
48 if ( diff )
49 {
50 if ( _count > 0 )
51 {
52 _count += blocksize_r;
53 _count -= diff;
54 }
55 else
56 {
57 _count -= blocksize_r;
58 _count += diff;
59 }
60 }
61 }
62 return *this;
63 }
64
66 //
67 // METHOD NAME : ByteCount::bestUnit
68 // METHOD TYPE : ByteCount::Unit
69 //
70 const ByteCount::Unit & ByteCount::bestUnit() const
71 {
72 SizeType usize( _count < 0 ? -_count : _count );
73 if ( usize < K.factor() )
74 return B;
75 if ( usize < M.factor() )
76 return K;
77 if ( usize < G.factor() )
78 return M;
79 if ( usize < T.factor() )
80 return G;
81 return T;
82 }
83
85 //
86 // METHOD NAME : ByteCount::bestUnit1000
87 // METHOD TYPE : ByteCount::Unit
88 //
89 const ByteCount::Unit & ByteCount::bestUnit1000() const
90 {
91 SizeType usize( _count < 0 ? -_count : _count );
92 if ( usize < kB.factor() )
93 return B;
94 if ( usize < MB.factor() )
95 return kB;
96 if ( usize < GB.factor() )
97 return MB;
98 if ( usize < TB.factor() )
99 return GB;
100 return TB;
101 }
102
104} // namespace zypp
ByteCount.h
zypp::ByteCount::MiB
static const Unit MiB
Definition ByteCount.h:50
zypp::ByteCount::MB
static const Unit MB
1000^2 Byte
Definition ByteCount.h:61
zypp::ByteCount::TiB
static const Unit TiB
Definition ByteCount.h:56
zypp::ByteCount::G
static const Unit G
1024^3 Byte
Definition ByteCount.h:52
zypp::ByteCount::bestUnit1000
const Unit & bestUnit1000() const
Return the best Unit (B,kB,MB,GB,TB) for count.
Definition ByteCount.cc:89
zypp::ByteCount::ByteCount
ByteCount()
Default ctor.
Definition ByteCount.h:71
zypp::ByteCount::Unit
base::Unit Unit
Definition ByteCount.h:37
zypp::ByteCount::kB
static const Unit kB
1000 Byte
Definition ByteCount.h:59
zypp::ByteCount::fillBlock
ByteCount & fillBlock(ByteCount blocksize_r=K)
Adjust count to multiple of blocksize_r (default 1K).
Definition ByteCount.cc:43
zypp::ByteCount::bestUnit
const Unit & bestUnit() const
Return the best Unit (B,K,M,G,T) for count.
Definition ByteCount.cc:70
zypp::ByteCount::K
static const Unit K
1024 Byte
Definition ByteCount.h:46
zypp::ByteCount::TB
static const Unit TB
1000^4 Byte
Definition ByteCount.h:65
zypp::ByteCount::SizeType
Unit::ValueType SizeType
Definition ByteCount.h:38
zypp::ByteCount::B
static const Unit B
1 Byte
Definition ByteCount.h:43
zypp::ByteCount::KiB
static const Unit KiB
Definition ByteCount.h:47
zypp::ByteCount::GiB
static const Unit GiB
Definition ByteCount.h:53
zypp::ByteCount::M
static const Unit M
1024^2 Byte
Definition ByteCount.h:49
zypp::ByteCount::GB
static const Unit GB
1000^3 Byte
Definition ByteCount.h:63
zypp::ByteCount::_count
SizeType _count
Definition ByteCount.h:156
zypp::ByteCount::T
static const Unit T
1024^4 Byte
Definition ByteCount.h:55
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2