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 >
99 Foam::functionEntries::inputMode::selectableNames
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 
113 bool Foam::functionEntries::inputMode::execute
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 
134  }
135 
136  return true;
137 }
138 
139 
140 bool Foam::functionEntries::inputModeDefault::execute
141 (
142  dictionary& parentDict,
143  Istream& is
144 )
145 {
146  return entry::New(parentDict, is, entry::inputMode::PROTECT);
147 }
148 
149 
150 bool Foam::functionEntries::inputModeMerge::execute
151 (
152  dictionary& parentDict,
153  Istream& is
154 )
155 {
156  return entry::New(parentDict, is, entry::inputMode::MERGE);
157 }
158 
159 
160 bool Foam::functionEntries::inputModeOverwrite::execute
161 (
162  dictionary& parentDict,
163  Istream& is
164 )
165 {
166  return entry::New(parentDict, is, entry::inputMode::OVERWRITE);
167 }
168 
169 
170 bool Foam::functionEntries::inputModeWarn::execute
171 (
172  dictionary& parentDict,
173  Istream& is
174 )
175 {
176  return entry::New(parentDict, is, entry::inputMode::WARN);
177 }
178 
179 
180 bool Foam::functionEntries::inputModeError::execute
181 (
182  dictionary& parentDict,
183  Istream& is
184 )
185 {
186  return entry::New(parentDict, is, entry::inputMode::ERROR);
187 }
188 
189 
190 // ************************************************************************* //
Foam::entry::inputMode::WARN
@ WARN
Keep initial entry. Warn about subsequent ones.
Foam::entry::New
static bool New(dictionary &parentDict, Istream &is, const inputMode inpMode=inputMode::GLOBAL, const int endChar=0)
Definition: entryIO.C:98
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:53
Foam::entry::inputMode::ERROR
@ ERROR
FatalError for duplicate entries.
Foam::entry::globalInputMode
static inputMode globalInputMode
Definition: entry.H:126
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::entry::inputMode
inputMode
Definition: entry.H:72
inputMode.H
inputMode
Specify the global input mode when reading further dictionaries, expects a single word to follow.
addToMemberFunctionSelectionTable.H
Macros for easy insertion into member function selection tables.
Foam::entry::resetInputMode
static void resetInputMode()
Definition: entry.C:54
Foam::functionEntries::addNamedToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream, calc)
Foam
Definition: atmBoundaryLayer.C:26
Foam::entry::inputMode::MERGE
@ MERGE
Merge sub-dictionaries when possible.
dictionary.H
Foam::entry::inputMode::PROTECT
@ PROTECT
Keep initial entry. Silently ignore subsequent ones.
WarningInFunction
#define WarningInFunction
Definition: messageStream.H:353
Foam::entry::inputMode::OVERWRITE
@ OVERWRITE
Keep last entry. Silently remove previous ones.