inputModeEntry.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "inputModeEntry.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 Foam::functionEntries::inputModeEntry::inputMode
32  Foam::functionEntries::inputModeEntry::mode_(MERGE);
33 
34 namespace Foam
35 {
36 namespace functionEntries
37 {
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 (
48  const label lineNumber,
49  const dictionary& parentDict,
50  Istream& is
51 )
52 :
53  functionEntry(typeName, lineNumber, parentDict, is, token(is))
54 {
55  if (!operator[](0).isWord())
56  {
58  << "Expected a word, found " << operator[](0)
59  << " while reading function " << typeName
60  << exit(FatalIOError);
61  }
62 }
63 
64 
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 
68 {
69  mode_ = MERGE;
70 }
71 
72 
74 {
75  return mode_ == MERGE;
76 }
77 
78 
80 {
81  return mode_ == OVERWRITE;
82 }
83 
84 
86 {
87  return mode_ == PROTECT;
88 }
89 
91 {
92  return mode_ == ERROR;
93 }
94 
95 
97 (
98  dictionary& contextDict,
99  Istream& is
100 )
101 {
102  clear();
103 
104  const word& mode = operator[](0).wordToken();
105 
106  if (mode == "merge" || mode == "default")
107  {
108  mode_ = MERGE;
109  }
110  else if (mode == "overwrite")
111  {
112  mode_ = OVERWRITE;
113  }
114  else if (mode == "protect")
115  {
116  mode_ = PROTECT;
117  }
118  else if (mode == "warn")
119  {
120  mode_ = WARN;
121  }
122  else if (mode == "error")
123  {
124  mode_ = ERROR;
125  }
126  else
127  {
129  << "unsupported input mode '" << mode
130  << "' ... defaulting to 'merge'"
131  << endl;
132  }
133 
134  return true;
135 }
136 
137 
138 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
T & operator[](const label)
Return element of UList.
Definition: UListI.H:167
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Specify the input mode when reading dictionaries, expects a single word to follow.
static bool overwrite()
Return true if the inputMode is overwrite.
static bool protect()
Return true if the inputMode is protect.
static bool merge()
Return true if the inputMode is merge.
static bool error()
Return true if the inputMode is error.
static void clear()
Reset the inputMode to default (ie, merge)
virtual bool execute(dictionary &contextDict, Istream &)
Expand the functionEntry into the contextDict.
inputModeEntry(const label lineNumber, const dictionary &parentDict, Istream &is)
Construct from line number, dictionary and Istream.
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:66
A token holds items read from Istream.
Definition: token.H:74
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling words, derived from string.
Definition: word.H:63
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
tUEqn clear()
#define WarningInFunction
Report a warning using Foam::Warning.
defineFunctionTypeNameAndDebug(includeFvConstraintEntry, 0)
addToRunTimeSelectionTable(functionEntry, includeFvConstraintEntry, dictionary)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
mode_t mode(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file mode.
Definition: POSIX.C:461
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
IOerror FatalIOError