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 -------------------------------------------------------------------------------
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 "functionEntry.H"
30 #include "IOstreams.H"
31 #include "ISstream.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
38  (
39  functionEntry,
40  execute,
41  dictionaryIstream
42  );
43 
45  (
46  functionEntry,
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()
128  << exit(FatalError);
129  }
130 
131  return mfuncPtr(parentDict, is);
132 }
133 
134 
136 (
137  const word& functionName,
138  const dictionary& parentDict,
140  Istream& is
141 )
142 {
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()
167  << exit(FatalError);
168  }
169 
170  return mfuncPtr(parentDict, entry, is);
171 }
172 
173 
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 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::primitiveEntry
A keyword and a list of tokens comprise a primitiveEntry. A primitiveEntry can be read,...
Definition: primitiveEntry.H:63
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionEntry::write
virtual void write(Ostream &os) const
Write.
Definition: functionEntry.C:174
s
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))
Definition: gmvOutputSpray.H:25
Foam::token::stringToken
const string & stringToken() const
Return const reference to the string contents.
Definition: tokenI.H:689
ISstream.H
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::IOstream::fatalCheck
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:64
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::IOstream::lineNumber
label lineNumber() const noexcept
Const access to the current stream line number.
Definition: IOstream.H:318
Foam::functionEntry::functionEntry
functionEntry(const functionEntry &)=delete
No copy construct.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
functionEntry.H
Foam::dictionary::name
const fileName & name() const noexcept
The dictionary name.
Definition: dictionaryI.H:48
Foam::OBJstream::write
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::defineMemberFunctionSelectionTable
defineMemberFunctionSelectionTable(edgeMesh, write, fileExtension)
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::IOstream::relativeName
fileName relativeName() const
Return the name of the stream relative to the current case.
Definition: IOstream.C:52
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::functionEntry::continueReadUntilRightBrace
static bool continueReadUntilRightBrace(Istream &is, std::string &str, const bool stripComments=true)
Slurp a string until a closing '}' is found.
Definition: functionEntry.C:66
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionEntry::readLine
static token readLine(const word &key, Istream &is)
Read line and return as a string token.
Definition: functionEntry.C:56
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::functionEntry::execute
static bool execute(const word &functionName, dictionary &parentDict, Istream &is)
Execute the functionEntry in a sub-dict context.
Definition: functionEntry.C:98