codedBase.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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  //- Disallow default bitwise copy construct
86  codedBase(const codedBase&);
87 
88  //- Disallow default bitwise assignment
89  void operator=(const codedBase&);
90 
91 
92 protected:
93 
94  //- Update library as required
95  void updateLibrary
96  (
97  const word& redirectType
98  ) const;
99 
100  //- Get the loaded dynamic libraries
101  virtual dlLibraryTable& libs() const = 0;
102 
103  //- Adapt the context for the current object
104  virtual void prepare
105  (
106  dynamicCode&,
107  const dynamicCodeContext&
108  ) const = 0;
109 
110  // Return a description (type + name) for the output
111  virtual string description() const = 0;
112 
113  // Clear any redirected objects
114  virtual void clearRedirect() const = 0;
115 
116  // Get the dictionary to initialize the codeContext
117  virtual const dictionary& codeDict() const = 0;
118 
119 
120 public:
121 
122  //- Runtime type information
123  ClassName("codedBase");
124 
125 
126  // Constructors
127 
128  //- Construct null
129  codedBase();
130 
131 
132  //- Destructor
133  virtual ~codedBase();
134 
135 };
136 
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 } // End namespace Foam
141 
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 
144 #endif
145 
146 // ************************************************************************* //
virtual ~codedBase()
Destructor.
Definition: codedBase.C:357
Base class for function objects and boundary conditions using dynamic code.
Definition: codedBase.H:53
A class for handling words, derived from string.
Definition: word.H:59
ClassName("codedBase")
Runtime type information.
void updateLibrary(const word &redirectType) const
Update library as required.
Definition: codedBase.C:290
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
Encapsulation of dynamic code dictionaries.
virtual dlLibraryTable & libs() const =0
Get the loaded dynamic libraries.
A class for handling file names.
Definition: fileName.H:69
Tools for handling dynamic code compilation.
Definition: dynamicCode.H:56
A table of dynamically loaded libraries.
codedBase()
Construct null.
Definition: codedBase.C:351
virtual void prepare(dynamicCode &, const dynamicCodeContext &) const =0
Adapt the context for the current object.
virtual const dictionary & codeDict() const =0
virtual void clearRedirect() const =0
virtual string description() const =0