25 #ifndef WMODULEFACTORY_H
26 #define WMODULEFACTORY_H
35 #include <boost/weak_ptr.hpp>
37 #include "../common/WSharedAssociativeContainer.h"
38 #include "WDataModule.h"
40 #include "WModuleCombinerTypes.h"
41 #include "WModuleLoader.h"
53 typedef std::shared_ptr< WModuleFactory >
SPtr;
58 typedef std::shared_ptr< const WModuleFactory >
ConstSPtr;
99 std::shared_ptr< WModule >
create( std::shared_ptr< WModule > prototype, std::string uuid =
"" );
111 std::shared_ptr< WModule >
create( std::string prototype, std::string uuid =
"" );
181 template <
typename T>
182 static bool isA( std::shared_ptr< WModule > module );
196 std::shared_ptr< WModule > module = std::shared_ptr< WModule >()
221 static bool isPrototype( std::shared_ptr< WModule > module );
239 template<
typename ModuleType >
293 template <
typename T>
297 return (
dynamic_cast< T*
>( module.get() ) );
300 template<
typename ModuleType >
303 std::vector< std::shared_ptr< ModuleType > > results;
312 std::shared_ptr< ModuleType > asTargetType = std::dynamic_pointer_cast< ModuleType >( *listIter );
316 results.push_back( asTargetType );
Class able to create a new copy of an arbitrary module.
const std::shared_ptr< WModule > isPrototypeAvailable(std::string name)
Searches a prototype by name.
PrototypeSharedContainerType m_prototypes
The module prototypes available.
static std::shared_ptr< WModuleFactory > m_instance
Singleton instance of WModuleFactory.
WSharedAssociativeContainer< UuidModuleMap > m_uuidModuleMap
Keep track of uuids of each created module.
std::shared_ptr< WModuleFactory > SPtr
Shared pointer to a WModule.
WCombinerTypes::WCompatiblesList getCompatiblePrototypes(std::shared_ptr< WModule > module=std::shared_ptr< WModule >())
Returns a set of module combiners with module combinations compatible with the specified one.
WCombinerTypes::WCompatiblesList getAllPrototypes()
Creates a list of WApplyCombiner for all modules known by the factory.
PrototypeSharedContainerType::ReadTicket getPrototypes() const
This method gives read access to the list of all prototypes.
static WModule::SPtr findByUUID(std::string uuid)
Find a module instance by UUID.
std::shared_ptr< WModule > create(std::shared_ptr< WModule > prototype, std::string uuid="")
Create a new and initialized module using the specified prototype.
std::set< std::shared_ptr< WModule > >::const_iterator PrototypeContainerConstIteratorType
Const iterator for the prototype set.
friend class WModuleFactoryTest
Access for test class.
const std::shared_ptr< WModule > getPrototypeByInstance(std::shared_ptr< WModule > instance)
Finds a prototype using an instance of a module.
static bool isA(std::shared_ptr< WModule > module)
Checks whether the first instance can be casted to the second one.
static SPtr getModuleFactory()
Returns instance of the module factory to use to create modules.
std::set< std::shared_ptr< WModule > >::iterator PrototypeContainerIteratorType
Iterator for the prototype set.
std::vector< WDataModule::SPtr > getDataModulePrototypesByInput(WDataModuleInput::ConstSPtr input) const
Query a list of WDataModule prototypes depending on given input.
void load()
Loads the modules and creates prototypes.
WModuleLoader::SPtr m_moduleLoader
Loader class managing dynamically loaded modules in OpenWalnut.
virtual ~WModuleFactory()
Destructor.
static void initializeModule(std::shared_ptr< WModule > module)
This method uses a newly created instance of WModule and initializes it properly.
WSharedAssociativeContainer< PrototypeContainerType > PrototypeSharedContainerType
The alias for a shared container.
const std::shared_ptr< WModule > getPrototypeByName(std::string name)
Finds a prototype using the specified name.
std::set< std::shared_ptr< WModule > > PrototypeContainerType
For shortening: a type defining a shared set of WModule pointers.
std::vector< std::shared_ptr< ModuleType > > getPrototypesByType() const
Get all module prototypes which are of a certain type.
bool checkPrototype(std::shared_ptr< WModule > module, PrototypeSharedContainerType::ReadTicket ticket)
Checks whether the specified module is a prototype or an instantiated module.
std::map< std::string, std::weak_ptr< WModule > > UuidModuleMap
Mapping between a UUID and a module.
static bool isPrototype(std::shared_ptr< WModule > module)
Checks whether the specified module is a prototype or an instantiated module.
std::shared_ptr< const WModuleFactory > ConstSPtr
Shared pointer to a const WModule.
WModuleFactory()
Constructors are protected because this is a Singleton.
static std::shared_ptr< WModuleLoader > getModuleLoader()
Returns instance of the module loader.
std::shared_ptr< WModuleLoader > SPtr
Shared pointer abbreviation.
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.