libstorage-ng
HumanString.h
1 /*
2  * Copyright (c) [2004-2014] Novell, Inc.
3  * Copyright (c) 2016 SUSE LLC
4  *
5  * All Rights Reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of version 2 of the GNU General Public License as published
9  * by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, contact Novell, Inc.
18  *
19  * To contact Novell about this file by physical or electronic mail, you may
20  * find current contact information at www.novell.com.
21  */
22 
23 
24 #ifndef STORAGE_HUMAN_STRING_H
25 #define STORAGE_HUMAN_STRING_H
26 
27 
28 #include <string>
29 
30 
31 namespace storage
32 {
33 
34  // TODO use C++11 user-defined literals? Swig has some support for them.
35 
36  const unsigned long long B = 1;
37  const unsigned long long KiB = 1024 * B;
38  const unsigned long long MiB = 1024 * KiB;
39  const unsigned long long GiB = 1024 * MiB;
40  const unsigned long long TiB = 1024 * GiB;
41  const unsigned long long PiB = 1024 * TiB;
42  const unsigned long long EiB = 1024 * PiB;
43 
44 
50  int num_suffixes();
51 
59  std::string get_suffix(int i, bool classic);
60 
61 
73  std::string byte_to_humanstring(unsigned long long size, bool classic, int precision,
74  bool omit_zeroes);
75 
90  unsigned long long humanstring_to_byte(const std::string& str, bool classic);
91 
92 }
93 
94 
95 #endif
unsigned long long humanstring_to_byte(const std::string &str, bool classic)
Converts a size description using B, KiB, KB, MiB, MB, GiB, GB, TiB, TB, PiB, PB, EiB or EB into an i...
std::string get_suffix(int i, bool classic)
Return a suffix.
int num_suffixes()
Return number of suffixes.
std::string byte_to_humanstring(unsigned long long size, bool classic, int precision, bool omit_zeroes)
Return a pretty description of a size with required precision and using B, KiB, MiB, GiB, TiB, PiB or EiB as unit as appropriate.
The storage namespace.
Definition: Actiongraph.h:37