Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openfoam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
openfoam
Commits
49615340
Commit
49615340
authored
6 years ago
by
Mark OLESEN
Browse files
Options
Downloads
Patches
Plain Diff
ENH: add failsafe version of Enum::get()
parent
59cb856f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/OpenFOAM/primitives/enums/Enum.C
+19
-1
19 additions, 1 deletion
src/OpenFOAM/primitives/enums/Enum.C
src/OpenFOAM/primitives/enums/Enum.H
+5
-1
5 additions, 1 deletion
src/OpenFOAM/primitives/enums/Enum.H
with
24 additions
and
2 deletions
src/OpenFOAM/primitives/enums/Enum.C
+
19
−
1
View file @
49615340
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
========= |
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / O peration |
\\ / A nd | Copyright (C) 2017-201
8
OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-201
9
OpenCFD Ltd.
\\/ M anipulation |
\\/ M anipulation |
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
License
License
...
@@ -77,6 +77,24 @@ EnumType Foam::Enum<EnumType>::get(const word& enumName) const
...
@@ -77,6 +77,24 @@ EnumType Foam::Enum<EnumType>::get(const word& enumName) const
}
}
template
<
class
EnumType
>
EnumType
Foam
::
Enum
<
EnumType
>::
get
(
const
word
&
enumName
,
const
EnumType
defaultValue
)
const
{
const
label
idx
=
find
(
enumName
);
if
(
idx
<
0
)
{
return
defaultValue
;
}
return
EnumType
(
vals_
[
idx
]);
}
template
<
class
EnumType
>
template
<
class
EnumType
>
EnumType
Foam
::
Enum
<
EnumType
>::
read
(
Istream
&
is
)
const
EnumType
Foam
::
Enum
<
EnumType
>::
read
(
Istream
&
is
)
const
{
{
...
...
This diff is collapsed.
Click to expand it.
src/OpenFOAM/primitives/enums/Enum.H
+
5
−
1
View file @
49615340
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
========= |
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / O peration |
\\ / A nd | Copyright (C) 2017-201
8
OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-201
9
OpenCFD Ltd.
\\/ M anipulation |
\\/ M anipulation |
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
License
License
...
@@ -130,6 +130,10 @@ public:
...
@@ -130,6 +130,10 @@ public:
// FatalError if not found.
// FatalError if not found.
EnumType
get
(
const
word
&
enumName
)
const
;
EnumType
get
(
const
word
&
enumName
)
const
;
//- The enumeration corresponding to the given name.
// \return The enumeration or default if not found.
EnumType
get
(
const
word
&
enumName
,
const
EnumType
defaultValue
)
const
;
//- The name corresponding to the given enumeration.
//- The name corresponding to the given enumeration.
// Return an empty word if not found.
// Return an empty word if not found.
inline
const
word
&
get
(
const
EnumType
e
)
const
;
inline
const
word
&
get
(
const
EnumType
e
)
const
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment