27#ifndef ASYNC_FACTORY_INCLUDED
28#define ASYNC_FACTORY_INCLUDED
147template <
class T,
typename... Args>
159 typename std::map<std::string,
Factory<T, Args...>*>::iterator it;
160 it = factories().find(name);
161 if (it == factories().end())
166 return (*it).second->createObject(args...);
178 std::stringstream ss;
179 for (
typename FactoryMap::const_iterator it = factories().begin();
180 it != factories().end(); ++it)
182 ss <<
"\"" << (*it).first <<
"\" ";
191 Factory(
const std::string &name) : m_name(name)
193 typename FactoryMap::iterator it = factories().find(m_name);
194 assert(it == factories().end());
195 factories()[name] =
this;
213 typename FactoryMap::iterator it = factories().find(m_name);
214 assert(it != factories().end());
215 factories().erase(it);
227 typedef std::map<std::string,
Factory<T, Args...>*> FactoryMap;
230 static FactoryMap& factories(
void)
232 static FactoryMap factory_map;
289template <
class Base,
class T,
typename... Args>
306 return new T(args...);
Factory(const Factory< T, Args... > &)=delete
Don't allow copy construction.
static std::string validFactories(void)
Get a list of valid class names.
virtual ~Factory(void)
Destructor.
virtual T * createObject(Args... args)=0
Create and return a new instance of an object.
Factory(const std::string &name)
Constructor.
Factory & operator=(const Factory< T, Args... > &)=delete
Don't allow assignment.
static T * createNamedObject(const std::string &name, Args... args)
Create an instance of the named class.
SpecificFactory(const std::string &name)
Constructor.
T * createObject(Args... args)
Create and return a new instance of an object.
Namespace for the asynchronous programming classes.