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-2024 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"
27 #include "dictionary.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 const Foam::word Foam::functionEntries::inputModeEntry::typeName
33 (
34  Foam::functionEntries::inputModeEntry::typeName_()
35 );
36 
37 // Don't lookup the debug switch here as the debug switch dictionary
38 // might include inputModeEntries
39 int Foam::functionEntries::inputModeEntry::debug(0);
40 
41 Foam::functionEntries::inputModeEntry::inputMode
42  Foam::functionEntries::inputModeEntry::mode_(MERGE);
43 
44 namespace Foam
45 {
46 namespace functionEntries
47 {
49  (
52  execute,
53  dictionaryIstream
54  );
55 }
56 }
57 
58 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
59 
60 // we could combine this into execute() directly, but leave it here for now
61 void Foam::functionEntries::inputModeEntry::setMode(Istream& is)
62 {
63  clear();
64 
65  word mode(is);
66 
67  if (mode == "merge" || mode == "default")
68  {
69  mode_ = MERGE;
70  }
71  else if (mode == "overwrite")
72  {
73  mode_ = OVERWRITE;
74  }
75  else if (mode == "protect")
76  {
77  mode_ = PROTECT;
78  }
79  else if (mode == "warn")
80  {
81  mode_ = WARN;
82  }
83  else if (mode == "error")
84  {
85  mode_ = ERROR;
86  }
87  else
88  {
90  << "unsupported input mode '" << mode
91  << "' ... defaulting to 'merge'"
92  << endl;
93  }
94 }
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
100 (
101  dictionary& parentDict,
102  Istream& is
103 )
104 {
105  setMode(is);
106  return true;
107 }
108 
109 
111 {
112  mode_ = MERGE;
113 }
114 
115 
117 {
118  return mode_ == MERGE;
119 }
120 
121 
123 {
124  return mode_ == OVERWRITE;
125 }
126 
127 
129 {
130  return mode_ == PROTECT;
131 }
132 
134 {
135  return mode_ == ERROR;
136 }
137 
138 
139 // ************************************************************************* //
Macros for easy insertion into member function selection tables.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
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 execute(dictionary &parentDict, Istream &)
Execute the functionEntry in a sub-dict context.
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)
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:66
A class for handling words, derived from string.
Definition: word.H:62
#define WarningInFunction
Report a warning using Foam::Warning.
addToMemberFunctionSelectionTable(functionEntry, includeFvConstraintEntry, execute, dictionaryIstream)
Namespace for OpenFOAM.
mode_t mode(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file mode.
Definition: POSIX.C:461
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258