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 
42  const unsigned long long B = 1;
43 
49  const unsigned long long KiB = 1024 * B;
50 
56  const unsigned long long MiB = 1024 * KiB;
57 
63  const unsigned long long GiB = 1024 * MiB;
64 
70  const unsigned long long TiB = 1024 * GiB;
71 
77  const unsigned long long PiB = 1024 * TiB;
78 
84  const unsigned long long EiB = 1024 * PiB;
85 
86 
92  int num_suffixes();
93 
94 
102  std::string get_suffix(int i, bool classic);
103 
104 
116  std::string byte_to_humanstring(unsigned long long size, bool classic, int precision,
117  bool omit_zeroes);
118 
133  unsigned long long humanstring_to_byte(const std::string& str, bool classic);
134 
135 }
136 
137 
138 #endif
const unsigned long long EiB
Abbreviation for exbibyte.
Definition: HumanString.h:84
const unsigned long long MiB
Abbreviation for mebibyte.
Definition: HumanString.h:56
const unsigned long long GiB
Abbreviation for gibibyte.
Definition: HumanString.h:63
const unsigned long long TiB
Abbreviation for tebibyte.
Definition: HumanString.h:70
const unsigned long long PiB
Abbreviation for pebibyte.
Definition: HumanString.h:77
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.
const unsigned long long B
Abbreviation for byte.
Definition: HumanString.h:42
int num_suffixes()
Return number of suffixes.
const unsigned long long KiB
Abbreviation for kibibyte.
Definition: HumanString.h:49
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:39