1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 Copyright (c) 2011-2021 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.org for more information. 6 7 This file is part of plumed, version 2. 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 /// Deleted copy constructor 44 DLLoader(const DLLoader&) = delete; 45 /// Deleted assignment 46 DLLoader&operator=(const DLLoader&) = delete; 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 63