[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.
This commit is contained in:
Adriaan de Groot 2021-03-09 18:21:58 +01:00
parent 1ebb807624
commit ea63f48c31
3 changed files with 14 additions and 8 deletions

View File

@ -19,7 +19,7 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QMutexLocker> #include <QMutexLocker>
using CalamaresUtils::operator""_MiB; using namespace CalamaresUtils::Units;
namespace Calamares namespace Calamares
{ {

View File

@ -18,6 +18,9 @@
namespace CalamaresUtils namespace CalamaresUtils
{ {
namespace Units
{
/** User defined literals, 1_KB is 1 KiloByte (= 10^3 bytes) */ /** User defined literals, 1_KB is 1 KiloByte (= 10^3 bytes) */
constexpr qint64 operator""_KB( unsigned long long m ) 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; return operator""_MiB(m)*1024;
} }
}
constexpr qint64 constexpr qint64
KBtoBytes( unsigned long long m ) KBtoBytes( unsigned long long m )
{ {
return operator""_KB( m ); return Units::operator""_KB( m );
} }
constexpr qint64 constexpr qint64
KiBtoBytes( unsigned long long m ) KiBtoBytes( unsigned long long m )
{ {
return operator""_KiB( m ); return Units::operator""_KiB( m );
} }
constexpr qint64 constexpr qint64
MBtoBytes( unsigned long long m ) MBtoBytes( unsigned long long m )
{ {
return operator""_MB( m ); return Units::operator""_MB( m );
} }
constexpr qint64 constexpr qint64
MiBtoBytes( unsigned long long m ) MiBtoBytes( unsigned long long m )
{ {
return operator""_MiB( m ); return Units::operator""_MiB( m );
} }
constexpr qint64 constexpr qint64
GBtoBytes( unsigned long long m ) GBtoBytes( unsigned long long m )
{ {
return operator""_GB( m ); return Units::operator""_GB( m );
} }
constexpr qint64 constexpr qint64
GiBtoBytes( unsigned long long m ) GiBtoBytes( unsigned long long m )
{ {
return operator""_GiB( m ); return Units::operator""_GiB( m );
} }
constexpr qint64 constexpr qint64
@ -157,4 +162,5 @@ bytesToSectors( qint64 bytes, qint64 blocksize )
} }
} // namespace CalamaresUtils } // namespace CalamaresUtils
#endif #endif

View File

@ -18,7 +18,7 @@
#include <QFile> #include <QFile>
using CalamaresUtils::operator""_MiB; using namespace CalamaresUtils::Units;
QString QString
targetPrefix() targetPrefix()