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-2018 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  if (mode == "merge" || mode == "default")
67  {
68  mode_ = MERGE;
69  }
70  else if (mode == "overwrite")
71  {
72  mode_ = OVERWRITE;
73  }
74  else if (mode == "protect")
75  {
76  mode_ = PROTECT;
77  }
78  else if (mode == "warn")
79  {
80  mode_ = WARN;
81  }
82  else if (mode == "error")
83  {
84  mode_ = ERROR;
85  }
86  else
87  {
89  << "unsupported input mode '" << mode
90  << "' ... defaulting to 'merge'"
91  << endl;
92  }
93 }
94 
95 
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 
99 (
100  dictionary& parentDict,
101  Istream& is
102 )
103 {
104  setMode(is);
105  return true;
106 }
107 
108 
110 {
111  mode_ = MERGE;
112 }
113 
114 
116 {
117  return mode_ == MERGE;
118 }
119 
120 
122 {
123  return mode_ == OVERWRITE;
124 }
125 
126 
128 {
129  return mode_ == PROTECT;
130 }
131 
133 {
134  return mode_ == ERROR;
135 }
136 
137 
138 // ************************************************************************* //
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 keyword definitions, which are a keyword followed by any number of values (e....
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:257