dlLibraryTable.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::dlLibraryTable
29 
30 Description
31  A table of dynamically loaded libraries.
32 
33 SourceFiles
34  dlLibraryTable.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef dlLibraryTable_H
39 #define dlLibraryTable_H
40 
41 #include "DynamicList.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class dlLibraryTable Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class dlLibraryTable
53 {
54  // Private Data
55 
56  DynamicList<void*> libPtrs_;
57 
58  DynamicList<fileName> libNames_;
59 
60 
61  // Private Member Functions
62 
63  //- Open specified library name and return pointer.
64  // Warning messages, but no additional side-effects.
65  void* openLibrary(const fileName& libName, bool verbose);
66 
67  //- No copy construct
68  dlLibraryTable(const dlLibraryTable&) = delete;
69 
70  //- No copy assignment
71  void operator=(const dlLibraryTable&) = delete;
72 
73 
74 public:
75 
76  // Declare name of the class and its debug switch
77  ClassName("dlLibraryTable");
78 
79  // Constructors
80 
81  //- Construct null
82  dlLibraryTable() = default;
83 
84  //- Move construct
85  dlLibraryTable(dlLibraryTable&&) = default;
86 
87  //- Open specified libraries. Ignores duplicate names.
88  explicit dlLibraryTable
89  (
90  const UList<fileName>& libNames,
91  bool verbose = true
92  );
93 
94  //- Open all libraries listed in the 'libsEntry' entry in the
95  //- given dictionary. Verbose = true.
96  dlLibraryTable(const dictionary& dict, const word& libsEntry);
97 
98 
99  //- Destructor. Closes all libraries loaded by the table.
100  ~dlLibraryTable();
101 
102 
103  // Member Functions
104 
105  //- True if no there are no libraries loaded by the table
106  bool empty() const;
107 
108  //- The number of libraries loaded by the table
109  label size() const;
110 
111  //- Clearing closes all libraries loaded by the table.
112  void clear(bool verbose = true);
113 
114  //- Add to the list of names, but do not yet open.
115  // Ignores duplicate names.
116  bool append(const fileName& libName);
117 
118  //- Add to the list of names, but do not yet open.
119  // Ignores duplicate names.
120  label append(const UList<fileName>& libNames);
121 
122  //- Open named, but unopened libraries.
123  //- These names will normally have been added with the append() method.
124  bool open(bool verbose = true);
125 
126  //- Open the named library, optionally warn if problems occur
127  void* open(const fileName& libName, bool verbose = true);
128 
129  //- Open the named libraries, optionally warn if problems occur
130  // Ignores duplicate names.
131  bool open(const UList<fileName>& libNames, bool verbose = true);
132 
133  //- Close the named library, optionally warn if problems occur
134  bool close(const fileName& libName, bool verbose = true);
135 
136  //- Find the handle of the named library
137  void* findLibrary(const fileName& libName);
138 
139  //- Open all libraries listed in the 'libsEntry' entry in the
140  //- given dictionary.
141  bool open(const dictionary& dict, const word& libsEntry);
142 
143  //- Open all libraries listed in the 'libsEntry' entry in the
144  //- given dictionary and check the additions
145  //- to the given constructor table
146  template<class TablePtr>
147  bool open
148  (
149  const dictionary& dict,
150  const word& libsEntry,
151  const TablePtr& tablePtr
152  );
153 
154 
155  // Member Operators
156 
157  //- Move assignment
158  dlLibraryTable& operator=(dlLibraryTable&&) = default;
159 };
160 
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 } // End namespace Foam
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #ifdef NoRepository
169  #include "dlLibraryTableTemplates.C"
170 #endif
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 #endif
175 
176 // ************************************************************************* //
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:51
Foam::dlLibraryTable::findLibrary
void * findLibrary(const fileName &libName)
Find the handle of the named library.
Definition: dlLibraryTable.C:334
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::DynamicList< void * >
Foam::dlLibraryTable::close
bool close(const fileName &libName, bool verbose=true)
Close the named library, optionally warn if problems occur.
Definition: dlLibraryTable.C:303
Foam::dlLibraryTable::empty
bool empty() const
True if no there are no libraries loaded by the table.
Definition: dlLibraryTable.C:105
Foam::dlLibraryTable::clear
void clear(bool verbose=true)
Clearing closes all libraries loaded by the table.
Definition: dlLibraryTable.C:135
Foam::dlLibraryTable::append
bool append(const fileName &libName)
Add to the list of names, but do not yet open.
Definition: dlLibraryTable.C:197
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::dlLibraryTable::open
bool open(bool verbose=true)
Definition: dlLibraryTable.C:227
Foam::dlLibraryTable::ClassName
ClassName("dlLibraryTable")
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
DynamicList.H
dlLibraryTableTemplates.C
Foam::dlLibraryTable::size
label size() const
The number of libraries loaded by the table.
Definition: dlLibraryTable.C:119
Foam::dlLibraryTable::dlLibraryTable
dlLibraryTable()=default
Construct null.
Foam::dlLibraryTable::~dlLibraryTable
~dlLibraryTable()
Destructor. Closes all libraries loaded by the table.
Definition: dlLibraryTable.C:97