From 7ec6683874d60be3a62bdc0e2f4d3eba58b390d6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 30 Sep 2015 13:56:52 +0100 Subject: Use __VA_ARGS__ to remove need for global typedef in macro --- libadhocutil/factory.impl.h | 6 ++---- libadhocutil/plugins.impl.h | 18 +++++++++--------- libadhocutil/unittests/testFactory.cpp | 4 ++++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/libadhocutil/factory.impl.h b/libadhocutil/factory.impl.h index bbba002..c257884 100644 --- a/libadhocutil/factory.impl.h +++ b/libadhocutil/factory.impl.h @@ -25,13 +25,11 @@ namespace AdHoc { #define INSTANTIATEVOIDFACTORY(Base) \ template class AdHoc::Factory; \ - typedef AdHoc::Factory FactoryType; \ - INSTANTIATEPLUGINOF(FactoryType) + INSTANTIATEPLUGINOF(AdHoc::Factory) #define INSTANTIATEFACTORY(Base, ...) \ template class AdHoc::Factory; \ - typedef AdHoc::Factory FactoryType; \ - INSTANTIATEPLUGINOF(FactoryType) + INSTANTIATEPLUGINOF(AdHoc::Factory) #endif diff --git a/libadhocutil/plugins.impl.h b/libadhocutil/plugins.impl.h index 1947845..8b64002 100644 --- a/libadhocutil/plugins.impl.h +++ b/libadhocutil/plugins.impl.h @@ -89,15 +89,15 @@ namespace AdHoc { } } -#define INSTANTIATEPLUGINOF(T) \ - template class AdHoc::PluginOf; \ - template void AdHoc::PluginManager::add(T *, const std::string &, const std::string &, int); \ - template void AdHoc::PluginManager::remove(const std::string &); \ - template boost::shared_ptr> AdHoc::PluginManager::get(const std::string &) const; \ - template T * AdHoc::PluginManager::getImplementation(const std::string &) const; \ - template std::set>> AdHoc::PluginManager::getAll() const; \ - template void AdHoc::PluginManager::addResolver(const AdHoc::PluginManager::PluginResolver & f); \ - template void AdHoc::PluginManager::removeResolver(); \ +#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::remove<__VA_ARGS__>(const std::string &); \ + template boost::shared_ptr> AdHoc::PluginManager::get<__VA_ARGS__>(const std::string &) const; \ + template __VA_ARGS__ * AdHoc::PluginManager::getImplementation<__VA_ARGS__>(const std::string &) const; \ + template std::set>> 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__>(); \ #define PLUGINRESOLVER(T, F) \ namespace MAKE_UNIQUE(__plugin__) { \ diff --git a/libadhocutil/unittests/testFactory.cpp b/libadhocutil/unittests/testFactory.cpp index 24f731f..7a94aa9 100644 --- a/libadhocutil/unittests/testFactory.cpp +++ b/libadhocutil/unittests/testFactory.cpp @@ -33,6 +33,10 @@ NAMEDFACTORY("a", ImplOfThing, BaseThingFactory); FACTORY(OtherImplOfThing, BaseThingFactory); INSTANTIATEFACTORY(BaseThing, int, std::string); +// Multiple factories in one compilation unit +INSTANTIATEFACTORY(BaseThing, std::string, std::string); +// Factories of things with commas +INSTANTIATEFACTORY(BaseThing, std::map); BOOST_AUTO_TEST_CASE( ready ) { -- cgit v1.2.3