From ea63f48c315d2f9010272d747b4d028d7c5279a7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Mar 2021 18:21:58 +0100 Subject: [PATCH] [libcalamares] Put the units in a nested namespace - this makes it much easier to use the literal suffixes by using the namespace rather than individual operators. --- src/libcalamares/GlobalStorage.cpp | 2 +- src/libcalamares/utils/Units.h | 18 ++++++++++++------ src/modules/preservefiles/PreserveFiles.cpp | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/libcalamares/GlobalStorage.cpp b/src/libcalamares/GlobalStorage.cpp index 6cae46eeb..9f394e245 100644 --- a/src/libcalamares/GlobalStorage.cpp +++ b/src/libcalamares/GlobalStorage.cpp @@ -19,7 +19,7 @@ #include #include -using CalamaresUtils::operator""_MiB; +using namespace CalamaresUtils::Units; namespace Calamares { diff --git a/src/libcalamares/utils/Units.h b/src/libcalamares/utils/Units.h index abccacb0d..7a13dac10 100644 --- a/src/libcalamares/utils/Units.h +++ b/src/libcalamares/utils/Units.h @@ -18,6 +18,9 @@ namespace CalamaresUtils { +namespace Units +{ + /** User defined literals, 1_KB is 1 KiloByte (= 10^3 bytes) */ constexpr qint64 operator""_KB( unsigned long long m ) { @@ -54,40 +57,42 @@ constexpr qint64 operator""_GiB( unsigned long long m ) return operator""_MiB(m)*1024; } +} + constexpr qint64 KBtoBytes( unsigned long long m ) { - return operator""_KB( m ); + return Units::operator""_KB( m ); } constexpr qint64 KiBtoBytes( unsigned long long m ) { - return operator""_KiB( m ); + return Units::operator""_KiB( m ); } constexpr qint64 MBtoBytes( unsigned long long m ) { - return operator""_MB( m ); + return Units::operator""_MB( m ); } constexpr qint64 MiBtoBytes( unsigned long long m ) { - return operator""_MiB( m ); + return Units::operator""_MiB( m ); } constexpr qint64 GBtoBytes( unsigned long long m ) { - return operator""_GB( m ); + return Units::operator""_GB( m ); } constexpr qint64 GiBtoBytes( unsigned long long m ) { - return operator""_GiB( m ); + return Units::operator""_GiB( m ); } constexpr qint64 @@ -157,4 +162,5 @@ bytesToSectors( qint64 bytes, qint64 blocksize ) } } // namespace CalamaresUtils + #endif diff --git a/src/modules/preservefiles/PreserveFiles.cpp b/src/modules/preservefiles/PreserveFiles.cpp index 64770adce..b235aac93 100644 --- a/src/modules/preservefiles/PreserveFiles.cpp +++ b/src/modules/preservefiles/PreserveFiles.cpp @@ -18,7 +18,7 @@ #include -using CalamaresUtils::operator""_MiB; +using namespace CalamaresUtils::Units; QString targetPrefix()