entry.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) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2017-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "entry.H"
30 #include "dictionary.H"
31 #include "StringStream.H"
32 #include "JobInfo.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
37 (
38  Foam::debug::infoSwitch("disableFunctionEntries", 0)
39 );
40 
41 
43 
44 
45 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
46 
48 (
49  const IOstream& is,
50  const std::string& msg
51 )
52 {
53  std::cerr
54  << "--> FOAM Warning :\n"
55  << " Reading \"" << is.relativeName()
56  << "\" at line " << is.lineNumber() << '\n'
57  << " " << msg << std::endl;
58 }
59 
60 
62 {
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68 
69 Foam::entry::entry(const keyType& keyword)
70 :
71  IDLList<entry>::link(),
72  keyword_(keyword)
73 {}
74 
75 
77 :
78  IDLList<entry>::link(),
79  keyword_(e.keyword_)
80 {}
81 
82 
84 {
85  return clone(dictionary::null);
86 }
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
91 void Foam::entry::raiseBadInput(const ITstream& is) const
92 {
93  const word& keyword = keyword_;
94 
95  // Can use FatalIOError instead of SafeFatalIOError
96  // since predicate checks are not used at the earliest stages
98  (
99  "", // functionName
100  "", // sourceFileName
101  0, // sourceFileLineNumber
102  this->relativeName(), // ioFileName
103  is.lineNumber() // ioStartLineNumber
104  )
105  << "Entry '" << keyword << "' with invalid input" << nl << nl
106  << exit(FatalIOError);
107 }
108 
109 
111 {
112  const word& keyword = keyword_;
113 
114  if (is.nRemainingTokens())
115  {
116  const label remaining = is.nRemainingTokens();
117 
118  // Similar to SafeFatalIOError
120  {
121  OSstream& err =
123  (
124  "", // functionName
125  "", // sourceFileName
126  0, // sourceFileLineNumber
127  this->relativeName(), // ioFileName
128  is.lineNumber() // ioStartLineNumber
129  );
130 
131  err << "Entry '" << keyword << "' has "
132  << remaining << " excess tokens in stream" << nl << nl
133  << " ";
134  is.writeList(err, 0);
135 
136  err << exit(FatalIOError);
137  }
138  else
139  {
140  std::cerr
141  << nl
142  << "--> FOAM FATAL IO ERROR:" << nl;
143 
144  std::cerr
145  << "Entry '" << keyword << "' has "
146  << remaining << " excess tokens in stream" << nl << nl;
147 
148  std::cerr
149  << "file: " << this->relativeName()
150  << " at line " << is.lineNumber() << '.' << nl
151  << std::endl;
152 
153  std::exit(1);
154  }
155  }
156  else if (!is.size())
157  {
158  // Similar to SafeFatalIOError
160  {
162  (
163  "", // functionName
164  "", // sourceFileName
165  0, // sourceFileLineNumber
166  this->relativeName(), // ioFileName
167  is.lineNumber() // ioStartLineNumber
168  )
169  << "Entry '" << keyword
170  << "' had no tokens in stream" << nl << nl
171  << exit(FatalIOError);
172  }
173  else
174  {
175  std::cerr
176  << nl
177  << "--> FOAM FATAL IO ERROR:" << nl
178  << "Entry '" << keyword
179  << "' had no tokens in stream" << nl << nl;
180 
181  std::cerr
182  << "file: " << this->relativeName()
183  << " at line " << is.lineNumber() << '.' << nl
184  << std::endl;
185 
186  std::exit(1);
187  }
188  }
189 }
190 
191 
192 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
193 
195 {
196  if (this == &e)
197  {
198  return; // Self-assignment is a no-op
199  }
200 
201  keyword_ = e.keyword_;
202 }
203 
204 
205 bool Foam::entry::operator==(const entry& e) const
206 {
207  if (this == &e)
208  {
209  return true;
210  }
211  if (keyword_ != e.keyword_)
212  {
213  return false;
214  }
215 
216  // Compare contents (as strings)
217 
218  OStringStream oss1;
219  oss1 << *this;
220 
221  OStringStream oss2;
222  oss2 << e;
223 
224  return oss1.str() == oss2.str();
225 }
226 
227 
228 bool Foam::entry::operator!=(const entry& e) const
229 {
230  return !operator==(e);
231 }
232 
233 
234 // ************************************************************************* //
Foam::entry::entry
entry(const keyType &keyword)
Construct from keyword.
Definition: entry.C:69
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::entry::globalInputMode
static inputMode globalInputMode
The current global input-mode.
Definition: entry.H:130
Foam::IOstream
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition: IOstream.H:79
Foam::IOstream::lineNumber
label lineNumber() const noexcept
Const access to the current stream line number.
Definition: IOstream.H:318
StringStream.H
Input/output from string buffers.
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::entry::inputMode
inputMode
The input mode options.
Definition: entry.H:76
entry.H
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:392
Foam::debug::infoSwitch
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
Definition: debug.C:231
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:68
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::ITstream
An input stream of tokens.
Definition: ITstream.H:52
Foam::entry::operator=
void operator=(const entry &e)
Definition: entry.C:194
Foam::OSstream
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:54
Foam::entry::resetInputMode
static void resetInputMode()
Reset the globalInputMode to merge.
Definition: entry.C:61
Foam::entry::reportReadWarning
static void reportReadWarning(const IOstream &, const std::string &)
Report a read warning (on std::cerr)
Definition: entry.C:48
Foam::ILList
Template class for intrusive linked lists.
Definition: ILList.H:52
Foam::IOstream::relativeName
fileName relativeName() const
Return the name of the stream relative to the current case.
Definition: IOstream.C:52
Foam::entry::disableFunctionEntries
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
Definition: entry.H:127
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::Detail::StringStreamAllocator::str
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:88
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::entry::inputMode::MERGE
Merge sub-dictionaries when possible.
Foam::entry::clone
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:83
Foam::entry::operator!=
bool operator!=(const entry &e) const
Definition: entry.C:228
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::JobInfo::constructed
static bool constructed
Global value for constructed job info.
Definition: JobInfo.H:101
Foam::OStringStream
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:227
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::entry::operator==
bool operator==(const entry &e) const
Definition: entry.C:205
dictionary.H
JobInfo.H
Foam::ITstream::nRemainingTokens
label nRemainingTokens() const noexcept
Number of tokens remaining.
Definition: ITstream.H:214
Foam::entry::checkITstream
void checkITstream(const ITstream &is) const
Definition: entry.C:110