Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DynamicLibraryLoader.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2012-2013 (http://safir.sourceforge.net)
4 *
5 * Created by: Lars Hagström / lars@foldspace.nu
6 *
7 *******************************************************************************
8 *
9 * This file is part of Safir SDK Core.
10 *
11 * Safir SDK Core is free software: you can redistribute it and/or modify
12 * it under the terms of version 3 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * Safir SDK Core is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22 *
23 ******************************************************************************/
24 #ifndef __DYNAMIC_LIBRARY_LOADER_H__
25 #define __DYNAMIC_LIBRARY_LOADER_H__
26 
27 #include <Safir/Utilities/Internal/UtilsExportDefs.h>
28 #include <boost/shared_ptr.hpp>
29 #include <boost/function.hpp>
30 #include <string>
31 
32 namespace Safir
33 {
34 namespace Utilities
35 {
41  class LLUF_UTILS_API DynamicLibraryLoader
42  {
43  public:
46 
49 
62  void Load(const std::string& libraryName,
63  const bool unloadOnDestruction,
64  const bool global = false);
65 
69  void Unload();
70 
93  template<class T>
94  T* GetFunction(const std::string& functionName)
95  {
96  return reinterpret_cast<T*>(GetFunctionInternal(functionName));
97  }
98  private:
99  void * GetFunctionInternal(const std::string& functionName);
100 
101 #ifdef _MSC_VER
102 #pragma warning (push)
103 #pragma warning (disable: 4251)
104 #endif
105 
106  class Impl;
107  boost::shared_ptr<Impl> m_impl;
108 
109 #ifdef _MSC_VER
110 #pragma warning (pop)
111 #endif
112 
113  bool m_unloadOnDestruction;
114  };
115 }
116 }
117 
118 
119 #endif
120 
T * GetFunction(const std::string &functionName)
Find a function in the library.
Definition: DynamicLibraryLoader.h:94
This class provides a simple wrapper around dynamic loading functionality of the operating system...
Definition: DynamicLibraryLoader.h:41