Commit 73116c4f authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: cleanup of Enum class

- more dictionary-like methods, enforce keyType::LITERAL for all
  lookups to avoid any spurious keyword matching.

- new readEntry, readIfPresent methods

- The get() method replaces the now deprecate lookup() method.

- Deprecate lookupOrFailsafe()
  Failsafe behaviour is now an optional parameter for lookupOrDefault,
  which makes it easier to tailor behaviour at runtime.

- output of the names is now always flatted without line-breaks.
  Thus,

     os << flatOutput(someEnumNames.names()) << nl;
     os << someEnumNames << nl;

  both generate the same output.

- Constructor now uses C-string (const char*) directly instead of
  Foam::word in its initializer_list.

- Remove special enum + initializer_list constructor form since
  it can create unbounded lookup indices.

- Removd old hasEnum, hasName forms that were provided during initial
  transition from NamedEnum.

- Added static_assert on Enum contents to restrict to enum or
  integral values.  Should not likely be using this class to enumerate
  other things since it internally uses an 'int' for its values.

  Changed volumeType accordingly to enumerate on its type (enum),
  not the class itself.
parent 7c9e7276
......@@ -52,22 +52,22 @@ const Foam::Enum
Foam::functionObjects::fieldVisualisationBase::colourByType
>
Foam::functionObjects::fieldVisualisationBase::colourByTypeNames
{
({
{ colourByType::cbColour, "colour" },
{ colourByType::cbField, "field" },
};
});
const Foam::Enum
<
Foam::functionObjects::fieldVisualisationBase::colourMapType
>
Foam::functionObjects::fieldVisualisationBase::colourMapTypeNames
{
({
{ colourMapType::cmRainbow, "rainbow" },
{ colourMapType::cmBlueWhiteRed, "blueWhiteRed" },
{ colourMapType::cmFire, "fire" },
{ colourMapType::cmGreyscale, "greyscale" },
};
});
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
......@@ -489,7 +489,7 @@ Foam::functionObjects::fieldVisualisationBase::fieldVisualisationBase
colourMap_(cmRainbow),
range_()
{
colourBy_ = colourByTypeNames.lookup("colourBy", dict);
colourByTypeNames.readEntry("colourBy", dict, colourBy_);
switch (colourBy_)
{
......@@ -502,10 +502,7 @@ Foam::functionObjects::fieldVisualisationBase::fieldVisualisationBase
{
dict.readEntry("range", range_);
if (dict.found("colourMap"))
{
colourMap_ = colourMapTypeNames.lookup("colourMap", dict);
}
colourMapTypeNames.readIfPresent("colourMap", dict, colourMap_);
const dictionary& sbarDict = dict.subDict("scalarBar");
sbarDict.readEntry("visible", scalarBar_.visible_);
......
......@@ -37,11 +37,11 @@ const Foam::Enum
Foam::functionObjects::runTimePostPro::geometryBase::renderModeType
>
Foam::functionObjects::runTimePostPro::geometryBase::renderModeTypeNames
{
({
{ renderModeType::rmFlat, "flat" },
{ renderModeType::rmGouraud, "gouraud" },
{ renderModeType::rmPhong, "phong" },
};
});
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
......@@ -87,15 +87,13 @@ Foam::functionObjects::runTimePostPro::geometryBase::geometryBase
parent_(parent),
name_(dict.dictName()),
visible_(dict.get<bool>("visible")),
renderMode_(rmGouraud),
renderMode_
(
renderModeTypeNames.lookupOrDefault("renderMode", dict, rmGouraud)
),
opacity_(nullptr),
colours_(colours)
{
if (dict.found("renderMode"))
{
renderMode_ = renderModeTypeNames.lookup("renderMode", dict);
}
if (dict.found("opacity"))
{
opacity_.reset(Function1<scalar>::New("opacity", dict).ptr());
......
......@@ -55,12 +55,12 @@ const Foam::Enum
Foam::functionObjects::runTimePostPro::pathline::representationType
>
Foam::functionObjects::runTimePostPro::pathline::representationTypeNames
{
({
{ representationType::rtNone, "none" },
{ representationType::rtLine, "line" },
{ representationType::rtTube, "tube" },
{ representationType::rtVector, "vector" },
};
});
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
......@@ -129,7 +129,7 @@ Foam::functionObjects::runTimePostPro::pathline::pathline
geometryBase(parent, dict, colours),
representation_
(
representationTypeNames.lookup("representation", dict)
representationTypeNames.get("representation", dict)
),
tubeRadius_(0.0),
lineColour_(nullptr)
......
......@@ -55,10 +55,10 @@ const Foam::Enum
Foam::functionObjects::runTimePostPro::pointData::representationType
>
Foam::functionObjects::runTimePostPro::pointData::representationTypeNames
{
({
{ representationType::rtSphere, "sphere" },
{ representationType::rtVector, "vector" },
};
});
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
......@@ -99,7 +99,7 @@ Foam::functionObjects::runTimePostPro::pointData::pointData
geometryBase(parent, dict, colours),
representation_
(
representationTypeNames.lookup("representation", dict)
representationTypeNames.get("representation", dict)
),
maxGlyphLength_(dict.get<scalar>("maxGlyphLength")),
pointColour_(nullptr)
......
......@@ -56,13 +56,13 @@ const Foam::Enum
Foam::functionObjects::runTimePostPro::surface::representationType
>
Foam::functionObjects::runTimePostPro::surface::representationTypeNames
{
({
{ representationType::rtNone, "none" },
{ representationType::rtWireframe, "wireframe" },
{ representationType::rtSurface, "surface" },
{ representationType::rtSurfaceWithEdges, "surfaceWithEdges" },
{ representationType::rtGlyph, "glyph" },
};
});
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
......@@ -149,7 +149,7 @@ Foam::functionObjects::runTimePostPro::surface::surface
geometryBase(parent, dict, colours),
representation_
(
representationTypeNames.lookup("representation", dict)
representationTypeNames.get("representation", dict)
),
featureEdges_(false),
surfaceColour_(nullptr),
......
Markdown is supported
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