5
5
* *
6
6
* The full license is in the file LICENSE, distributed with this software. *
7
7
****************************************************************************/
8
+
8
9
#ifndef XPLUGIN_REGISTRY_HPP
9
10
#define XPLUGIN_REGISTRY_HPP
10
11
17
18
18
19
#include < xplugin/xlazy_shared_library_plugin_factory.hpp>
19
20
#include < xplugin/xplugin_config.hpp>
21
+ #include < xplugin/xplugin_util.hpp>
20
22
21
23
namespace xp ::detail
22
24
{
23
-
24
25
template <class FACTORY_BASE , bool THREAD_SAFE>
25
26
class xplugin_registry_impl ;
26
27
@@ -95,11 +96,15 @@ namespace xp::detail
95
96
using const_iterator = xplugin_registry_iterator<self_type, typename storage_map_type::const_iterator>;
96
97
using iterator = xplugin_registry_iterator<self_type, typename storage_map_type::iterator>;
97
98
98
- xplugin_registry_impl (const std::filesystem::path & path,
99
- const std::string & prefix = get_default_library_prefix(),
100
- const std::string & extension = get_default_library_extension());
99
+ explicit xplugin_registry_impl (const std::filesystem::path& path,
100
+ const std::string& prefix = get_default_library_prefix(),
101
+ const std::string& extension = get_default_library_extension());
101
102
102
- factory_base_type *operator [](const std::string &name);
103
+ template <class R , std::enable_if_t <xp::util::is_range_of_v<R, std::filesystem::path>, int > = 3 >
104
+ explicit xplugin_registry_impl (R r,
105
+ const std::string& prefix = get_default_library_prefix());
106
+
107
+ factory_base_type* operator [](const std::string& name);
103
108
104
109
std::size_t size () const ;
105
110
bool empty () const ;
@@ -116,6 +121,8 @@ namespace xp::detail
116
121
117
122
private:
118
123
124
+ void add_entry (const std::filesystem::path& path, const std::string& prefix);
125
+
119
126
static std::string get_default_library_extension ();
120
127
static std::string get_default_library_prefix ();
121
128
@@ -199,51 +206,51 @@ namespace xp::detail
199
206
}
200
207
201
208
// registry implementation
202
- template <class FACTORY_BASE , bool THREAD_SAVE >
203
- typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::iterator xplugin_registry_impl<FACTORY_BASE,
204
- THREAD_SAVE >::begin()
209
+ template <class FACTORY_BASE , bool THREAD_SAFE >
210
+ typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::iterator xplugin_registry_impl<FACTORY_BASE,
211
+ THREAD_SAFE >::begin()
205
212
{
206
213
return iterator (m_lazy_shared_lib_factories.begin ());
207
214
}
208
215
209
- template <class FACTORY_BASE , bool THREAD_SAVE >
210
- typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::iterator xplugin_registry_impl<FACTORY_BASE,
211
- THREAD_SAVE >::end()
216
+ template <class FACTORY_BASE , bool THREAD_SAFE >
217
+ typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::iterator xplugin_registry_impl<FACTORY_BASE,
218
+ THREAD_SAFE >::end()
212
219
{
213
220
return iterator (m_lazy_shared_lib_factories.end ());
214
221
}
215
222
216
223
// const iterator
217
- template <class FACTORY_BASE , bool THREAD_SAVE >
218
- typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::const_iterator xplugin_registry_impl<
219
- FACTORY_BASE, THREAD_SAVE >::begin() const
224
+ template <class FACTORY_BASE , bool THREAD_SAFE >
225
+ typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::const_iterator xplugin_registry_impl<
226
+ FACTORY_BASE, THREAD_SAFE >::begin() const
220
227
{
221
228
return const_iterator (m_lazy_shared_lib_factories.cbegin ());
222
229
}
223
230
224
- template <class FACTORY_BASE , bool THREAD_SAVE >
225
- typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::const_iterator xplugin_registry_impl<
226
- FACTORY_BASE, THREAD_SAVE >::end() const
231
+ template <class FACTORY_BASE , bool THREAD_SAFE >
232
+ typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::const_iterator xplugin_registry_impl<
233
+ FACTORY_BASE, THREAD_SAFE >::end() const
227
234
{
228
235
return const_iterator (m_lazy_shared_lib_factories.cend ());
229
236
}
230
237
231
- template <class FACTORY_BASE , bool THREAD_SAVE >
232
- typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::const_iterator xplugin_registry_impl<
233
- FACTORY_BASE, THREAD_SAVE >::cbegin() const
238
+ template <class FACTORY_BASE , bool THREAD_SAFE >
239
+ typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::const_iterator xplugin_registry_impl<
240
+ FACTORY_BASE, THREAD_SAFE >::cbegin() const
234
241
{
235
242
return const_iterator (m_lazy_shared_lib_factories.cbegin ());
236
243
}
237
244
238
- template <class FACTORY_BASE , bool THREAD_SAVE >
239
- typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::const_iterator xplugin_registry_impl<
240
- FACTORY_BASE, THREAD_SAVE >::cend() const
245
+ template <class FACTORY_BASE , bool THREAD_SAFE >
246
+ typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::const_iterator xplugin_registry_impl<
247
+ FACTORY_BASE, THREAD_SAFE >::cend() const
241
248
{
242
249
return const_iterator (m_lazy_shared_lib_factories.cend ());
243
250
}
244
251
245
- template <class FACTORY_BASE , bool THREAD_SAVE >
246
- xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::xplugin_registry_impl(const std::filesystem::path &path,
252
+ template <class FACTORY_BASE , bool THREAD_SAFE >
253
+ xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::xplugin_registry_impl(const std::filesystem::path &path,
247
254
const std::string &prefix,
248
255
const std::string &extension)
249
256
{
@@ -252,27 +259,30 @@ namespace xp::detail
252
259
{
253
260
if (entry.path ().extension () == extension)
254
261
{
255
- std::string name = entry.path ().stem ().string ();
256
-
257
- // remove prefix
258
- if (name.substr (0 , prefix.size ()) == prefix)
259
- {
260
- name = name.substr (prefix.size ());
261
- m_lazy_shared_lib_factories.emplace (name, entry.path ());
262
- }
262
+ add_entry (entry.path (), prefix);
263
263
}
264
264
}
265
265
}
266
266
267
- template <class FACTORY_BASE , bool THREAD_SAVE>
268
- bool xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE>::contains(const std::string &name) const
267
+ template <class FACTORY_BASE , bool THREAD_SAFE>
268
+ template <class R , std::enable_if_t <xp::util::is_range_of_v<R, std::filesystem::path>, int >>
269
+ xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE>::xplugin_registry_impl(R r, const std::string& prefix)
270
+ {
271
+ for (const auto & entry: r)
272
+ {
273
+ add_entry (entry, prefix);
274
+ }
275
+ }
276
+
277
+ template <class FACTORY_BASE , bool THREAD_SAFE>
278
+ bool xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE>::contains(const std::string &name) const
269
279
{
270
280
return m_lazy_shared_lib_factories.find (name) != m_lazy_shared_lib_factories.end ();
271
281
}
272
282
273
- template <class FACTORY_BASE , bool THREAD_SAVE >
274
- typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::factory_base_type *xplugin_registry_impl<
275
- FACTORY_BASE, THREAD_SAVE >::operator [](const std::string &name)
283
+ template <class FACTORY_BASE , bool THREAD_SAFE >
284
+ typename xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::factory_base_type *xplugin_registry_impl<
285
+ FACTORY_BASE, THREAD_SAFE >::operator [](const std::string &name)
276
286
{
277
287
auto find_res = m_lazy_shared_lib_factories.find (name);
278
288
if (find_res == m_lazy_shared_lib_factories.end ())
@@ -282,20 +292,32 @@ namespace xp::detail
282
292
return find_res->second .factory ();
283
293
}
284
294
285
- template <class FACTORY_BASE , bool THREAD_SAVE >
286
- std::size_t xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::size() const
295
+ template <class FACTORY_BASE , bool THREAD_SAFE >
296
+ std::size_t xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::size() const
287
297
{
288
298
return m_lazy_shared_lib_factories.size ();
289
299
}
290
300
291
- template <class FACTORY_BASE , bool THREAD_SAVE >
292
- bool xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::empty() const
301
+ template <class FACTORY_BASE , bool THREAD_SAFE >
302
+ bool xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::empty() const
293
303
{
294
304
return m_lazy_shared_lib_factories.empty ();
295
305
}
296
306
297
- template <class FACTORY_BASE , bool THREAD_SAVE>
298
- std::string xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE>::get_default_library_extension()
307
+ template <class FACTORY_BASE , bool THREAD_SAFE>
308
+ void xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE>::add_entry(const std::filesystem::path& p, const std::string& prefix)
309
+ {
310
+ std::string name = p.stem ().string ();
311
+ // remove prefix
312
+ if (name.substr (0 , prefix.size ()) == prefix)
313
+ {
314
+ name = name.substr (prefix.size ());
315
+ m_lazy_shared_lib_factories.emplace (name, p);
316
+ }
317
+ }
318
+
319
+ template <class FACTORY_BASE , bool THREAD_SAFE>
320
+ std::string xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE>::get_default_library_extension()
299
321
{
300
322
#ifdef _WIN32
301
323
return " .dll" ;
@@ -306,8 +328,8 @@ namespace xp::detail
306
328
#endif
307
329
}
308
330
309
- template <class FACTORY_BASE , bool THREAD_SAVE >
310
- std::string xplugin_registry_impl<FACTORY_BASE, THREAD_SAVE >::get_default_library_prefix()
331
+ template <class FACTORY_BASE , bool THREAD_SAFE >
332
+ std::string xplugin_registry_impl<FACTORY_BASE, THREAD_SAFE >::get_default_library_prefix()
311
333
{
312
334
#ifdef _WIN32
313
335
return " " ;
0 commit comments