From fec8361ed5640ee5c7ae47ae7652655d4201cac0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 30 Jul 2020 10:51:48 +0200 Subject: [PATCH] [partition] Drop "convenience" functions - the functions are used just once - thin wrappers for named-enum methods that are just as convenient --- src/modules/partition/core/Config.cpp | 5 +++-- src/modules/partition/core/PartitionActions.cpp | 17 ++--------------- src/modules/partition/core/PartitionActions.h | 7 ++++--- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/modules/partition/core/Config.cpp b/src/modules/partition/core/Config.cpp index aaf9cb906..7af004942 100644 --- a/src/modules/partition/core/Config.cpp +++ b/src/modules/partition/core/Config.cpp @@ -64,7 +64,7 @@ getSwapChoices( const QVariantMap& configurationMap ) for ( const auto& item : l ) { bool ok = false; - auto v = PartitionActions::Choices::nameToChoice( item, ok ); + auto v = PartitionActions::Choices::swapChoiceNames().find( item, ok ); if ( ok ) { choices.insert( v ); @@ -105,7 +105,8 @@ getSwapChoices( const QVariantMap& configurationMap ) #define COMPLAIN_UNSUPPORTED( 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 ); \ } diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index 0c7ed6e6d..dc4d4eeb4 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -257,8 +257,8 @@ doReplacePartition( PartitionCoreModule* core, Device* dev, Partition* partition namespace Choices { -static const NamedEnumTable< SwapChoice >& -nameTable() +const NamedEnumTable< SwapChoice >& +swapChoiceNames() { static const NamedEnumTable< SwapChoice > names { { QStringLiteral( "none" ), SwapChoice::NoSwap }, { QStringLiteral( "small" ), SwapChoice::SmallSwap }, @@ -269,19 +269,6 @@ nameTable() 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 pickOne( const SwapChoiceSet& s ) { diff --git a/src/modules/partition/core/PartitionActions.h b/src/modules/partition/core/PartitionActions.h index 558ccb4b9..706fbaea3 100644 --- a/src/modules/partition/core/PartitionActions.h +++ b/src/modules/partition/core/PartitionActions.h @@ -19,6 +19,8 @@ #ifndef PARTITIONACTIONS_H #define PARTITIONACTIONS_H +#include "utils/NamedEnum.h" + #include #include @@ -34,7 +36,7 @@ namespace PartitionActions */ namespace Choices { -/** @brief Ccchoice of swap (size and type) */ +/** @brief Choice of swap (size and type) */ enum SwapChoice { NoSwap, // don't create any swap, don't use any @@ -45,8 +47,7 @@ enum SwapChoice }; using SwapChoiceSet = QSet< SwapChoice >; -SwapChoice nameToChoice( QString name, bool& ok ); -QString choiceToName( SwapChoice ); +const NamedEnumTable< SwapChoice >& swapChoiceNames(); /** @brief Given a set of swap choices, return a sensible value from it. *