Loading...
Searching...
No Matches
functionEntry.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-2016 OpenFOAM Foundation
9 Copyright (C) 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 "functionEntry.H"
30#include "IOstreams.H"
31#include "ISstream.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
38 (
40 execute,
41 dictionaryIstream
42 );
43
45 (
47 execute,
48 primitiveEntryIstream
49 );
50
51} // End namespace Foam
52
53
54// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
55
57{
58 string s;
59 dynamic_cast<ISstream&>(is).getLine(s);
60
61 return token(string(key+s), is.lineNumber());
62}
63
64
66(
67 Istream& is,
68 std::string& str,
69 const bool stripComments
70)
71{
72 return
73 dynamic_cast<ISstream&>(is)
74 .continueReadUntilRightBrace(str, stripComments);
75}
76
77
78// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79
81(
82 const word& key,
83 const dictionary& dict,
84 Istream& is
85)
86:
88 (
89 word(key + dict.name() + Foam::name(is.lineNumber())),
90 readLine(key, is)
91 )
92{}
93
94
95// * * * * * * * * * * * * Member Function Selectors * * * * * * * * * * * * //
96
98(
99 const word& functionName,
100 dictionary& parentDict,
101 Istream& is
102)
103{
105
106 if (!executedictionaryIstreamMemberFunctionTablePtr_)
107 {
108 std::cerr
109 << FUNCTION_NAME << nl
110 << "Not yet initialized, function = "
111 << functionName.c_str() << std::endl;
112
113 // Return true to keep reading
114 return true;
115 }
116
117 auto* mfuncPtr =
118 executedictionaryIstreamMemberFunctionTable(functionName);
119
120 if (!mfuncPtr)
121 {
123 << "Unknown functionEntry '" << functionName
124 << "' in " << is.relativeName()
125 << " near line " << is.lineNumber() << nl << nl
126 << "Valid functionEntries :" << nl
127 << executedictionaryIstreamMemberFunctionTablePtr_->sortedToc()
129 }
130
131 return mfuncPtr(parentDict, is);
132}
133
134
136(
137 const word& functionName,
138 const dictionary& parentDict,
139 primitiveEntry& entry,
140 Istream& is
141)
142{
143 is.fatalCheck(FUNCTION_NAME);
144
145 if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_)
146 {
147 std::cerr
148 << FUNCTION_NAME << nl
149 << "Not yet initialized, function = "
150 << functionName.c_str() << std::endl;
151
152 // Return true to keep reading anyhow
153 return true;
154 }
155
156 auto* mfuncPtr =
157 executeprimitiveEntryIstreamMemberFunctionTable(functionName);
158
159 if (!mfuncPtr)
160 {
162 << "Unknown functionEntry '" << functionName
163 << "' in " << is.relativeName()
164 << " near line " << is.lineNumber() << nl << nl
165 << "Valid functionEntries :" << nl
166 << executeprimitiveEntryIstreamMemberFunctionTablePtr_->sortedToc()
168 }
169
170 return mfuncPtr(parentDict, entry, is);
171}
172
173
174void Foam::functionEntry::write(Ostream& os) const
175{
176 // Contents should be single string token
177 const token& tok = operator[](0);
178 const string& s = tok.stringToken();
179
180 // Write character-wise for literal output
181 for (size_t i = 0; i < s.size(); ++i)
182 {
183 os.write(s[i]);
184 }
185
186 os << nl;
187}
188
189
190// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
label lineNumber() const noexcept
Const access to the current stream line number.
Definition IOstream.H:409
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:51
fileName relativeName() const
Return the name of the stream relative to the current case.
Definition IOstream.C:39
Generic input stream using a standard (STL) stream.
Definition ISstream.H:54
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
T & operator[](const label i)
Return element of UList.
Definition UListI.H:363
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
static bool continueReadUntilRightBrace(Istream &is, std::string &str, const bool stripComments=true)
Slurp a string until a closing '}' is found.
virtual void write(Ostream &os) const
Write.
functionEntry(const functionEntry &)=delete
No copy construct.
static token readLine(const word &key, Istream &is)
Read line and return as a string token.
static bool execute(const word &functionName, dictionary &parentDict, Istream &is)
Execute the functionEntry in a sub-dict context.
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
primitiveEntry(const keyType &key)
Construct from keyword and no tokens.
virtual const fileName & name() const
Return the token stream name.
virtual const dictionary & dict() const
This entry is not a dictionary, calling this function generates a FatalError.
A token holds an item read from Istream.
Definition token.H:70
const string & stringToken() const
Return const reference to the string contents.
Definition tokenI.H:1076
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define defineMemberFunctionSelectionTable(baseType, funcName, argNames)
Define run-time selection table.
#define FUNCTION_NAME
Namespace for OpenFOAM.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
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
dictionary dict