All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DLLoader.h
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 The plumed team
3  (see the PEOPLE file at the root of the distribution for a list of names)
4 
5  See http://www.plumed-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
8 
9  plumed is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  plumed is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #ifndef __PLUMED_tools_DLLoader_h
23 #define __PLUMED_tools_DLLoader_h
24 
25 #include <stack>
26 #include <string>
27 
28 namespace PLMD{
29 
30 /// \ingroup TOOLBOX
31 /// Class taking care of dynamic loading.
32 /// It contains wrappers to the dlopen() routine.
33 /// It is designed so that when an object of this class goes
34 /// out of scope all the libraries loaded by it are unloaded. In this
35 /// manner, loaded libraries are automatically unloaded at the end of
36 /// execution. Libraries are loaded with RTDL_LOCAL option, which
37 /// means that they are not accessible from outside. Still, if they
38 /// contain self-registering classes, they will register themselves
39 /// to the ActionRegister object.
40 class DLLoader{
41  std::stack<void*> handles;
42  std::string lastError;
43 /// Private copy constructor
44  DLLoader(const DLLoader&);
45 /// Private assignment
46  DLLoader&operator=(const DLLoader&);
47 public:
48 /// Default constructor
49  DLLoader();
50 /// Cleanup
51  ~DLLoader();
52 /// Load a library, returning its handle
53  void* load(const std::string&);
54 /// Returns the last error in dynamic loader
55  const std::string & error();
56 /// Returns true if the dynamic loader is available (on some systems it may not).
57  static bool installed();
58 };
59 
60 }
61 
62 #endif
~DLLoader()
Cleanup.
Definition: DLLoader.cpp:58
Class taking care of dynamic loading.
Definition: DLLoader.h:40
DLLoader()
Default constructor.
Definition: DLLoader.cpp:67
const std::string & error()
Returns the last error in dynamic loader.
Definition: DLLoader.cpp:54
std::stack< void * > handles
Definition: DLLoader.h:41
static bool installed()
Returns true if the dynamic loader is available (on some systems it may not).
Definition: DLLoader.cpp:30
DLLoader & operator=(const DLLoader &)
Private assignment.
std::string lastError
Definition: DLLoader.h:42
void * load(const std::string &)
Load a library, returning its handle.
Definition: DLLoader.cpp:39