Mailinglist Archive: zypp-devel (66 mails)

< Previous Next >
[zypp-devel] Binary multiplication prefixes and zypp ByteCount
  • From: Jan Kupec <jkupec@xxxxxxx>
  • Date: Thu, 05 Feb 2009 16:02:23 +0100
  • Message-id: <498AFF7F.3060901@xxxxxxx>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

What about the attached diff to ByteCount.cc as part of fixing
https://bugzilla.novell.com/show_bug.cgi?id=471335 ?

Note the empty 'symbol' for Byte - this way users can just do:

ByteCount bytes;
cout << "Size: " << bytes << "B" << endl; // OR
cout << str::form("Size: %sB", bytes.asString(0,1,1)) << endl; //OR
cout << str::form("Size: %sbit", bytes.asString(0,1,1)) << endl; // etc.

to get

"Size: 13 B"
"Size: 13 KiB"
"Size: 13 MiB"
"Size: 13 Mibit"
(plus the decimal variants)

etc...

without need for

if (bytes.bestUnit().factor() == ByteCount::B.factor())
cout << str::form("Size: %s", bytes.asString(0,1,1));
else
cout << str::form("Size: %sB", bytes.asString(0,1,1));

- --
cheers,
jano


Ján Kupec
YaST team
- ---------------------------------------------------------(PGP)---
Key ID: 637EE901
Fingerprint: 93B9 C79B 2D20 51C3 800B E09B 8048 46A6 637E E901
- ---------------------------------------------------------(IRC)---
Server: irc.freenode.net
Nick: jniq
Channels: #zypp #yast #suse #susecz
- ---------------------------------------------------------(EOF)---
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAkmK/38ACgkQgEhGpmN+6QEyHQCfRNz+fo4ICWNlTlo1MSfM5LpF
fUQAn2L8yBOoItnFtHLCTNt8qU23v87L
=AjsE
-----END PGP SIGNATURE-----
diff --git a/zypp/ByteCount.cc b/zypp/ByteCount.cc
index f44cdcd..4ea8bc9 100644
--- a/zypp/ByteCount.cc
+++ b/zypp/ByteCount.cc
@@ -19,16 +19,16 @@ using std::endl;
namespace zypp
{ /////////////////////////////////////////////////////////////////

- const ByteCount::Unit ByteCount::B( 1LL, "B", 0 );
- const ByteCount::Unit ByteCount::K( 1024LL, "K", 1 );
- const ByteCount::Unit ByteCount::M( 1048576LL, "M", 1 );
- const ByteCount::Unit ByteCount::G( 1073741824LL, "G", 2 );
- const ByteCount::Unit ByteCount::T( 1099511627776LL, "T", 3 );
+ const ByteCount::Unit ByteCount::B( 1LL, "", 0 );
+ const ByteCount::Unit ByteCount::K( 1024LL, "Ki", 1 );
+ const ByteCount::Unit ByteCount::M( 1048576LL, "Mi", 1 );
+ const ByteCount::Unit ByteCount::G( 1073741824LL, "Gi", 2 );
+ const ByteCount::Unit ByteCount::T( 1099511627776LL, "Ti", 3 );

- const ByteCount::Unit ByteCount::kB( 1000LL, "kB", 1 );
- const ByteCount::Unit ByteCount::MB( 1000000LL, "MB", 1 );
- const ByteCount::Unit ByteCount::GB( 1000000000LL, "GB", 2 );
- const ByteCount::Unit ByteCount::TB( 1000000000000LL, "TB", 3 );
+ const ByteCount::Unit ByteCount::kB( 1000LL, "k", 1 );
+ const ByteCount::Unit ByteCount::MB( 1000000LL, "M", 1 );
+ const ByteCount::Unit ByteCount::GB( 1000000000LL, "G", 2 );
+ const ByteCount::Unit ByteCount::TB( 1000000000000LL, "T", 3 );

///////////////////////////////////////////////////////////////////
//
< Previous Next >