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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "functionEntry.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
33  (
34  functionEntry,
35  execute,
36  dictionaryIstream
37  );
38 
40  (
41  functionEntry,
42  execute,
43  primitiveEntryIstream
44  );
45 }
46 
47 
48 // * * * * * * * * * * * * Member Function Selectors * * * * * * * * * * * * //
49 
51 (
52  const word& functionName,
53  dictionary& parentDict,
54  Istream& is
55 )
56 {
57  is.fatalCheck
58  (
59  "functionEntry::execute"
60  "(const word& functionName, dictionary& parentDict, Istream&)"
61  );
62 
63  if (!executedictionaryIstreamMemberFunctionTablePtr_)
64  {
65  cerr<< "functionEntry::execute"
66  << "(const word&, dictionary&, Istream&)"
67  << " not yet initialized, function = "
68  << functionName.c_str() << std::endl;
69 
70  // Return true to keep reading
71  return true;
72  }
73 
74  executedictionaryIstreamMemberFunctionTable::iterator mfIter =
75  executedictionaryIstreamMemberFunctionTablePtr_->find(functionName);
76 
77  if (mfIter == executedictionaryIstreamMemberFunctionTablePtr_->end())
78  {
80  << "Unknown functionEntry '" << functionName
81  << "' in " << is.name() << " near line " << is.lineNumber()
82  << nl << nl
83  << "Valid functionEntries are :" << endl
84  << executedictionaryIstreamMemberFunctionTablePtr_->toc()
85  << exit(FatalError);
86  }
87 
88  return mfIter()(parentDict, is);
89 }
90 
91 
93 (
94  const word& functionName,
95  const dictionary& parentDict,
96  primitiveEntry& entry,
97  Istream& is
98 )
99 {
100  is.fatalCheck
101  (
102  "functionEntry::execute"
103  "(const word&, const dictionary&, primitiveEntry&, Istream&)"
104  );
105 
106  if (!executeprimitiveEntryIstreamMemberFunctionTablePtr_)
107  {
108  cerr<< "functionEntry::execute"
109  << "(const word&, const dictionary&, primitiveEntry&, Istream&)"
110  << " not yet initialized, function = "
111  << functionName.c_str() << std::endl;
112 
113  // return true to keep reading anyhow
114  return true;
115  }
116 
117  executeprimitiveEntryIstreamMemberFunctionTable::iterator mfIter =
118  executeprimitiveEntryIstreamMemberFunctionTablePtr_->find(functionName);
119 
120  if (mfIter == executeprimitiveEntryIstreamMemberFunctionTablePtr_->end())
121  {
123  << "Unknown functionEntry '" << functionName
124  << "' in " << is.name() << " near line " << is.lineNumber()
125  << nl << nl
126  << "Valid functionEntries are :" << endl
127  << executeprimitiveEntryIstreamMemberFunctionTablePtr_->toc()
128  << exit(FatalError);
129  }
130 
131  return mfIter()(parentDict, entry, is);
132 }
133 
134 
135 // ************************************************************************* //
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
A keyword and a list of tokens is a &#39;primitiveEntry&#39;. An primitiveEntry can be read, written and printed, and the types and values of its tokens analysed.
A class for handling words, derived from string.
Definition: word.H:59
static bool execute(const word &functionName, dictionary &parentDict, Istream &)
Execute the functionEntry in a sub-dict context.
Definition: functionEntry.C:51
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:297
static const char nl
Definition: Ostream.H:262
label lineNumber() const
Return current stream line number.
Definition: IOstream.H:438
defineMemberFunctionSelectionTable(edgeMesh, write, fileExtension)
void fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:105
Namespace for OpenFOAM.