|
16 | 16 | namespace xp |
17 | 17 | { |
18 | 18 |
|
19 | | -// lazy storage of a shared library |
20 | | -// and the factory it contains. |
21 | | -// Both are loaded / created on demand |
22 | | -template <class FACTORY_BASE, bool THREAD_SAFE> |
23 | | -class xlazy_shared_library_plugin_factory |
24 | | -{ |
25 | | - public: |
26 | | - using factory_base_type = FACTORY_BASE; |
27 | | - xlazy_shared_library_plugin_factory(const xlazy_shared_library_plugin_factory &) = delete; |
28 | | - xlazy_shared_library_plugin_factory &operator=(const xlazy_shared_library_plugin_factory &) = delete; |
| 19 | + // lazy storage of a shared library |
| 20 | + // and the factory it contains. |
| 21 | + // Both are loaded / created on demand |
| 22 | + template <class FACTORY_BASE, bool THREAD_SAFE> |
| 23 | + class xlazy_shared_library_plugin_factory |
| 24 | + { |
| 25 | + public: |
| 26 | + using factory_base_type = FACTORY_BASE; |
| 27 | + xlazy_shared_library_plugin_factory(const xlazy_shared_library_plugin_factory &) = delete; |
| 28 | + xlazy_shared_library_plugin_factory &operator=(const xlazy_shared_library_plugin_factory &) = delete; |
29 | 29 |
|
30 | | - xlazy_shared_library_plugin_factory(xlazy_shared_library_plugin_factory &&other) = delete; |
31 | | - xlazy_shared_library_plugin_factory &operator=(xlazy_shared_library_plugin_factory &&other) = delete; |
| 30 | + xlazy_shared_library_plugin_factory(xlazy_shared_library_plugin_factory &&other) = delete; |
| 31 | + xlazy_shared_library_plugin_factory &operator=(xlazy_shared_library_plugin_factory &&other) = delete; |
32 | 32 |
|
33 | | - ~xlazy_shared_library_plugin_factory() = default; |
| 33 | + ~xlazy_shared_library_plugin_factory() = default; |
34 | 34 |
|
35 | | - inline xlazy_shared_library_plugin_factory(const std::filesystem::path &path); |
| 35 | + xlazy_shared_library_plugin_factory(const std::filesystem::path &path); |
36 | 36 |
|
37 | | - inline const std::filesystem::path &path() const noexcept; |
| 37 | + const std::filesystem::path& path() const noexcept; |
38 | 38 |
|
39 | | - factory_base_type *factory() const; |
| 39 | + factory_base_type* factory() const; |
40 | 40 |
|
41 | | - private: |
42 | | - using create_plugin_factory_type = factory_base_type *(*)(); |
43 | | - using mutex_type = xmutex_t<THREAD_SAFE>; |
44 | | - using scoped_lock_type = xscoped_lock_t<THREAD_SAFE, mutex_type>; |
| 41 | + private: |
| 42 | + using create_plugin_factory_type = factory_base_type *(*)(); |
| 43 | + using mutex_type = xmutex_t<THREAD_SAFE>; |
| 44 | + using scoped_lock_type = xscoped_lock_t<THREAD_SAFE, mutex_type>; |
45 | 45 |
|
46 | | - mutable mutex_type m_mutex; |
47 | | - std::filesystem::path m_path; |
48 | | - mutable std::unique_ptr<xshared_library> m_library; |
49 | | - mutable std::unique_ptr<factory_base_type> m_factory; |
50 | | -}; |
| 46 | + mutable mutex_type m_mutex; |
| 47 | + std::filesystem::path m_path; |
| 48 | + mutable std::unique_ptr<xshared_library> m_library; |
| 49 | + mutable std::unique_ptr<factory_base_type> m_factory; |
| 50 | + }; |
51 | 51 |
|
52 | | -template <class FACTORY_BASE, bool THREAD_SAFE> |
53 | | -inline xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::xlazy_shared_library_plugin_factory( |
54 | | - const std::filesystem::path &path) |
55 | | - : m_path(path), |
56 | | - m_library() |
57 | | -{ |
58 | | -} |
59 | | - |
60 | | -template <class FACTORY_BASE, bool THREAD_SAFE> |
61 | | -inline typename xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory_base_type * |
62 | | -xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory() const |
63 | | -{ |
64 | | - scoped_lock_type lock(m_mutex); |
65 | | - if (!m_factory) |
| 52 | + template <class FACTORY_BASE, bool THREAD_SAFE> |
| 53 | + xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::xlazy_shared_library_plugin_factory( |
| 54 | + const std::filesystem::path &path) |
| 55 | + : m_path(path) |
| 56 | + , m_library() |
66 | 57 | { |
| 58 | + } |
67 | 59 |
|
68 | | - m_library.reset(new xshared_library(m_path)); |
69 | | - m_factory.reset(m_library->find_symbol<create_plugin_factory_type>("create_plugin_factory")()); |
| 60 | + template <class FACTORY_BASE, bool THREAD_SAFE> |
| 61 | + typename xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory_base_type * |
| 62 | + xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory() const |
| 63 | + { |
| 64 | + scoped_lock_type lock(m_mutex); |
| 65 | + if (!m_factory) |
| 66 | + { |
| 67 | + |
| 68 | + m_library.reset(new xshared_library(m_path)); |
| 69 | + m_factory.reset(m_library->find_symbol<create_plugin_factory_type>("create_plugin_factory")()); |
| 70 | + } |
| 71 | + return m_factory.get(); |
70 | 72 | } |
71 | | - return m_factory.get(); |
72 | | -} |
73 | 73 |
|
74 | | -template <class FACTORY_BASE, bool THREAD_SAFE> |
75 | | -const std::filesystem::path &xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::path() const noexcept |
76 | | -{ |
77 | | - return m_path; |
78 | | -} |
| 74 | + template <class FACTORY_BASE, bool THREAD_SAFE> |
| 75 | + const std::filesystem::path& xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::path() const noexcept |
| 76 | + { |
| 77 | + return m_path; |
| 78 | + } |
79 | 79 |
|
80 | 80 | } // namespace xp |
81 | 81 |
|
|
0 commit comments