summaryrefslogtreecommitdiff
path: root/libadhocutil/plugins.impl.h
diff options
context:
space:
mode:
Diffstat (limited to 'libadhocutil/plugins.impl.h')
-rw-r--r--libadhocutil/plugins.impl.h43
1 files changed, 22 insertions, 21 deletions
diff --git a/libadhocutil/plugins.impl.h b/libadhocutil/plugins.impl.h
index 8b64002..6f8da05 100644
--- a/libadhocutil/plugins.impl.h
+++ b/libadhocutil/plugins.impl.h
@@ -5,18 +5,12 @@
namespace AdHoc {
template <typename T>
- PluginOf<T>::PluginOf(T * t, const std::string & n, const std::string & f, int l) :
+ PluginOf<T>::PluginOf(const std::shared_ptr<T> & t, const std::string & n, const std::string & f, int l) :
Plugin(n, f, l),
impl(t)
{
}
- template <typename T>
- PluginOf<T>::~PluginOf()
- {
- delete impl;
- }
-
/// Get the type of this plugin.
template <typename T>
const std::type_info &
@@ -27,17 +21,24 @@ namespace AdHoc {
/// Get the implementation of this plugin.
template <typename T>
- T *
+ std::shared_ptr<T>
PluginOf<T>::implementation() const
{
return impl;
}
template <typename T>
+ std::shared_ptr<AbstractPluginImplementation>
+ PluginOf<T>::instance() const
+ {
+ return impl;
+ }
+
+ template <typename T>
void
- PluginManager::add(T * i, const std::string & n, const std::string & f, int l)
+ PluginManager::add(const std::shared_ptr<T> & i, const std::string & n, const std::string & f, int l)
{
- add(PluginPtr(new PluginOf<T>(i, n, f, l)));
+ add(std::make_shared<PluginOf<T>>(i, n, f, l));
}
template <typename T>
@@ -48,26 +49,26 @@ namespace AdHoc {
}
template <typename T>
- boost::shared_ptr<const PluginOf<T>>
+ std::shared_ptr<const PluginOf<T>>
PluginManager::get(const std::string & n) const
{
- return boost::dynamic_pointer_cast<const PluginOf<T>>(get(n, typeid(T)));
+ return std::dynamic_pointer_cast<const PluginOf<T>>(get(n, typeid(T)));
}
template <typename T>
- T *
+ std::shared_ptr<T>
PluginManager::getImplementation(const std::string & n) const
{
- return get<T>(n)->implementation();
+ return std::static_pointer_cast<T>(get<T>(n)->implementation());
}
template <typename T>
- std::set<boost::shared_ptr<const PluginOf<T>>>
+ std::set<std::shared_ptr<const PluginOf<T>>>
PluginManager::getAll() const
{
- std::set<boost::shared_ptr<const PluginOf<T>>> all;
+ std::set<std::shared_ptr<const PluginOf<T>>> all;
for(const auto & p : getAll(typeid(T))) {
- if (auto tp = boost::dynamic_pointer_cast<const PluginOf<T>>(p)) {
+ if (auto tp = std::dynamic_pointer_cast<const PluginOf<T>>(p)) {
all.insert(tp);
}
}
@@ -91,11 +92,11 @@ namespace AdHoc {
#define INSTANTIATEPLUGINOF(...) \
template class AdHoc::PluginOf<__VA_ARGS__>; \
- template void AdHoc::PluginManager::add<__VA_ARGS__>(__VA_ARGS__ *, const std::string &, const std::string &, int); \
+ template void AdHoc::PluginManager::add<__VA_ARGS__>(const std::shared_ptr<__VA_ARGS__> &, const std::string &, const std::string &, int); \
template void AdHoc::PluginManager::remove<__VA_ARGS__>(const std::string &); \
- template boost::shared_ptr<const AdHoc::PluginOf<__VA_ARGS__>> AdHoc::PluginManager::get<__VA_ARGS__>(const std::string &) const; \
- template __VA_ARGS__ * AdHoc::PluginManager::getImplementation<__VA_ARGS__>(const std::string &) const; \
- template std::set<boost::shared_ptr<const AdHoc::PluginOf<__VA_ARGS__>>> AdHoc::PluginManager::getAll<__VA_ARGS__>() const; \
+ template std::shared_ptr<const AdHoc::PluginOf<__VA_ARGS__>> AdHoc::PluginManager::get<__VA_ARGS__>(const std::string &) const; \
+ template std::shared_ptr<__VA_ARGS__> AdHoc::PluginManager::getImplementation<__VA_ARGS__>(const std::string &) const; \
+ template std::set<std::shared_ptr<const AdHoc::PluginOf<__VA_ARGS__>>> AdHoc::PluginManager::getAll<__VA_ARGS__>() const; \
template void AdHoc::PluginManager::addResolver<__VA_ARGS__>(const AdHoc::PluginManager::PluginResolver & f); \
template void AdHoc::PluginManager::removeResolver<__VA_ARGS__>(); \