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-------------------------------------------------------------------------------
10License
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
34namespace Foam
35{
36namespace functionEntries
37{
39 (
42 execute,
43 dictionaryIstream,
45 );
46
48 (
51 execute,
52 dictionaryIstream,
53 default
54 );
55
57 (
60 execute,
61 dictionaryIstream,
62 merge
63 );
64
66 (
69 execute,
70 dictionaryIstream,
71 overwrite
72 );
73
75 (
78 execute,
79 dictionaryIstream,
80 warn
81 );
82
84 (
87 execute,
88 dictionaryIstream,
89 error
90 );
91} // End namespace functionEntries
92} // End namespace Foam
93
94
95const 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 {
125 }
126 else
127 {
129 << "Unsupported inputMode '" << modeName
130 << "' ... defaulting to 'merge'"
131 << endl;
132
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// ************************************************************************* //
Macros for easy insertion into member function selection tables.
#define addNamedToMemberFunctionSelectionTable(baseType, thisType, funcName, argNames, lookupName)
Add to hash-table of functions with 'lookupName' as the key.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
bool found(const word &enumName) const
True if there is an enumeration corresponding to the given name.
Definition: EnumI.H:103
EnumType get(const word &enumName) const
The enumeration corresponding to the given name.
Definition: Enum.C:75
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
static void resetInputMode()
Reset the globalInputMode to merge.
Definition: entry.C:61
static inputMode globalInputMode
The current global input-mode.
Definition: entry.H:130
inputMode
The input mode options.
Definition: entry.H:77
@ OVERWRITE
Keep last entry. Silently remove previous ones.
@ PROTECT
Keep initial entry. Silently ignore subsequent ones.
@ WARN
Keep initial entry. Warn about subsequent ones.
@ MERGE
Merge sub-dictionaries when possible.
@ ERROR
FatalError for duplicate entries.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:77
Temporarily change inputMode to protect for the following entry.
Definition: inputMode.H:97
Temporarily change inputMode to error for the following entry.
Definition: inputMode.H:161
Temporarily change inputMode to merge for the following entry.
Definition: inputMode.H:113
Temporarily change inputMode to overwrite for the following entry.
Definition: inputMode.H:129
Temporarily change inputMode to warn for the following entry.
Definition: inputMode.H:145
Specify the global input mode when reading further dictionaries, expects a single word to follow.
Definition: inputMode.H:78
static const Enum< entry::inputMode > selectableNames
Text representations of the selectable input modes.
Definition: inputMode.H:82
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:69
virtual bool execute()
Calculate the output fields.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372