All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
codedBase.H
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) 2011-2024 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 Class
25  Foam::codedBase
26 
27 Description
28  Base class for function objects and boundary conditions using dynamic code
29 
30 SourceFiles
31  codedBase.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef codedBase_H
36 #define codedBase_H
37 
38 #include "dictionary.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 // Forward declaration of classes
46 class dynamicCode;
47 class dynamicCodeContext;
48 class dlLibraryTable;
49 
50 /*---------------------------------------------------------------------------*\
51  Class codedBase Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class codedBase
55 {
56  // Private Member Data
57 
58  //- Name of the dynamically generated CodedType
59  const word codeName_;
60 
61  //- Dictionary contents for the CodedType
62  const dictionary dict_;
63 
64  //- Previously loaded library
65  mutable fileName oldLibPath_;
66 
67 
68  // Private Member Functions
69 
70  //- Global loader/unloader function type
71  typedef void (*loaderFunctionType)(bool);
72 
73  //- Create a code name from the given function name
74  static word codeName(const word& name);
75 
76  //- Load specified library and execute globalFuncName(true)
77  void* loadLibrary
78  (
79  const fileName& libPath,
80  const string& globalFuncName,
81  const dictionary& contextDict
82  ) const;
83 
84  //- Execute globalFuncName(false) and unload specified library
85  void unloadLibrary
86  (
87  const fileName& libPath,
88  const string& globalFuncName,
89  const dictionary& contextDict
90  ) const;
91 
92  //- Create library based on the dynamicCodeContext
93  void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
94 
95 
96 protected:
97 
98  // Protected Member Functions
99 
100  //- Update library as required
101  void updateLibrary() const;
102 
103  //- Name of the dynamically generated CodedType
104  virtual const word& codeName() const;
105 
106  //- Return a description (type + name) for the output
107  virtual string description() const;
108 
109  //- Get the dictionary to initialise the codeContext
110  virtual const dictionary& codeDict() const;
111 
112  //- Get the keywords associated with source code
113  virtual wordList codeKeys() const = 0;
114 
115  //- Get the name of the dictionary variables in the source code
116  virtual wordList codeDictVars() const = 0;
117 
118  //- Adapt the context for the current object
119  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const = 0;
120 
121  //- Clear any redirected objects
122  virtual void clearRedirect() const = 0;
123 
124 
125 public:
126 
127  //- Runtime type information
128  TypeName("codedBase");
129 
130 
131  // Constructors
132 
133  //- Construct null
134  codedBase();
135 
136  //- Construct from name and dictionary
137  codedBase(const word& name, const dictionary& dict);
138 
139  //- Construct from dictionary
140  codedBase(const dictionary& dict);
141 
142  //- Copy constructor
143  codedBase(const codedBase& cb);
144 
145 
146  //- Destructor
147  virtual ~codedBase();
148 
149 
150  // Member Operators
151 
152  //- Disallow default bitwise assignment
153  void operator=(const codedBase&) = delete;
154 
155 
156  // Member Functions
157 
158  word codeTemplateC(const word& baseTypeName) const;
159 
160  word codeTemplateH(const word& baseTypeName) const;
161 
162  virtual void writeCode(Ostream& os) const;
163 };
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 } // End namespace Foam
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 #endif
173 
174 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:54
virtual void clearRedirect() const =0
Clear any redirected objects.
word codeTemplateC(const word &baseTypeName) const
Definition: codedBase.C:423
virtual void writeCode(Ostream &os) const
Definition: codedBase.C:435
virtual wordList codeKeys() const =0
Get the keywords associated with source code.
virtual wordList codeDictVars() const =0
Get the name of the dictionary variables in the source code.
virtual const word & codeName() const
Name of the dynamically generated CodedType.
Definition: codedBase.C:376
TypeName("codedBase")
Runtime type information.
word codeTemplateH(const word &baseTypeName) const
Definition: codedBase.C:429
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const =0
Adapt the context for the current object.
virtual ~codedBase()
Destructor.
Definition: codedBase.C:417
codedBase()
Construct null.
Definition: codedBase.C:390
virtual const dictionary & codeDict() const
Get the dictionary to initialise the codeContext.
Definition: codedBase.C:382
void operator=(const codedBase &)=delete
Disallow default bitwise assignment.
void updateLibrary() const
Update library as required.
Definition: codedBase.C:314
virtual string description() const
Return a description (type + name) for the output.
Definition: codedBase.C:196
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Encapsulation of dynamic code dictionaries.
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:57
A class for handling file names.
Definition: fileName.H:82
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
dictionary dict