Loading...
Searching...
No Matches
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-2024 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 "SpanStream.H"
32#include "JobInfo.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
37(
38 Foam::debug::infoSwitch("disableFunctionEntries", 0)
39);
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
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
110void Foam::entry::checkITstream(const ITstream& is) const
111{
112 const label remaining = (is.size() ? is.nRemainingTokens() : -100);
113
114 if (!remaining)
115 {
116 return;
117 }
118
119 const word& keyword = keyword_;
120
121 // Similar to SafeFatalIOError
123 {
124 OSstream& err =
126 (
127 "", // functionName
128 "", // sourceFileName
129 0, // sourceFileLineNumber
130 this->relativeName(), // ioFileName
131 is.lineNumber() // ioStartLineNumber
132 );
133
134 if (remaining > 0)
135 {
136 err
137 << "Entry '" << keyword
138 << "' has " << remaining << " excess tokens in stream"
139 << nl << nl
140 << " ";
141 is.writeList(err, 0); // <- flatOutput
142 }
143 else
144 {
145 err
146 << "Entry '" << keyword
147 << "' had no tokens in stream"
148 << nl << nl;
149 }
150
151 err << exit(FatalIOError);
152 }
153 else
154 {
155 // Not yet constructed
156
157 std::cerr
158 << nl
159 << "--> FOAM FATAL IO ERROR:" << nl;
160
161 if (remaining > 0)
162 {
163 std::cerr
164 << "Entry '" << keyword << "' has "
165 << remaining << " excess tokens in stream" << nl << nl;
166 }
167 else
168 {
169 std::cerr
170 << "Entry '" << keyword
171 << "' had no tokens in stream" << nl << nl;
172 }
173
174 std::cerr
175 << "file: " << this->relativeName()
176 << " at line " << is.lineNumber() << '.' << nl
177 << std::endl;
178
179 std::exit(1);
180 }
181}
182
183
184// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
185
186void Foam::entry::operator=(const entry& e)
187{
188 if (this == &e)
189 {
190 return; // Self-assignment is a no-op
191 }
192
193 keyword_ = e.keyword_;
194}
195
196
197bool Foam::entry::operator==(const entry& e) const
198{
199 if (this == &e)
200 {
201 return true;
202 }
203 if (keyword_ != e.keyword_)
204 {
205 return false;
206 }
207
208 // Compare contents (as strings)
209 OCharStream content1;
210 content1 << *this;
211
212 OCharStream content2;
213 content2 << e;
214
215 return
216 (
217 content1.view().size() == content2.view().size()
218 &&
219 std::equal
220 (
221 content1.view().begin(),
222 content1.view().end(),
223 content2.view().begin()
224 )
225 );
226}
227
228
229bool Foam::entry::operator!=(const entry& e) const
230{
231 return !operator==(e);
232}
233
234
235// ************************************************************************* //
Input/output streams with (internal or external) character storage.
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition IOstream.H:85
label lineNumber() const noexcept
Const access to the current stream line number.
Definition IOstream.H:409
fileName relativeName() const
Return the name of the stream relative to the current case.
Definition IOstream.C:39
An input stream of tokens.
Definition ITstream.H:56
label nRemainingTokens() const noexcept
Number of tokens remaining.
Definition ITstream.H:432
static bool constructed
Global value for constructed job info.
Definition JobInfo.H:115
An OSstream with internal List storage.
auto view() const
A string_view of buffer contents.
Generic output stream using a standard (STL) stream.
Definition OSstream.H:53
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
Definition UListIO.C:90
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition dictionary.H:487
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
entry(const keyType &keyword)
Construct from keyword.
Definition entry.C:62
static void resetInputMode()
Reset the globalInputMode to merge.
Definition entry.C:54
void operator=(const entry &e)
Definition entry.C:179
virtual autoPtr< entry > clone() const
Construct on freestore as copy.
Definition entry.C:76
bool operator!=(const entry &e) const
Definition entry.C:222
void checkITstream(const ITstream &is) const
Check after reading if the input token stream has unconsumed tokens remaining or if there were no tok...
Definition entry.C:103
virtual autoPtr< entry > clone(const dictionary &parentDict) const =0
Construct on freestore as copy with reference to the.
static inputMode globalInputMode
The current global input-mode.
Definition entry.H:144
inputMode
The input mode options.
Definition entry.H:75
@ MERGE
Merge sub-dictionaries when possible.
Definition entry.H:76
virtual fileName relativeName() const =0
Return the entry name relative to the current case.
const keyType & keyword() const noexcept
Return keyword.
Definition entry.H:231
static void reportReadWarning(const IOstream &, const std::string &)
Report a read warning (on std::cerr).
Definition entry.C:41
bool operator==(const entry &e) const
Definition entry.C:190
static int disableFunctionEntries
Enable or disable use of function entries and variable expansions.
Definition entry.H:139
A class for handling keywords in dictionaries.
Definition keyType.H:69
A class for handling words, derived from Foam::string.
Definition word.H:66
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
Definition debug.C:228
ILList< DLListBase, T > IDLList
Definition IDLList.H:39
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
volScalarField & e