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-2020 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  dlLibraryTableTemplates.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef dlLibraryTable_H
40 #define dlLibraryTable_H
41 
42 #include "DynamicList.H"
43 #include "InfoProxy.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward Declarations
51 class dlLibraryTable;
52 Ostream& operator<<(Ostream& os, const InfoProxy<dlLibraryTable>& info);
53 
54 /*---------------------------------------------------------------------------*\
55  Class dlLibraryTable Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class dlLibraryTable
59 {
60  // Private Data
61 
62  DynamicList<void*> libPtrs_;
63 
64  DynamicList<fileName> libNames_;
65 
66 
67  // Private Member Functions
68 
69  //- Open specified library name and return pointer.
70  // Warning messages, but no additional side-effects.
71  void* openLibrary(const fileName& libName, bool verbose);
72 
73 
74 public:
75 
76  // Declare name of the class and its debug switch
77  ClassName("dlLibraryTable");
78 
79  // Generated Methods
80 
81  //- Default construct
82  dlLibraryTable() = default;
83 
84  //- No copy construct
85  dlLibraryTable(const dlLibraryTable&) = delete;
86 
87  //- Move construct
88  dlLibraryTable(dlLibraryTable&&) = default;
89 
90  //- No copy assignment
91  void operator=(const dlLibraryTable&) = delete;
92 
93  //- Move assignment
95 
96 
97  // Constructors
98 
99  //- Open specified libraries. Ignores duplicate names.
100  explicit dlLibraryTable
101  (
102  const UList<fileName>& libNames,
103  bool verbose = true
104  );
105 
106  //- Open all libraries listed in the 'libsEntry' entry in the
107  //- given dictionary. Verbose = true.
108  dlLibraryTable(const dictionary& dict, const word& libsEntry);
109 
110 
111  //- Destructor. Closes all libraries loaded by the table.
112  ~dlLibraryTable();
113 
114 
115  // Member Functions
116 
117  //- True if there are no libraries loaded by the table
118  bool empty() const;
119 
120  //- The number of libraries loaded by the table
121  label size() const;
122 
123  //- Names of the libraries in use, or requested
124  const UList<fileName>& names() const
125  {
126  return libNames_;
127  }
128 
129  //- Pointers to the libraries in use. Access with caution.
130  const UList<void*>& pointers() const
131  {
132  return libPtrs_;
133  }
134 
135  //- Clearing closes all libraries loaded by the table.
136  void clear(bool verbose = true);
137 
138  //- Add to the list of names, but do not yet open.
139  // Ignores duplicate names.
140  bool append(const fileName& libName);
141 
142  //- Add to the list of names, but do not yet open.
143  // Ignores duplicate names.
144  label append(const UList<fileName>& libNames);
145 
146  //- Open named, but unopened libraries.
147  //- These names will normally have been added with the append() method.
148  bool open(bool verbose = true);
149 
150  //- Open the named library, optionally warn if problems occur
151  void* open(const fileName& libName, bool verbose = true);
152 
153  //- Open the named libraries, optionally warn if problems occur
154  // Ignores duplicate names.
155  bool open(const UList<fileName>& libNames, bool verbose = true);
156 
157  //- Close the named library, optionally warn if problems occur
158  bool close(const fileName& libName, bool verbose = true);
159 
160  //- Find the handle of the named library
161  void* findLibrary(const fileName& libName);
162 
163  //- Open all libraries listed in the 'libsEntry' entry in the
164  //- given dictionary.
165  bool open(const dictionary& dict, const word& libsEntry);
166 
167  //- Open all libraries listed in the 'libsEntry' entry in the
168  //- given dictionary and check the additions
169  //- to the given constructor table
170  template<class TablePtr>
171  bool open
172  (
173  const dictionary& dict,
174  const word& libsEntry,
175  const TablePtr& tablePtr
176  );
177 
178 
179  // Info
180 
181  //- Return info proxy.
182  // Used to print library table information to a stream
184  {
185  return *this;
186  }
187 };
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #ifdef NoRepository
197  #include "dlLibraryTableTemplates.C"
198 #endif
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #endif
203 
204 // ************************************************************************* //
Foam::dlLibraryTable::pointers
const UList< void * > & pointers() const
Pointers to the libraries in use. Access with caution.
Definition: dlLibraryTable.H:129
Foam::dlLibraryTable
A table of dynamically loaded libraries.
Definition: dlLibraryTable.H:57
Foam::dlLibraryTable::findLibrary
void * findLibrary(const fileName &libName)
Find the handle of the named library.
Definition: dlLibraryTable.C:336
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::InfoProxy
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:47
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::DynamicList< void * >
InfoProxy.H
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 there are no libraries loaded by the table.
Definition: dlLibraryTable.C:105
Foam::dlLibraryTable::info
InfoProxy< dlLibraryTable > info() const
Return info proxy.
Definition: dlLibraryTable.H:182
Foam::dlLibraryTable::operator=
void operator=(const dlLibraryTable &)=delete
No copy assignment.
Foam::dlLibraryTable::clear
void clear(bool verbose=true)
Clearing closes all libraries loaded by the table.
Definition: dlLibraryTable.C:135
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::dlLibraryTable::append
bool append(const fileName &libName)
Add to the list of names, but do not yet open.
Definition: dlLibraryTable.C:197
Foam::dlLibraryTable::names
const UList< fileName > & names() const
Names of the libraries in use, or requested.
Definition: dlLibraryTable.H:123
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
Default construct.
Foam::dlLibraryTable::~dlLibraryTable
~dlLibraryTable()
Destructor. Closes all libraries loaded by the table.
Definition: dlLibraryTable.C:97