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-2020 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 Data
57 
58  //- Previously loaded library
59  mutable fileName oldLibPath_;
60 
61  // Private Member Functions
62 
63  //- Global loader/unloader function type
64  typedef void (*loaderFunctionType)(bool);
65 
66  //- Load specified library and execute globalFuncName(true)
67  void* loadLibrary
68  (
69  const fileName& libPath,
70  const string& globalFuncName,
71  const dictionary& contextDict
72  ) const;
73 
74  //- Execute globalFuncName(false) and unload specified library
75  void unloadLibrary
76  (
77  const fileName& libPath,
78  const string& globalFuncName,
79  const dictionary& contextDict
80  ) const;
81 
82  //- Create library based on the dynamicCodeContext
83  void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
84 
85 
86 protected:
87 
88  //- Update library as required
89  void updateLibrary() const;
90 
91  //- Name of the dynamically generated CodedType
92  virtual const word& codeName() const = 0;
93 
94  //- Return a description (type + name) for the output
95  virtual string description() const = 0;
96 
97  //- Get the dictionary to initialize the codeContext
98  virtual const dictionary& codeDict() const = 0;
99 
100  //- Get the keywords associated with source code
101  virtual const wordList& codeKeys() const = 0;
102 
103  //- Adapt the context for the current object
104  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const = 0;
105 
106  //- Clear any redirected objects
107  virtual void clearRedirect() const = 0;
108 
109 
110 public:
111 
112  //- Runtime type information
113  ClassName("codedBase");
114 
115 
116  // Constructors
117 
118  //- Construct null
119  codedBase();
120 
121  //- Disallow default bitwise copy construction
122  codedBase(const codedBase&) = delete;
123 
124 
125  //- Destructor
126  virtual ~codedBase();
127 
128 
129  // Member Operators
130 
131  //- Disallow default bitwise assignment
132  void operator=(const codedBase&) = delete;
133 };
134 
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 } // End namespace Foam
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 #endif
143 
144 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:79
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
void operator=(const codedBase &)=delete
Disallow default bitwise assignment.
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const =0
Adapt the context for the current object.
virtual const wordList & codeKeys() const =0
Get the keywords associated with source code.
A class for handling words, derived from string.
Definition: word.H:59
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:53
codedBase()
Construct null.
Definition: codedBase.C:347
void updateLibrary() const
Update library as required.
Definition: codedBase.C:283
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
Encapsulation of dynamic code dictionaries.
virtual string description() const =0
Return a description (type + name) for the output.
ClassName("codedBase")
Runtime type information.
virtual void clearRedirect() const =0
Clear any redirected objects.
virtual ~codedBase()
Destructor.
Definition: codedBase.C:353
virtual const word & codeName() const =0
Name of the dynamically generated CodedType.
virtual const dictionary & codeDict() const =0
Get the dictionary to initialize the codeContext.
Namespace for OpenFOAM.