[libcalamares] Add convenience method to check for unit-comparability
- Not all kinds of units are comparable. Introduce a method in PartitionSize to check for comparability (this could also be a free method, but seems more tidy here because it is specifically about comparing in the context of partition sizes).
This commit is contained in:
parent
d048975f15
commit
93a68c3d5f
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
|
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -96,6 +97,20 @@ public:
|
|||||||
* @return the size in bytes, or -1 if it cannot be calculated.
|
* @return the size in bytes, or -1 if it cannot be calculated.
|
||||||
*/
|
*/
|
||||||
qint64 toBytes() const;
|
qint64 toBytes() const;
|
||||||
|
|
||||||
|
/** @brief Are the units comparable?
|
||||||
|
*
|
||||||
|
* None units cannot be compared with anything. Percentages can
|
||||||
|
* be compared with each other, and all the explicit sizes (KiB, ...)
|
||||||
|
* can be compared with each other.
|
||||||
|
*/
|
||||||
|
static constexpr bool unitsComparable( const SizeUnit u1, const SizeUnit u2 )
|
||||||
|
{
|
||||||
|
return !( ( u1 == SizeUnit::None || u2 == SizeUnit::None ) ||
|
||||||
|
( u1 == SizeUnit::Percent && u2 != SizeUnit::Percent ) ||
|
||||||
|
( u1 != SizeUnit::Percent && u2 == SizeUnit::Percent ) );
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Calamares
|
} // namespace Calamares
|
||||||
|
Loading…
Reference in New Issue
Block a user