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

Add 'base 10' partition size multiples
This commit is contained in:
Adriaan de Groot 2019-08-13 20:26:22 +02:00 committed by GitHub
commit 09a36cd669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 1 deletions

View File

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

View File

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

View File

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