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-------------------------------------------------------------------------------
11License
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{
63 globalInputMode = inputMode::MERGE;
64}
65
66
67// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68
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
91void 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
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
229{
230 return !operator==(e);
231}
232
233
234// ************************************************************************* //
Input/output from string buffers.
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:88
Template class for intrusive linked lists.
Definition: ILList.H:69
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition: IOstream.H:82
label lineNumber() const noexcept
Const access to the current stream line number.
Definition: IOstream.H:318
fileName relativeName() const
Return the name of the stream relative to the current case.
Definition: IOstream.C:52
An input stream of tokens.
Definition: ITstream.H:56
label nRemainingTokens() const noexcept
Number of tokens remaining.
Definition: ITstream.H:214
static bool constructed
Global value for constructed job info.
Definition: JobInfo.H:101
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:57
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:231
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
Definition: UListIO.C:79
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
static void resetInputMode()
Reset the globalInputMode to merge.
Definition: entry.C:61
void operator=(const entry &e)
Definition: entry.C:194
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition: entry.C:83
void checkITstream(const ITstream &is) const
Definition: entry.C:110
static inputMode globalInputMode
The current global input-mode.
Definition: entry.H:130
inputMode
The input mode options.
Definition: entry.H:77
static void reportReadWarning(const IOstream &, const std::string &)
Report a read warning (on std::cerr)
Definition: entry.C:48
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
Definition: entry.H:127
A class for handling keywords in dictionaries.
Definition: keyType.H:71
friend bool operator!=(const refineCell &rc1, const refineCell &rc2)
Definition: refineCell.H:106
friend bool operator==(const refineCell &rc1, const refineCell &rc2)
Definition: refineCell.H:97
A class for handling words, derived from Foam::string.
Definition: word.H:68
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
Definition: debug.C:231
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
volScalarField & e
Definition: createFields.H:11