Commit e082be56 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

STYLE: use Enum for #inputMode selection

parent 751f1108
......@@ -55,60 +55,61 @@ namespace functionEntries
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// we could combine this into execute() directly, but leave it here for now
void Foam::functionEntries::inputModeEntry::setMode(Istream& is)
const Foam::Enum
<
Foam::functionEntries::inputModeEntry::inputMode
>
Foam::functionEntries::inputModeEntry::inputModeNames
{
clear();
{ inputMode::MERGE, "merge" },
{ inputMode::OVERWRITE, "overwrite" },
{ inputMode::PROTECT, "protect" },
{ inputMode::WARN, "warn" },
{ inputMode::ERROR, "error" },
// Aliases
{ inputMode::MERGE, "default" },
};
const word mode(is);
if (mode == "merge" || mode == "default")
{
mode_ = MERGE;
}
else if (mode == "overwrite")
{
mode_ = OVERWRITE;
}
else if (mode == "protect")
{
mode_ = PROTECT;
}
else if (mode == "warn")
{
mode_ = WARN;
}
else if (mode == "error")
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionEntries::inputModeEntry::execute
(
dictionary& unused,
Istream& is
)
{
const word modeName(is);
// Bheaviour like Enum lookupOrFailsafe()
if (inputModeNames.hasEnum(modeName))
{
mode_ = ERROR;
mode_ = inputModeNames[modeName];
}
else
{
WarningInFunction
<< "unsupported input mode '" << mode
<< "Unsupported inputMode '" << modeName
<< "' ... defaulting to 'merge'"
<< endl;
reset();
}
}
return true;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionEntries::inputModeEntry::execute
(
dictionary& unused,
Istream& is
)
void Foam::functionEntries::inputModeEntry::reset()
{
setMode(is);
return true;
mode_ = MERGE;
}
void Foam::functionEntries::inputModeEntry::clear()
{
mode_ = MERGE;
reset();
}
......
......@@ -58,6 +58,7 @@ SourceFiles
#define inputModeEntry_H
#include "functionEntry.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -84,15 +85,15 @@ class inputModeEntry
ERROR
};
//- Text representations of the input modes
const static Enum<inputMode> inputModeNames;
//- The current input mode
static inputMode mode_;
// Private Member Functions
//- Read the mode as a word and set enum appropriately
static void setMode(Istream& is);
//- Disallow default bitwise copy construct
inputModeEntry(const inputModeEntry&) = delete;
......@@ -112,6 +113,9 @@ public:
static bool execute(dictionary& parentDict, Istream& is);
//- Reset the inputMode to %default (ie, %merge)
static void reset();
//- Identical to reset.
static void clear();
//- Return true if the inputMode is %merge
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment