Loading...
Searching...
No Matches
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"
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,
144)
145{
146 return entry::New(parentDict, is, entry::inputMode::PROTECT);
147}
148
149
151(
152 dictionary& parentDict,
154)
155{
156 return entry::New(parentDict, is, entry::inputMode::MERGE);
157}
158
159
161(
162 dictionary& parentDict,
164)
165{
166 return entry::New(parentDict, is, entry::inputMode::OVERWRITE);
167}
168
169
171(
172 dictionary& parentDict,
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:57
bool found(const word &key) const
Same as contains().
Definition Enum.H:480
EnumType get(const word &enumName) const
The enumeration corresponding to the given name.
Definition Enum.C:68
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
static void resetInputMode()
Reset the globalInputMode to merge.
Definition entry.C:54
static bool New(dictionary &parentDict, Istream &is, const inputMode inpMode=inputMode::GLOBAL, const int endChar=0)
Construct from an Istream and insert into the dictionary.
Definition entryIO.C:98
static inputMode globalInputMode
The current global input-mode.
Definition entry.H:144
inputMode
The input mode options.
Definition entry.H:75
@ OVERWRITE
Keep last entry. Silently remove previous ones.
Definition entry.H:77
@ PROTECT
Keep initial entry. Silently ignore subsequent ones.
Definition entry.H:78
@ WARN
Keep initial entry. Warn about subsequent ones.
Definition entry.H:79
@ MERGE
Merge sub-dictionaries when possible.
Definition entry.H:76
@ ERROR
FatalError for duplicate entries.
Definition entry.H:80
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition error.H:74
Temporarily change inputMode to protect for the following entry.
Definition inputMode.H:99
static bool execute(dictionary &parentDict, Istream &is)
Execute in a sub-dict context.
Definition inputMode.C:134
Temporarily change inputMode to error for the following entry.
Definition inputMode.H:179
static bool execute(dictionary &parentDict, Istream &is)
Execute in a sub-dict context.
Definition inputMode.C:174
Temporarily change inputMode to merge for the following entry.
Definition inputMode.H:119
static bool execute(dictionary &parentDict, Istream &is)
Execute in a sub-dict context.
Definition inputMode.C:144
Temporarily change inputMode to overwrite for the following entry.
Definition inputMode.H:139
static bool execute(dictionary &parentDict, Istream &is)
Execute in a sub-dict context.
Definition inputMode.C:154
Temporarily change inputMode to warn for the following entry.
Definition inputMode.H:159
static bool execute(dictionary &parentDict, Istream &is)
Execute in a sub-dict context.
Definition inputMode.C:164
Specify the global input mode when reading further dictionaries, expects a single word to follow.
Definition inputMode.H:74
static bool execute(dictionary &unused, Istream &is)
Change the global input-mode.
Definition inputMode.C:107
static const Enum< entry::inputMode > selectableNames
Text representations of the selectable input modes.
Definition inputMode.H:80
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
A class for handling words, derived from Foam::string.
Definition word.H:66
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for containing a functionEntry.
Definition calcEntry.C:33
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519