inputModeEntry.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 | Copyright (C) 2011-2015 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 
43 
44 namespace Foam
45 {
46 namespace functionEntries
47 {
49  (
50  functionEntry,
51  inputModeEntry,
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
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 // ************************************************************************* //
Foam::functionEntries::inputModeEntry::overwrite
static bool overwrite()
Return true if the inputMode is overwrite.
Definition: inputModeEntry.C:121
inputModeEntry.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::functionEntries::inputModeEntry::MERGE
@ MERGE
Definition: inputModeEntry.H:71
Foam::functionEntries::inputModeEntry::protect
static bool protect()
Return true if the inputMode is protect.
Definition: inputModeEntry.C:127
Foam::functionEntries::inputModeEntry::error
static bool error()
Return true if the inputMode is error.
Definition: inputModeEntry.C:132
Foam::functionEntries::inputModeEntry::clear
static void clear()
Reset the inputMode to default (ie, merge)
Definition: inputModeEntry.C:109
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mode
mode_t mode(const fileName &)
Return the file mode.
Definition: POSIX.C:573
Foam::functionEntries::inputModeEntry::mode_
static inputMode mode_
The current input mode.
Definition: inputModeEntry.H:79
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
addToMemberFunctionSelectionTable.H
Macros for easy insertion into member function selection tables.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::functionEntries::inputModeEntry::inputMode
inputMode
The input mode options.
Definition: inputModeEntry.H:69
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::functionEntries::addToMemberFunctionSelectionTable
addToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream)
Foam::functionEntries::inputModeEntry::PROTECT
@ PROTECT
Definition: inputModeEntry.H:73
dictionary.H
Foam::functionEntries::inputModeEntry::WARN
@ WARN
Definition: inputModeEntry.H:74
Foam::functionEntries::inputModeEntry::OVERWRITE
@ OVERWRITE
Definition: inputModeEntry.H:72
Foam::functionEntries::inputModeEntry::ERROR
@ ERROR
Definition: inputModeEntry.H:75
Foam::functionEntries::inputModeEntry::setMode
static void setMode(Istream &)
Read the mode as a word and set enum appropriately.
Definition: inputModeEntry.C:61
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::functionEntries::inputModeEntry::merge
static bool merge()
Return true if the inputMode is merge.
Definition: inputModeEntry.C:115
Foam::functionEntries::inputModeEntry::execute
static bool execute(dictionary &parentDict, Istream &)
Execute the functionEntry in a sub-dict context.
Definition: inputModeEntry.C:99