]> Creatis software - cpPlugins.git/blob - lib/third_party/Pluma/DLibrary.hpp
Base objects migration
[cpPlugins.git] / lib / third_party / Pluma / DLibrary.hpp
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // Pluma - Plug-in Management Framework\r
4 // Copyright (C) 2010-2012 Gil Costa (gsaurus@gmail.com)\r
5 //\r
6 // This software is provided 'as-is', without any express or implied warranty.\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.\r
8 //\r
9 // Permission is granted to anyone to use this software for any purpose,\r
10 // including commercial applications, and to alter it and redistribute it freely,\r
11 // subject to the following restrictions:\r
12 //\r
13 // 1. The origin of this software must not be misrepresented;\r
14 //    you must not claim that you wrote the original software.\r
15 //    If you use this software in a product, an acknowledgment\r
16 //    in the product documentation would be appreciated but is not required.\r
17 //\r
18 // 2. Altered source versions must be plainly marked as such,\r
19 //    and must not be misrepresented as being the original software.\r
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 #ifndef PLUMA_DYNAMIC_LIBRARY_HPP\r
26 #define PLUMA_DYNAMIC_LIBRARY_HPP\r
27 \r
28 ////////////////////////////////////////////////////////////\r
29 // Headers\r
30 ////////////////////////////////////////////////////////////\r
31 #include <Pluma/Config.hpp>\r
32 #include <string>\r
33 \r
34 // include OS dependent support for DLL\r
35 #ifdef PLUMA_SYS_WINDOWS\r
36     #include <Windows.h>\r
37 #else\r
38     #include <dlfcn.h>\r
39 #endif\r
40 \r
41 \r
42 \r
43 namespace pluma{\r
44 \r
45 ////////////////////////////////////////////////////////////\r
46 /// \brief Manages a Dynamic Linking Library.\r
47 ///\r
48 ////////////////////////////////////////////////////////////\r
49 class DLibrary{\r
50 \r
51 \r
52 public:\r
53 \r
54     ////////////////////////////////////////////////////////////\r
55     /// \brief Load a library.\r
56     ///\r
57     /// \param path Path to the library.\r
58     ///\r
59     /// \return Pointer to the loaded library, or NULL if failed.\r
60     ///\r
61     ////////////////////////////////////////////////////////////\r
62     static DLibrary* load(const std::string& path);\r
63 \r
64     ////////////////////////////////////////////////////////////\r
65     /// \brief Destructor.\r
66     ///\r
67     /// Close and free the opened library (if any).\r
68     ///\r
69     ////////////////////////////////////////////////////////////\r
70     ~DLibrary();\r
71 \r
72     ////////////////////////////////////////////////////////////\r
73     /// \brief Get a symbol from the library.\r
74     ///\r
75     /// \param symbol Symbol that we're looking for.\r
76     ///\r
77     /// \return Pointer to what the symbol refers to, or NULL if\r
78     /// the symbol is not found.\r
79     ///\r
80     ////////////////////////////////////////////////////////////\r
81     void* getSymbol(const std::string& symbol);\r
82 \r
83 \r
84 private:\r
85 \r
86     ////////////////////////////////////////////////////////////\r
87     /// \brief Default constructor.\r
88     ///\r
89     /// Library instances cannot be created, use load instead.\r
90     ///\r
91     /// \see load\r
92     ///\r
93     ////////////////////////////////////////////////////////////\r
94     DLibrary();\r
95 \r
96     ////////////////////////////////////////////////////////////\r
97     /// \brief Constructor via library handle.\r
98     ///\r
99     /// Used on load function.\r
100     ///\r
101     /// \see load\r
102     ///\r
103     ////////////////////////////////////////////////////////////\r
104     DLibrary(void* handle);\r
105 \r
106 \r
107 \r
108 ////////////////////////////////////////////////////////////\r
109 // Member data\r
110 ////////////////////////////////////////////////////////////\r
111 \r
112 \r
113 private:\r
114 \r
115     void* handle; ///< Library handle.\r
116 \r
117 };\r
118 \r
119 \r
120 }   // namespace pluma\r
121 \r
122 \r
123 #endif // PLUMA_DYNAMIC_LIBRARY_HPP\r