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 "dynamicCodeContext.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 // Forward declaration of classes
46 class dynamicCode;
47 
48 /*---------------------------------------------------------------------------*\
49  Class codedBase Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class codedBase
53 {
54  // Private Member Data
55 
56  //- Name of the dynamically generated CodedType
57  const word codeName_;
58 
59  dynamicCodeContext codeContext_;
60 
61  //- Previously loaded library
62  mutable fileName oldLibPath_;
63 
64 
65  // Private Member Functions
66 
67  //- Global loader/unloader function type
68  typedef void (*loaderFunctionType)(bool);
69 
70  //- Create a code name from the given function name
71  static word codeName(const word& name);
72 
73  //- Load specified library and execute globalFuncName(true)
74  void* loadLibrary
75  (
76  const fileName& libPath,
77  const string& globalFuncName,
78  const dictionary& contextDict
79  ) const;
80 
81  //- Execute globalFuncName(false) and unload specified library
82  void unloadLibrary
83  (
84  const fileName& libPath,
85  const string& globalFuncName,
86  const dictionary& contextDict
87  ) const;
88 
89  verbatimString expandCodeString
90  (
91  const word& codeKey,
92  const word& codeDictVar,
93  const dictionary& dict
94  ) const;
95 
96  //- Create library based on the dynamicCodeContext
97  void createLibrary
98  (
99  const dictionary& dict,
100  dynamicCode&,
101  const dynamicCodeContext&
102  ) const;
103 
104  //- Adapt the context for the current object
105  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const = 0;
106 
107 
108 public:
109 
110  //- Runtime type information
111  TypeName("codedBase");
112 
113 
114  // Constructors
115 
116  //- Construct from name and dictionary
117  codedBase
118  (
119  const word& name,
120  const dictionary& dict,
121  const wordList& codeKeys,
122  const wordList& codeDictVars
123  );
124 
125  //- Construct from dictionary
126  codedBase
127  (
128  const dictionary& dict,
129  const wordList& codeKeys,
130  const wordList& codeDictVars
131  );
132 
133  //- Copy constructor
134  codedBase(const codedBase& cb);
135 
136 
137  //- Destructor
138  virtual ~codedBase();
139 
140 
141  // Member Functions
142 
143  //- Name of the dynamically generated CodedType
144  const word& codeName() const;
145 
146  //- Return a description (type + name) for the output
147  string description() const;
148 
149  word codeTemplateC(const word& baseTypeName) const;
150 
151  word codeTemplateH(const word& baseTypeName) const;
152 
153  //- Update library from given updated dictionary as required
154  // Returns true if the library was updated, otherwise false
155  bool updateLibrary(const dictionary& dict) const;
156 
157  //- Read the dictionary and update the code
158  void read(const dictionary& dict);
159 
160  //- Write the code for restart
161  void write(Ostream& os) const;
162 
163 
164  // Member Operators
165 
166  //- Disallow default bitwise assignment
167  void operator=(const codedBase&) = delete;
168 };
169 
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 } // End namespace Foam
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 #endif
178 
179 // ************************************************************************* //
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:52
word codeTemplateC(const word &baseTypeName) const
Definition: codedBase.C:386
void read(const dictionary &dict)
Read the dictionary and update the code.
Definition: codedBase.C:455
const word & codeName() const
Name of the dynamically generated CodedType.
Definition: codedBase.C:374
TypeName("codedBase")
Runtime type information.
void write(Ostream &os) const
Write the code for restart.
Definition: codedBase.C:461
codedBase(const word &name, const dictionary &dict, const wordList &codeKeys, const wordList &codeDictVars)
Construct from name and dictionary.
Definition: codedBase.C:336
word codeTemplateH(const word &baseTypeName) const
Definition: codedBase.C:392
virtual ~codedBase()
Destructor.
Definition: codedBase.C:368
void operator=(const codedBase &)=delete
Disallow default bitwise assignment.
bool updateLibrary(const dictionary &dict) const
Update library from given updated dictionary as required.
Definition: codedBase.C:398
string description() const
Return a description (type + name) for the output.
Definition: codedBase.C:380
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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 verbatimStrings, derived from string.
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dictionary dict