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-2021 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  //- 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  //- Create library based on the dynamicCodeContext
90  void createLibrary(dynamicCode&, const dynamicCodeContext&) const;
91 
92 
93 protected:
94 
95  //- Update library as required
96  void updateLibrary() const;
97 
98  //- Name of the dynamically generated CodedType
99  virtual const word& codeName() const;
100 
101  //- Return a description (type + name) for the output
102  virtual string description() const;
103 
104  //- Get the dictionary to initialise the codeContext
105  virtual const dictionary& codeDict() const;
106 
107  //- Get the keywords associated with source code
108  virtual wordList codeKeys() const = 0;
109 
110  //- Adapt the context for the current object
111  virtual void prepare(dynamicCode&, const dynamicCodeContext&) const = 0;
112 
113  //- Clear any redirected objects
114  virtual void clearRedirect() const = 0;
115 
116 
117 public:
118 
119  //- Runtime type information
120  TypeName("codedBase");
121 
122 
123  // Constructors
124 
125  //- Construct null
126  codedBase();
127 
128  //- Construct from name and dictionary
129  codedBase(const word& name, const dictionary& dict);
130 
131  //- Construct from dictionary
132  codedBase(const dictionary& dict);
133 
134  //- Copy constructor
135  codedBase(const codedBase& cb);
136 
137 
138  //- Destructor
139  virtual ~codedBase();
140 
141 
142  // Member Operators
143 
144  //- Disallow default bitwise assignment
145  void operator=(const codedBase&) = delete;
146 
147 
148  // Member Functions
149 
150  word codeTemplateC(const word& baseTypeName) const;
151 
152  word codeTemplateH(const word& baseTypeName) const;
153 
154  virtual void writeCode(Ostream& os) const;
155 };
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 } // End namespace Foam
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #endif
165 
166 // ************************************************************************* //
dictionary dict
word codeTemplateH(const word &baseTypeName) const
Definition: codedBase.C:403
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:156
word codeTemplateC(const word &baseTypeName) const
Definition: codedBase.C:397
void operator=(const codedBase &)=delete
Disallow default bitwise assignment.
virtual const dictionary & codeDict() const
Get the dictionary to initialise the codeContext.
Definition: codedBase.C:356
virtual const word & codeName() const
Name of the dynamically generated CodedType.
Definition: codedBase.C:350
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const =0
Adapt the context for the current object.
virtual 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
virtual void writeCode(Ostream &os) const
Definition: codedBase.C:409
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
codedBase()
Construct null.
Definition: codedBase.C:364
void updateLibrary() const
Update library as required.
Definition: codedBase.C:288
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
Encapsulation of dynamic code dictionaries.
TypeName("codedBase")
Runtime type information.
virtual void clearRedirect() const =0
Clear any redirected objects.
virtual string description() const
Return a description (type + name) for the output.
Definition: codedBase.C:170
virtual ~codedBase()
Destructor.
Definition: codedBase.C:391
Namespace for OpenFOAM.