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
Wiki
Coding
Patterns
selectors
Changes
Page history
New page
Templates
Clone repository
update selector lookup coding pattern
authored
3 years ago
by
Mark OLESEN
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
coding/patterns/selectors.md
+33
-1
33 additions, 1 deletion
coding/patterns/selectors.md
with
33 additions
and
1 deletion
coding/patterns/selectors.md
View page @
c7ffb29a
...
...
@@ -9,6 +9,38 @@
[[
_TOC_
]]
### Lookups for New() selectors
\s
ince 2112
```
const word modelType(coeffs.get<word>("type"));
auto* ctorPtr = dictionaryConstructorTable(modelType);
if (!ctorPtr)
{
FatalIOErrorInLookup
(
dict,
"fvOption",
modelType,
*dictionaryConstructorTablePtr_
) << exit(FatalIOError);
}
return autoPtr<option>(ctorPtr(name, modelType, coeffs, mesh));
```
This contains the following aspects:
-
The dictionary
`get<word>`
for retrieval with input checking
-
The lookup uses
`dictionaryConstructorTable()`
instead of the HashTable
which adds in additional checks and compatibility aliases.
-
Exit immediately upon error, leaving the _good_ case to drop through.
-
Use of the
`FatalErrorInLookup`
or
`FatalIOErrorInLookup`
macros to
wrap standard boilerplate text for the output.
### Lookups for New() selectors
\s
ince 1912
...
...
@@ -44,7 +76,7 @@ This contains the following aspects:
but we save typing and potential mismatches by using these dedicated
methods.
-
Exit immediately upon error, leaving the _good_ case to drop through.
-
Use of the
`FatalErrorInLookup`
or
`FatalIOErrorInLookup`
macros
which
-
Use of the
`FatalErrorInLookup`
or
`FatalIOErrorInLookup`
macros
to
wrap standard boilerplate text for the output.
**Anti-pattern**
: The equivalent longhand version (pre-v1912)
...
...
This diff is collapsed.
Click to expand it.