inputMode.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "inputMode.H"
29 #include "dictionary.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionEntries
37 {
39  (
40  functionEntry,
41  inputMode,
42  execute,
43  dictionaryIstream,
44  inputMode
45  );
46 
48  (
49  functionEntry,
50  inputModeDefault,
51  execute,
52  dictionaryIstream,
53  default
54  );
55 
57  (
58  functionEntry,
59  inputModeMerge,
60  execute,
61  dictionaryIstream,
62  merge
63  );
64 
66  (
67  functionEntry,
68  inputModeOverwrite,
69  execute,
70  dictionaryIstream,
71  overwrite
72  );
73 
75  (
76  functionEntry,
77  inputModeWarn,
78  execute,
79  dictionaryIstream,
80  warn
81  );
82 
84  (
85  functionEntry,
86  inputModeError,
87  execute,
88  dictionaryIstream,
89  error
90  );
91 } // End namespace functionEntries
92 } // End namespace Foam
93 
94 
95 const Foam::Enum
96 <
98 >
100 ({
101  { entry::inputMode::MERGE, "merge" },
102  { entry::inputMode::OVERWRITE, "overwrite" },
103  { entry::inputMode::PROTECT, "protect" },
104  { entry::inputMode::WARN, "warn" },
105  { entry::inputMode::ERROR, "error" },
106  // Aliases
107  { entry::inputMode::MERGE, "default" },
108 });
109 
110 
111 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
112 
114 (
115  dictionary& unused,
116  Istream& is
117 )
118 {
119  const word modeName(is);
120 
121  // Like Enum::getOrDefault() with failsafe behaviour
122  if (selectableNames.found(modeName))
123  {
124  entry::globalInputMode = selectableNames.get(modeName);
125  }
126  else
127  {
129  << "Unsupported inputMode '" << modeName
130  << "' ... defaulting to 'merge'"
131  << endl;
132 
133  entry::resetInputMode();
134  }
135 
136  return true;
137 }
138 
139 
141 (
142  dictionary& parentDict,
143  Istream& is
144 )
145 {
146  return entry::New(parentDict, is, entry::inputMode::PROTECT);
147 }
148 
149 
151 (
152  dictionary& parentDict,
153  Istream& is
154 )
155 {
156  return entry::New(parentDict, is, entry::inputMode::MERGE);
157 }
158 
159 
161 (
162  dictionary& parentDict,
163  Istream& is
164 )
165 {
166  return entry::New(parentDict, is, entry::inputMode::OVERWRITE);
167 }
168 
169 
171 (
172  dictionary& parentDict,
173  Istream& is
174 )
175 {
176  return entry::New(parentDict, is, entry::inputMode::WARN);
177 }
178 
179 
181 (
182  dictionary& parentDict,
183  Istream& is
184 )
185 {
186  return entry::New(parentDict, is, entry::inputMode::ERROR);
187 }
188 
189 
190 // ************************************************************************* //
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::functionEntries::inputModeOverwrite::execute
static bool execute(dictionary &parentDict, Istream &is)
Execute in a sub-dict context.
Definition: inputMode.C:161
Foam::functionEntries::inputModeError::execute
static bool execute(dictionary &parentDict, Istream &is)
Execute in a sub-dict context.
Definition: inputMode.C:181
Foam::functionEntries::inputMode::execute
static bool execute(dictionary &unused, Istream &is)
Change the global input-mode.
Definition: inputMode.C:114
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::entry::inputMode
inputMode
The input mode options.
Definition: entry.H:76
inputMode.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::functionEntries::inputModeDefault::execute
static bool execute(dictionary &parentDict, Istream &is)
Execute in a sub-dict context.
Definition: inputMode.C:141
addToMemberFunctionSelectionTable.H
Macros for easy insertion into member function selection tables.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::functionEntries::inputMode::selectableNames
static const Enum< entry::inputMode > selectableNames
Text representations of the selectable input modes.
Definition: inputMode.H:82
Foam::functionEntries::addNamedToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream, calc)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionEntries::inputModeWarn::execute
static bool execute(dictionary &parentDict, Istream &is)
Execute in a sub-dict context.
Definition: inputMode.C:171
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
dictionary.H
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:303
Foam::functionEntries::inputModeMerge::execute
static bool execute(dictionary &parentDict, Istream &is)
Execute in a sub-dict context.
Definition: inputMode.C:151