mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: minor improvements for Enum
- found() method for consistency with other classes - operator()(name, deflt) for similarity to lookupOrDefault, but without a dictionary
This commit is contained in:
@ -309,7 +309,7 @@ int main(int argc, char *argv[])
|
|||||||
if
|
if
|
||||||
(
|
(
|
||||||
matchName != "perfect"
|
matchName != "perfect"
|
||||||
&& !slidingInterface::typeOfMatchNames.hasEnum(matchName)
|
&& !slidingInterface::typeOfMatchNames.found(matchName)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Info<< "Error: unknown match type - " << matchName
|
Info<< "Error: unknown match type - " << matchName
|
||||||
|
|||||||
@ -229,7 +229,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
|
|
||||||
word patchMapMethod;
|
word patchMapMethod;
|
||||||
if (meshToMesh::interpolationMethodNames_.hasEnum(mapMethod))
|
if (meshToMesh::interpolationMethodNames_.found(mapMethod))
|
||||||
{
|
{
|
||||||
// Lookup corresponding AMI method
|
// Lookup corresponding AMI method
|
||||||
meshToMesh::interpolationMethod method =
|
meshToMesh::interpolationMethod method =
|
||||||
|
|||||||
@ -1577,7 +1577,7 @@ int main(int argc, char *argv[])
|
|||||||
{ booleanSurface::DIFFERENCE, "difference" }
|
{ booleanSurface::DIFFERENCE, "difference" }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!validActions.hasEnum(action))
|
if (!validActions.found(action))
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Unsupported action " << action << endl
|
<< "Unsupported action " << action << endl
|
||||||
|
|||||||
@ -117,7 +117,7 @@ bool Foam::functionEntries::inputMode::execute
|
|||||||
const word modeName(is);
|
const word modeName(is);
|
||||||
|
|
||||||
// Behaviour like Enum lookupOrFailsafe()
|
// Behaviour like Enum lookupOrFailsafe()
|
||||||
if (selectableNames.hasEnum(modeName))
|
if (selectableNames.found(modeName))
|
||||||
{
|
{
|
||||||
entry::globalInputMode = selectableNames[modeName];
|
entry::globalInputMode = selectableNames[modeName];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,10 +87,8 @@ const Foam::word& Foam::Enum<EnumType>::getName(const EnumType e) const
|
|||||||
{
|
{
|
||||||
return word::null;
|
return word::null;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return names_[idx];
|
return names_[idx];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -233,16 +231,14 @@ EnumType Foam::Enum<EnumType>::lookupOrFailsafe
|
|||||||
const word enumName(dict.lookup(key));
|
const word enumName(dict.lookup(key));
|
||||||
const label idx = getIndex(enumName);
|
const label idx = getIndex(enumName);
|
||||||
|
|
||||||
if (idx < 0)
|
if (idx >= 0)
|
||||||
{
|
|
||||||
IOWarningInFunction(dict)
|
|
||||||
<< "bad " << key <<" specifier " << enumName
|
|
||||||
<< " using " << getName(deflt) << endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return EnumType(values_[idx]);
|
return EnumType(values_[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IOWarningInFunction(dict)
|
||||||
|
<< "bad " << key <<" specifier " << enumName
|
||||||
|
<< " using " << getName(deflt) << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return deflt;
|
return deflt;
|
||||||
|
|||||||
@ -25,10 +25,11 @@ Class
|
|||||||
Foam::Enum
|
Foam::Enum
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A Enum is a wrapper around a list of names/values that represent
|
Enum is a wrapper around a list of names/values that represent particular
|
||||||
particular enumeration values.
|
enumeration values.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
|
EnumI.H
|
||||||
Enum.C
|
Enum.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -132,9 +133,17 @@ public:
|
|||||||
// Query
|
// Query
|
||||||
|
|
||||||
//- Test if there is an enumeration corresponding to the given name.
|
//- Test if there is an enumeration corresponding to the given name.
|
||||||
|
inline bool found(const word& enumName) const;
|
||||||
|
|
||||||
|
//- Test if there is a name corresponding to the given enumeration.
|
||||||
|
inline bool found(const EnumType e) const;
|
||||||
|
|
||||||
|
//- Test if there is an enumeration corresponding to the given name.
|
||||||
|
// \deprecated Use found() - for compatibility with NamedEnum
|
||||||
inline bool hasEnum(const word& enumName) const;
|
inline bool hasEnum(const word& enumName) const;
|
||||||
|
|
||||||
//- Test if there is a name corresponding to the given enumeration.
|
//- Test if there is a name corresponding to the given enumeration.
|
||||||
|
// \deprecated Use found() - for compatibility with NamedEnum
|
||||||
inline bool hasName(const EnumType e) const;
|
inline bool hasName(const EnumType e) const;
|
||||||
|
|
||||||
|
|
||||||
@ -142,7 +151,7 @@ public:
|
|||||||
|
|
||||||
//- Lookup the key in the dictionary and return the corresponding
|
//- Lookup the key in the dictionary and return the corresponding
|
||||||
//- enumeration element based on its name.
|
//- enumeration element based on its name.
|
||||||
// Fatal if anything is incorrect.
|
// FatalError if anything is incorrect.
|
||||||
EnumType lookup
|
EnumType lookup
|
||||||
(
|
(
|
||||||
const word& key,
|
const word& key,
|
||||||
@ -152,7 +161,7 @@ public:
|
|||||||
//- Find the key in the dictionary and return the corresponding
|
//- Find the key in the dictionary and return the corresponding
|
||||||
//- enumeration element based on its name.
|
//- enumeration element based on its name.
|
||||||
// Return the default value if the key was not found in the dictionary.
|
// Return the default value if the key was not found in the dictionary.
|
||||||
// Fatal if the enumerated name was incorrect.
|
// FatalError if the enumerated name was incorrect.
|
||||||
EnumType lookupOrDefault
|
EnumType lookupOrDefault
|
||||||
(
|
(
|
||||||
const word& key,
|
const word& key,
|
||||||
@ -193,13 +202,23 @@ public:
|
|||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Return the enumeration corresponding to the given name
|
//- Return the enumeration corresponding to the given name
|
||||||
// Fatal if the name cannot be found.
|
// FatalError if the name is not found.
|
||||||
inline const EnumType operator[](const word& name) const;
|
// Identical to getEnum()
|
||||||
|
inline EnumType operator[](const word& enumName) const;
|
||||||
|
|
||||||
//- Return the first name corresponding to the given enumeration.
|
//- Return the first name corresponding to the given enumeration.
|
||||||
// Returns an empty word on failure.
|
// Returns an empty word on failure.
|
||||||
|
// Identical to getName()
|
||||||
inline const word& operator[](const EnumType e) const;
|
inline const word& operator[](const EnumType e) const;
|
||||||
|
|
||||||
|
//- Return the enumeration corresponding to the given name or deflt
|
||||||
|
//- if the name is not found.
|
||||||
|
inline EnumType operator()
|
||||||
|
(
|
||||||
|
const word& enumName,
|
||||||
|
const EnumType deflt
|
||||||
|
) const;
|
||||||
|
|
||||||
|
|
||||||
// IOstream operators
|
// IOstream operators
|
||||||
|
|
||||||
|
|||||||
@ -53,6 +53,20 @@ inline const Foam::List<int>& Foam::Enum<EnumType>::values() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class EnumType>
|
||||||
|
inline bool Foam::Enum<EnumType>::found(const word& enumName) const
|
||||||
|
{
|
||||||
|
return getIndex(enumName) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class EnumType>
|
||||||
|
inline bool Foam::Enum<EnumType>::found(const EnumType e) const
|
||||||
|
{
|
||||||
|
return getIndex(e) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class EnumType>
|
template<class EnumType>
|
||||||
inline bool Foam::Enum<EnumType>::hasEnum(const word& enumName) const
|
inline bool Foam::Enum<EnumType>::hasEnum(const word& enumName) const
|
||||||
{
|
{
|
||||||
@ -81,12 +95,12 @@ inline Foam::Ostream& Foam::Enum<EnumType>::writeList
|
|||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class EnumType>
|
template<class EnumType>
|
||||||
inline const EnumType Foam::Enum<EnumType>::operator[]
|
inline EnumType Foam::Enum<EnumType>::operator[]
|
||||||
(
|
(
|
||||||
const word& name
|
const word& enumName
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return getEnum(name);
|
return getEnum(enumName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -100,4 +114,22 @@ inline const Foam::word& Foam::Enum<EnumType>::operator[]
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class EnumType>
|
||||||
|
inline EnumType Foam::Enum<EnumType>::operator()
|
||||||
|
(
|
||||||
|
const word& enumName,
|
||||||
|
const EnumType deflt
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
const label idx = getIndex(enumName);
|
||||||
|
|
||||||
|
if (idx >= 0)
|
||||||
|
{
|
||||||
|
return EnumType(values_[idx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return deflt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -377,7 +377,7 @@ bool Foam::fileFormats::FIREMeshReader::readGeometry(const scalar scaleFactor)
|
|||||||
IOstream::streamFormat fmt = IOstream::ASCII;
|
IOstream::streamFormat fmt = IOstream::ASCII;
|
||||||
|
|
||||||
const word ext = geometryFile_.ext();
|
const word ext = geometryFile_.ext();
|
||||||
bool supported = FIRECore::file3dExtensions.hasEnum(ext);
|
bool supported = FIRECore::file3dExtensions.found(ext);
|
||||||
if (supported)
|
if (supported)
|
||||||
{
|
{
|
||||||
FIRECore::fileExt3d fireFileType = FIRECore::file3dExtensions[ext];
|
FIRECore::fileExt3d fireFileType = FIRECore::file3dExtensions[ext];
|
||||||
|
|||||||
@ -278,7 +278,7 @@ bool Foam::fileFormats::FIREMeshWriter::write(const fileName& meshName) const
|
|||||||
{
|
{
|
||||||
const word ext = baseName.ext();
|
const word ext = baseName.ext();
|
||||||
|
|
||||||
if (FIRECore::file3dExtensions.hasEnum(ext))
|
if (FIRECore::file3dExtensions.found(ext))
|
||||||
{
|
{
|
||||||
FIRECore::fileExt3d fireFileType = FIRECore::file3dExtensions[ext];
|
FIRECore::fileExt3d fireFileType = FIRECore::file3dExtensions[ext];
|
||||||
if (fireFileType == FIRECore::fileExt3d::POLY_ASCII)
|
if (fireFileType == FIRECore::fileExt3d::POLY_ASCII)
|
||||||
|
|||||||
@ -72,7 +72,7 @@ void Foam::functionObjects::mapFields::createInterpolation
|
|||||||
);
|
);
|
||||||
const fvMesh& mapRegion = mapRegionPtr_();
|
const fvMesh& mapRegion = mapRegionPtr_();
|
||||||
const word mapMethodName(dict.lookup("mapMethod"));
|
const word mapMethodName(dict.lookup("mapMethod"));
|
||||||
if (!meshToMesh::interpolationMethodNames_.hasEnum(mapMethodName))
|
if (!meshToMesh::interpolationMethodNames_.found(mapMethodName))
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< type() << " " << name() << ": unknown map method "
|
<< type() << " " << name() << ": unknown map method "
|
||||||
|
|||||||
Reference in New Issue
Block a user