55 * *
66 * The full license is in the file LICENSE, distributed with this software. *
77 ****************************************************************************/
8+
89#ifndef XPLUGIN_REGISTRY_HPP
910#define XPLUGIN_REGISTRY_HPP
1011
1718
1819#include < xplugin/xlazy_shared_library_plugin_factory.hpp>
1920#include < xplugin/xplugin_config.hpp>
21+ #include < xplugin/xplugin_util.hpp>
2022
2123namespace xp ::detail
2224{
23-
2425 template <class FACTORY_BASE , bool THREAD_SAFE>
2526 class xplugin_registry_impl ;
2627
@@ -95,11 +96,15 @@ namespace xp::detail
9596 using const_iterator = xplugin_registry_iterator<self_type, typename storage_map_type::const_iterator>;
9697 using iterator = xplugin_registry_iterator<self_type, typename storage_map_type::iterator>;
9798
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());
101102
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);
103108
104109 std::size_t size () const ;
105110 bool empty () const ;
@@ -116,6 +121,8 @@ namespace xp::detail
116121
117122 private:
118123
124+ void add_entry (const std::filesystem::path& path, const std::string& prefix);
125+
119126 static std::string get_default_library_extension ();
120127 static std::string get_default_library_prefix ();
121128
@@ -199,51 +206,51 @@ namespace xp::detail
199206 }
200207
201208 // 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()
205212 {
206213 return iterator (m_lazy_shared_lib_factories.begin ());
207214 }
208215
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()
212219 {
213220 return iterator (m_lazy_shared_lib_factories.end ());
214221 }
215222
216223 // 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
220227 {
221228 return const_iterator (m_lazy_shared_lib_factories.cbegin ());
222229 }
223230
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
227234 {
228235 return const_iterator (m_lazy_shared_lib_factories.cend ());
229236 }
230237
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
234241 {
235242 return const_iterator (m_lazy_shared_lib_factories.cbegin ());
236243 }
237244
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
241248 {
242249 return const_iterator (m_lazy_shared_lib_factories.cend ());
243250 }
244251
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,
247254 const std::string &prefix,
248255 const std::string &extension)
249256 {
@@ -252,27 +259,30 @@ namespace xp::detail
252259 {
253260 if (entry.path ().extension () == extension)
254261 {
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);
263263 }
264264 }
265265 }
266266
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
269279 {
270280 return m_lazy_shared_lib_factories.find (name) != m_lazy_shared_lib_factories.end ();
271281 }
272282
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)
276286 {
277287 auto find_res = m_lazy_shared_lib_factories.find (name);
278288 if (find_res == m_lazy_shared_lib_factories.end ())
@@ -282,20 +292,32 @@ namespace xp::detail
282292 return find_res->second .factory ();
283293 }
284294
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
287297 {
288298 return m_lazy_shared_lib_factories.size ();
289299 }
290300
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
293303 {
294304 return m_lazy_shared_lib_factories.empty ();
295305 }
296306
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()
299321 {
300322#ifdef _WIN32
301323 return " .dll" ;
@@ -306,8 +328,8 @@ namespace xp::detail
306328#endif
307329 }
308330
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()
311333 {
312334#ifdef _WIN32
313335 return " " ;
0 commit comments