codeBlockDictEntry.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2025-2026 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 "codeBlockDictEntry.H"
27 #include "codeBlockEntry.H"
28 #include "OSspecific.H"
29 #include "codeDict.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionEntries
37 {
39 
41 }
42 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 bool Foam::functionEntries::codeBlockDictEntry::resultStream
48 (
49  dictionary& dict,
50  Istream& is
51 )
52 {
53  if (debug)
54  {
55  Info<< "Expanding " << typeName << " at line " << is.lineNumber()
56  << " in file " << dict.name() << endl;
57  }
58 
59  // Construct the name of the function
60  // corresponding to this codeBlockDictEntry
61  const word functionName
62  (
63  codeBlockPtr_->codeBlockName_ + "_" + Foam::name(index_)
64  );
65 
66  // Find the function handle in the library
67  const codeDict::codeDictFunctionType function =
68  reinterpret_cast<codeDict::codeDictFunctionType>
69  (
70  dlSym(codeBlockPtr_->lib_, functionName)
71  );
72 
73  if (!function)
74  {
76  << "Failed looking up symbol " << functionName
77  << " in library " << codeBlockPtr_->lib_ << exit(FatalIOError);
78  }
79 
80  // Use function to append to contextDict
81  (*function)(dict, is);
82 
83  return true;
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
90 (
91  const label lineNumber,
92  const dictionary& parentDict,
93  Istream& is
94 )
95 :
96  functionEntry(typeName, lineNumber, parentDict),
97  codeBlockPtr_(nullptr),
98  index_(-1)
99 {
100  token t(is);
101 
102  if (t.isUnsignedInteger64())
103  {
104  codeBlockPtr_ =
105  reinterpret_cast<const codeBlockEntry*>(t.unsignedInteger64Token());
106 
107  is.read(t);
108 
109  if (t.isLabel())
110  {
111  index_ = t.labelToken();
112  }
113  else
114  {
116  << "Wrong argument type for " << typeName << nl
117  << " Expected a label but found token " << t
118  << exit(FatalIOError);
119  }
120  }
121  else
122  {
124  << "Wrong argument type for " << typeName << nl
125  << " Expected a unsignedInteger64 but found token " << t
126  << exit(FatalIOError);
127  }
128 }
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
134 (
135  dictionary& contextDict,
136  Istream& is
137 )
138 {
139  return resultStream(contextDict, is);
140 }
141 
142 
144 {}
145 
146 
147 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Macros for easy insertion into run-time selection tables.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
virtual Istream & read(token &)=0
Return next token from stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:111
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
codeBlockDictEntry(const label lineNumber, const dictionary &parentDict, Istream &is)
Construct from line number, dictionary and Istream.
virtual void write(Ostream &) const
Dummy write.
virtual bool execute(dictionary &contextDict, Istream &)
Expand the functionEntry into the contextDict.
Part of the #codeBlock...#codeBlock clause.
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:66
const dictionary & dict() const
This entry is not a dictionary,.
A token holds items read from Istream.
Definition: token.H:74
bool isLabel() const
Definition: tokenI.H:615
bool isUnsignedInteger64() const
Definition: tokenI.H:581
label labelToken() const
Definition: tokenI.H:634
uint64_t unsignedInteger64Token() const
Definition: tokenI.H:590
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
defineFunctionTypeNameAndDebug(includeFvConstraintEntry, 0)
addToRunTimeSelectionTable(functionEntry, includeFvConstraintEntry, dictionary)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
IOerror FatalIOError
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
void * dlSym(void *handle, const std::string &symbol)
Lookup a symbol in a dlopened library using handle to library.
Definition: POSIX.C:1276
static const char nl
Definition: Ostream.H:297
dictionary dict