source: calamares/trunk/fuentes/src/libcalamares/utils/Units.h @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 1.7 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
4 *
5 *   Calamares is free software: you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation, either version 3 of the License, or
8 *   (at your option) any later version.
9 *
10 *   Calamares is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef LIBCALAMARES_UTILS_UNITS_H
20#define LIBCALAMARES_UTILS_UNITS_H
21
22#include <QtCore/QIntegerForSize>
23
24namespace CalamaresUtils
25{
26
27/** User defined literals, 1_MiB is 1 MibiByte (= 2^20 bytes) */
28constexpr qint64 operator ""_MiB( unsigned long long m )
29{
30    return qint64(m) * 1024 * 1024;
31}
32
33/** User defined literals, 1_GiB is 1 GibiByte (= 2^30 bytes) */
34constexpr qint64 operator ""_GiB( unsigned long long m )
35{
36    return operator ""_MiB(m) * 1024;
37}
38
39constexpr qint64 MiBtoBytes( unsigned long long m )
40{
41    return operator ""_MiB( m );
42}
43
44constexpr qint64 GiBtoBytes( unsigned long long m )
45{
46    return operator ""_GiB( m );
47}
48
49constexpr qint64 MiBToBytes( double m )
50{
51    return qint64(m * 1024 * 1024);
52}
53
54constexpr qint64 GiBtoBytes( double m )
55{
56    return qint64(m * 1024 * 1024 * 1024);
57}
58
59constexpr int BytesToMiB( qint64 b )
60{
61    return int( b / 1024 / 1024 );
62}
63
64}  // namespace
65#endif
Note: See TracBrowser for help on using the repository browser.