Merge pull request #1221 from a-wai/add-base-10-sizes

Add 'base 10' partition size multiples
main
Adriaan de Groot 5 years ago committed by GitHub
commit 09a36cd669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,7 +33,8 @@ unitSuffixes()
{ QStringLiteral( "%" ), SizeUnit::Percent }, { QStringLiteral( "K" ), SizeUnit::KiB },
{ QStringLiteral( "KiB" ), SizeUnit::KiB }, { QStringLiteral( "M" ), SizeUnit::MiB },
{ QStringLiteral( "MiB" ), SizeUnit::MiB }, { QStringLiteral( "G" ), SizeUnit::GiB },
{ QStringLiteral( "GiB" ), SizeUnit::GiB }
{ QStringLiteral( "GiB" ), SizeUnit::GiB }, { QStringLiteral( "KB" ), SizeUnit::KB },
{ QStringLiteral( "MB" ), SizeUnit::MB }, { QStringLiteral( "GB" ), SizeUnit::GB }
};
return names;
@ -90,8 +91,11 @@ PartitionSize::toSectors( qint64 totalSectors, qint64 sectorSize ) const
return totalSectors * value() / 100;
}
case SizeUnit::Byte:
case SizeUnit::KB:
case SizeUnit::KiB:
case SizeUnit::MB:
case SizeUnit::MiB:
case SizeUnit::GB:
case SizeUnit::GiB:
return CalamaresUtils::bytesToSectors( toBytes(), sectorSize );
}
@ -125,8 +129,11 @@ PartitionSize::toBytes( qint64 totalSectors, qint64 sectorSize ) const
return totalSectors * value() / 100;
}
case SizeUnit::Byte:
case SizeUnit::KB:
case SizeUnit::KiB:
case SizeUnit::MB:
case SizeUnit::MiB:
case SizeUnit::GB:
case SizeUnit::GiB:
return toBytes();
}
@ -161,8 +168,11 @@ PartitionSize::toBytes( qint64 totalBytes ) const
return totalBytes * value() / 100;
}
case SizeUnit::Byte:
case SizeUnit::KB:
case SizeUnit::KiB:
case SizeUnit::MB:
case SizeUnit::MiB:
case SizeUnit::GB:
case SizeUnit::GiB:
return toBytes();
}
@ -186,10 +196,16 @@ PartitionSize::toBytes() const
return -1;
case SizeUnit::Byte:
return value();
case SizeUnit::KB:
return CalamaresUtils::KBtoBytes( static_cast< unsigned long long >( value() ) );
case SizeUnit::KiB:
return CalamaresUtils::KiBtoBytes( static_cast< unsigned long long >( value() ) );
case SizeUnit::MB:
return CalamaresUtils::MBtoBytes( static_cast< unsigned long long >( value() ) );
case SizeUnit::MiB:
return CalamaresUtils::MiBtoBytes( static_cast< unsigned long long >( value() ) );
case SizeUnit::GB:
return CalamaresUtils::GBtoBytes( static_cast< unsigned long long >( value() ) );
case SizeUnit::GiB:
return CalamaresUtils::GiBtoBytes( static_cast< unsigned long long >( value() ) );
}
@ -211,8 +227,11 @@ PartitionSize::operator<( const PartitionSize& other ) const
case SizeUnit::Percent:
return ( m_value < other.m_value );
case SizeUnit::Byte:
case SizeUnit::KB:
case SizeUnit::KiB:
case SizeUnit::MB:
case SizeUnit::MiB:
case SizeUnit::GB:
case SizeUnit::GiB:
return ( toBytes() < other.toBytes() );
}
@ -234,8 +253,11 @@ PartitionSize::operator>( const PartitionSize& other ) const
case SizeUnit::Percent:
return ( m_value > other.m_value );
case SizeUnit::Byte:
case SizeUnit::KB:
case SizeUnit::KiB:
case SizeUnit::MB:
case SizeUnit::MiB:
case SizeUnit::GB:
case SizeUnit::GiB:
return ( toBytes() > other.toBytes() );
}
@ -257,8 +279,11 @@ PartitionSize::operator==( const PartitionSize& other ) const
case SizeUnit::Percent:
return ( m_value == other.m_value );
case SizeUnit::Byte:
case SizeUnit::KB:
case SizeUnit::KiB:
case SizeUnit::MB:
case SizeUnit::MiB:
case SizeUnit::GB:
case SizeUnit::GiB:
return ( toBytes() == other.toBytes() );
}

@ -36,8 +36,11 @@ enum class SizeUnit
None,
Percent,
Byte,
KB,
KiB,
MB,
MiB,
GB,
GiB
};

@ -25,54 +25,108 @@
namespace CalamaresUtils
{
/** User defined literals, 1_KB is 1 KiloByte (= 10^3 bytes) */
constexpr qint64 operator""_KB( unsigned long long m )
{
return qint64( m ) * 1000;
}
/** User defined literals, 1_KiB is 1 KibiByte (= 2^10 bytes) */
constexpr qint64 operator""_KiB( unsigned long long m )
{
return qint64( m ) * 1024;
}
/** User defined literals, 1_MB is 1 MegaByte (= 10^6 bytes) */
constexpr qint64 operator""_MB( unsigned long long m )
{
return operator""_KB(m)*1000;
}
/** User defined literals, 1_MiB is 1 MibiByte (= 2^20 bytes) */
constexpr qint64 operator""_MiB( unsigned long long m )
{
return operator""_KiB(m)*1024;
}
/** User defined literals, 1_GB is 1 GigaByte (= 10^9 bytes) */
constexpr qint64 operator""_GB( unsigned long long m )
{
return operator""_MB(m)*1000;
}
/** User defined literals, 1_GiB is 1 GibiByte (= 2^30 bytes) */
constexpr qint64 operator""_GiB( unsigned long long m )
{
return operator""_MiB(m)*1024;
}
constexpr qint64
KBtoBytes( unsigned long long m )
{
return operator""_KB( m );
}
constexpr qint64
KiBtoBytes( unsigned long long m )
{
return operator""_KiB( m );
}
constexpr qint64
MBtoBytes( unsigned long long m )
{
return operator""_MB( m );
}
constexpr qint64
MiBtoBytes( unsigned long long m )
{
return operator""_MiB( m );
}
constexpr qint64
GBtoBytes( unsigned long long m )
{
return operator""_GB( m );
}
constexpr qint64
GiBtoBytes( unsigned long long m )
{
return operator""_GiB( m );
}
constexpr qint64
KBtoBytes( double m )
{
return qint64( m * 1000 );
}
constexpr qint64
KiBtoBytes( double m )
{
return qint64( m * 1024 );
}
constexpr qint64
MBtoBytes( double m )
{
return qint64( m * 1000 * 1000 );
}
constexpr qint64
MiBtoBytes( double m )
{
return qint64( m * 1024 * 1024 );
}
constexpr qint64
GBtoBytes( double m )
{
return qint64( m * 1000 * 1000 * 1000 );
}
constexpr qint64
GiBtoBytes( double m )
{

Loading…
Cancel
Save