[partition] Drop "convenience" functions

- the functions are used just once
- thin wrappers for named-enum methods that are just as convenient
This commit is contained in:
Adriaan de Groot 2020-07-30 10:51:48 +02:00
parent 824dac62d8
commit fec8361ed5
3 changed files with 9 additions and 20 deletions

View File

@ -64,7 +64,7 @@ getSwapChoices( const QVariantMap& configurationMap )
for ( const auto& item : l ) for ( const auto& item : l )
{ {
bool ok = false; bool ok = false;
auto v = PartitionActions::Choices::nameToChoice( item, ok ); auto v = PartitionActions::Choices::swapChoiceNames().find( item, ok );
if ( ok ) if ( ok )
{ {
choices.insert( v ); choices.insert( v );
@ -105,7 +105,8 @@ getSwapChoices( const QVariantMap& configurationMap )
#define COMPLAIN_UNSUPPORTED( x ) \ #define COMPLAIN_UNSUPPORTED( x ) \
if ( choices.contains( x ) ) \ if ( choices.contains( x ) ) \
{ \ { \
cWarning() << unsupportedSetting << PartitionActions::Choices::choiceToName( x ); \ bool bogus = false; \
cWarning() << unsupportedSetting << PartitionActions::Choices::swapChoiceNames().find( x, bogus ); \
choices.remove( x ); \ choices.remove( x ); \
} }

View File

@ -257,8 +257,8 @@ doReplacePartition( PartitionCoreModule* core, Device* dev, Partition* partition
namespace Choices namespace Choices
{ {
static const NamedEnumTable< SwapChoice >& const NamedEnumTable< SwapChoice >&
nameTable() swapChoiceNames()
{ {
static const NamedEnumTable< SwapChoice > names { { QStringLiteral( "none" ), SwapChoice::NoSwap }, static const NamedEnumTable< SwapChoice > names { { QStringLiteral( "none" ), SwapChoice::NoSwap },
{ QStringLiteral( "small" ), SwapChoice::SmallSwap }, { QStringLiteral( "small" ), SwapChoice::SmallSwap },
@ -269,19 +269,6 @@ nameTable()
return names; return names;
} }
SwapChoice
nameToChoice( QString name, bool& ok )
{
return nameTable().find( name, ok );
}
QString
choiceToName( SwapChoice c )
{
bool ok = false;
return nameTable().find( c, ok );
}
SwapChoice SwapChoice
pickOne( const SwapChoiceSet& s ) pickOne( const SwapChoiceSet& s )
{ {

View File

@ -19,6 +19,8 @@
#ifndef PARTITIONACTIONS_H #ifndef PARTITIONACTIONS_H
#define PARTITIONACTIONS_H #define PARTITIONACTIONS_H
#include "utils/NamedEnum.h"
#include <QSet> #include <QSet>
#include <QString> #include <QString>
@ -34,7 +36,7 @@ namespace PartitionActions
*/ */
namespace Choices namespace Choices
{ {
/** @brief Ccchoice of swap (size and type) */ /** @brief Choice of swap (size and type) */
enum SwapChoice enum SwapChoice
{ {
NoSwap, // don't create any swap, don't use any NoSwap, // don't create any swap, don't use any
@ -45,8 +47,7 @@ enum SwapChoice
}; };
using SwapChoiceSet = QSet< SwapChoice >; using SwapChoiceSet = QSet< SwapChoice >;
SwapChoice nameToChoice( QString name, bool& ok ); const NamedEnumTable< SwapChoice >& swapChoiceNames();
QString choiceToName( SwapChoice );
/** @brief Given a set of swap choices, return a sensible value from it. /** @brief Given a set of swap choices, return a sensible value from it.
* *