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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "functionEntry.H"
29 #include "IOstreams.H"
30 #include "ISstream.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
37  (
38  functionEntry,
39  execute,
40  dictionaryIstream
41  );
42 
44  (
45  functionEntry,
46  execute,
47  primitiveEntryIstream
48  );
49 } // End namespace Foam
50 
51 
52 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
53 
55 {
56  string s;
57  dynamic_cast<ISstream&>(is).getLine(s);
58 
59  return token(string(key+s), is.lineNumber());
60 }
61 
62 
63 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
64 
65 Foam::functionEntry::functionEntry
66 (
67  const word& key,
68  const dictionary& dict,
69  Istream& is
70 )
71 :
73  (
74  word(key+dict.name()+Foam::name(is.lineNumber())),
75  readLine(key, is)
76  )
77 {}
78 
79 
80 // * * * * * * * * * * * * Member Function Selectors * * * * * * * * * * * * //
81 
83 (
84  const word& functionName,
85  dictionary& parentDict,
86  Istream& is
87 )
88 {
90 
91  if (!executedictionaryIstreamMemberFunctionTablePtr_)
92  {
93  cerr<< FUNCTION_NAME << nl
94  << "Not yet initialized, function = "
95  << functionName.c_str() << std::endl;
96 
97  // Return true to keep reading
98  return true;
99  }
100 
101  auto mfIter =
102  executedictionaryIstreamMemberFunctionTablePtr_->cfind(functionName);
103 
104  if (!mfIter.found())
105  {
107  << "Unknown functionEntry '" << functionName
108  << "' in " << is.name() << " near line " << is.lineNumber()
109  << nl << nl
110  << "Valid functionEntries :" << endl
111  << executedictionaryIstreamMemberFunctionTablePtr_->sortedToc()
112  << exit(FatalError);
113  }
114 
115  return mfIter()(parentDict, is);
116 }
117 
118 
120 (
121  const word& functionName,
122  const dictionary& parentDict,
124  Istream& is
125 )
126 {
128 
129  if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_)
130  {
131  cerr<< FUNCTION_NAME << nl
132  << "Not yet initialized, function = "
133  << functionName.c_str() << std::endl;
134 
135  // Return true to keep reading anyhow
136  return true;
137  }
138 
139  auto mfIter =
140  executeprimitiveEntryIstreamMemberFunctionTablePtr_->cfind
141  (
142  functionName
143  );
144 
145  if (!mfIter.found())
146  {
148  << "Unknown functionEntry '" << functionName
149  << "' in " << is.name() << " near line " << is.lineNumber()
150  << nl << nl
151  << "Valid functionEntries :" << endl
152  << executeprimitiveEntryIstreamMemberFunctionTablePtr_->sortedToc()
153  << exit(FatalError);
154  }
155 
156  return mfIter()(parentDict, entry, is);
157 }
158 
159 
161 {
162  // Contents should be single string token
163  const token& tok = operator[](0);
164  const string& s = tok.stringToken();
165 
166  // Write character-wise for literal output
167  for (size_t i = 0; i < s.size(); ++i)
168  {
169  os.write(s[i]);
170  }
171 
172  os << nl;
173 }
174 
175 
176 // ************************************************************************* //
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:62
Foam::functionEntry::write
virtual void write(Ostream &os) const
Write.
Definition: functionEntry.C:160
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:644
ISstream.H
Foam::IOstream::fatalCheck
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:57
Foam::ISstream
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:55
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
functionEntry.H
Foam::dictionary::name
const fileName & name() const
The dictionary name.
Definition: dictionary.H:446
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::IOstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.C:39
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:121
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
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:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::functionEntry::readLine
static token readLine(const word &key, Istream &is)
Read line and return as a string token.
Definition: functionEntry.C:54
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::IOstream::lineNumber
label lineNumber() const
Const access to the current stream line number.
Definition: IOstream.H:309
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:83