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-2026 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 coded functionObjects, fvModels, Function1, Function2
29 
30  and boundary conditions
31 
32 SourceFiles
33  codedBase.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef codedBase_H
38 #define codedBase_H
39 
40 #include "dynamicCode.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class codedBase Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 class codedBase
52 :
53  public dynamicCode
54 {
55  // Private Data
56 
57  //- Optional switch to allow library unloading and reloading
58  // to support run-time code update
59  const bool reloadable_;
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  void checkLibrary
71  (
72  const dictionary& dict,
73  const fileName& libPath,
74  void* lib,
75  const string& uniqueFuncName,
76  const bool load
77  ) const;
78 
79  //- Load specified library and execute uniqueFuncName(true)
80  void* loadLibrary
81  (
82  const dictionary& dict,
83  const fileName& libPath,
84  const string& uniqueFuncName
85  ) const;
86 
87  //- Execute uniqueFuncName(false) and unload specified library
88  void unloadLibrary
89  (
90  const dictionary& dict,
91  const fileName& libPath,
92  const string& uniqueFuncName
93  ) const;
94 
95  verbatimString expandCodeString
96  (
97  const dictionary& dict,
98  const word& codeKey,
99  const word& codeDictVar
100  ) const;
101 
102 
103 public:
104 
105  //- Runtime type information
106  TypeName("codedBase");
107 
108 
109  // Constructors
110 
111  //- Construct from name and dictionary
112  codedBase
113  (
114  const word& name,
115  const dictionary& dict,
116  const wordList& codeKeys,
117  const wordList& codeDictVars,
118  const word& codeOptionsFileName,
119  const wordList& compileFiles,
120  const wordList& copyFiles,
121  const bool reloadable = true
122  );
123 
124 
125  //- Destructor
126  virtual ~codedBase();
127 
128 
129  // Member Functions
130 
131  //- Create a coded name from the given name
132  static word codedName(const word& name);
133 
134  //- Update library from given updated dictionary as required
135  // Returns true if the library was updated, otherwise false
136  bool updateLibrary(const dictionary& dict) const;
137 
138 
139  // Member Operators
140 
141  //- Disallow default bitwise assignment
142  void operator=(const codedBase&) = delete;
143 };
144 
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 } // End namespace Foam
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 #endif
153 
154 // ************************************************************************* //
Base class for coded functionObjects, fvModels, Function1, Function2.
Definition: codedBase.H:53
TypeName("codedBase")
Runtime type information.
codedBase(const word &name, const dictionary &dict, const wordList &codeKeys, const wordList &codeDictVars, const word &codeOptionsFileName, const wordList &compileFiles, const wordList &copyFiles, const bool reloadable=true)
Construct from name and dictionary.
Definition: codedBase.C:158
virtual ~codedBase()
Destructor.
Definition: codedBase.C:186
void operator=(const codedBase &)=delete
Disallow default bitwise assignment.
static word codedName(const word &name)
Create a coded name from the given name.
Definition: codedBase.C:202
bool updateLibrary(const dictionary &dict) const
Update library from given updated dictionary as required.
Definition: codedBase.C:230
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 and functionality.
Definition: dynamicCode.H:51
fileName libPath() const
Library path for specified code name.
Definition: dynamicCode.H:239
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:63
Namespace for OpenFOAM.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dictionary dict