OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Attributes | Static Private Attributes | Friends | List of all members
WModuleFactory Class Reference

Class able to create a new copy of an arbitrary module. More...

#include <WModuleFactory.h>

+ Collaboration diagram for WModuleFactory:

Public Types

typedef std::shared_ptr< WModuleFactorySPtr
 Shared pointer to a WModule. More...
 
typedef std::shared_ptr< const WModuleFactoryConstSPtr
 Shared pointer to a const WModule. More...
 
typedef std::set< std::shared_ptr< WModule > > PrototypeContainerType
 For shortening: a type defining a shared set of WModule pointers. More...
 
typedef std::set< std::shared_ptr< WModule > >::const_iterator PrototypeContainerConstIteratorType
 Const iterator for the prototype set. More...
 
typedef std::set< std::shared_ptr< WModule > >::iterator PrototypeContainerIteratorType
 Iterator for the prototype set. More...
 
typedef WSharedAssociativeContainer< PrototypeContainerTypePrototypeSharedContainerType
 The alias for a shared container. More...
 

Public Member Functions

virtual ~WModuleFactory ()
 Destructor. More...
 
void load ()
 Loads the modules and creates prototypes. More...
 
std::shared_ptr< WModulecreate (std::shared_ptr< WModule > prototype, std::string uuid="")
 Create a new and initialized module using the specified prototype. More...
 
std::shared_ptr< WModulecreate (std::string prototype, std::string uuid="")
 Create a new and initialized module using the specified prototype. More...
 
const std::shared_ptr< WModuleisPrototypeAvailable (std::string name)
 Searches a prototype by name. More...
 
const std::shared_ptr< WModulegetPrototypeByName (std::string name)
 Finds a prototype using the specified name. More...
 
const std::shared_ptr< WModulegetPrototypeByInstance (std::shared_ptr< WModule > instance)
 Finds a prototype using an instance of a module. More...
 
std::vector< WModule::ConstSPtrgetPrototypesByType (MODULE_TYPE type)
 Finds a prototype using an type. More...
 
PrototypeSharedContainerType::ReadTicket getPrototypes () const
 This method gives read access to the list of all prototypes. More...
 
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. More...
 
WCombinerTypes::WCompatiblesList getAllPrototypes ()
 Creates a list of WApplyCombiner for all modules known by the factory. More...
 
template<typename ModuleType >
std::vector< std::shared_ptr< ModuleType > > getPrototypesByType () const
 Get all module prototypes which are of a certain type. More...
 
std::vector< WDataModule::SPtrgetDataModulePrototypesByInput (WDataModuleInput::ConstSPtr input) const
 Query a list of WDataModule prototypes depending on given input. More...
 

Static Public Member Functions

static SPtr getModuleFactory ()
 Returns instance of the module factory to use to create modules. More...
 
static std::shared_ptr< WModuleLoadergetModuleLoader ()
 Returns instance of the module loader. More...
 
template<typename T >
static bool isA (std::shared_ptr< WModule > module)
 Checks whether the first instance can be casted to the second one. More...
 
static void initializeModule (std::shared_ptr< WModule > module)
 This method uses a newly created instance of WModule and initializes it properly. More...
 
static bool isPrototype (std::shared_ptr< WModule > module)
 Checks whether the specified module is a prototype or an instantiated module. More...
 
static WModule::SPtr findByUUID (std::string uuid)
 Find a module instance by UUID. More...
 

Protected Member Functions

 WModuleFactory ()
 Constructors are protected because this is a Singleton. More...
 
bool checkPrototype (std::shared_ptr< WModule > module, PrototypeSharedContainerType::ReadTicket ticket)
 Checks whether the specified module is a prototype or an instantiated module. More...
 

Protected Attributes

PrototypeSharedContainerType m_prototypes
 The module prototypes available. More...
 

Private Types

typedef std::map< std::string, std::weak_ptr< WModule > > UuidModuleMap
 Mapping between a UUID and a module. More...
 

Private Attributes

WModuleLoader::SPtr m_moduleLoader
 Loader class managing dynamically loaded modules in OpenWalnut. More...
 
WSharedAssociativeContainer< UuidModuleMapm_uuidModuleMap
 Keep track of uuids of each created module. More...
 

Static Private Attributes

static std::shared_ptr< WModuleFactorym_instance = std::shared_ptr< WModuleFactory >()
 Singleton instance of WModuleFactory. More...
 

Friends

class WModuleFactoryTest
 Access for test class. More...
 

Detailed Description

Class able to create a new copy of an arbitrary module.

It uses the Factory and Prototype design pattern.

Definition at line 46 of file WModuleFactory.h.

Member Typedef Documentation

◆ ConstSPtr

typedef std::shared_ptr< const WModuleFactory > WModuleFactory::ConstSPtr

Shared pointer to a const WModule.

Definition at line 58 of file WModuleFactory.h.

◆ PrototypeContainerConstIteratorType

typedef std::set< std::shared_ptr< WModule > >::const_iterator WModuleFactory::PrototypeContainerConstIteratorType

Const iterator for the prototype set.

Definition at line 68 of file WModuleFactory.h.

◆ PrototypeContainerIteratorType

typedef std::set< std::shared_ptr< WModule > >::iterator WModuleFactory::PrototypeContainerIteratorType

Iterator for the prototype set.

Definition at line 73 of file WModuleFactory.h.

◆ PrototypeContainerType

typedef std::set< std::shared_ptr< WModule > > WModuleFactory::PrototypeContainerType

For shortening: a type defining a shared set of WModule pointers.

Definition at line 63 of file WModuleFactory.h.

◆ PrototypeSharedContainerType

The alias for a shared container.

Definition at line 78 of file WModuleFactory.h.

◆ SPtr

typedef std::shared_ptr< WModuleFactory > WModuleFactory::SPtr

Shared pointer to a WModule.

Definition at line 53 of file WModuleFactory.h.

◆ UuidModuleMap

typedef std::map< std::string, std::weak_ptr< WModule > > WModuleFactory::UuidModuleMap
private

Mapping between a UUID and a module.

Definition at line 285 of file WModuleFactory.h.

Constructor & Destructor Documentation

◆ ~WModuleFactory()

WModuleFactory::~WModuleFactory ( )
virtual

Destructor.

Definition at line 52 of file WModuleFactory.cpp.

◆ WModuleFactory()

WModuleFactory::WModuleFactory ( )
protected

Constructors are protected because this is a Singleton.

Definition at line 45 of file WModuleFactory.cpp.

Referenced by getModuleFactory().

+ Here is the caller graph for this function:

Member Function Documentation

◆ checkPrototype()

bool WModuleFactory::checkPrototype ( std::shared_ptr< WModule module,
PrototypeSharedContainerType::ReadTicket  ticket 
)
protected

Checks whether the specified module is a prototype or an instantiated module.

Use isPrototype if no ticket acquired yet.

Parameters
modulethe module to check
ticketticket which already has read lock.
Returns
true if it is a prototype

Definition at line 107 of file WModuleFactory.cpp.

Referenced by create().

+ Here is the caller graph for this function:

◆ create() [1/2]

std::shared_ptr< WModule > WModuleFactory::create ( std::shared_ptr< WModule prototype,
std::string  uuid = "" 
)

Create a new and initialized module using the specified prototype.

Parameters
prototypethe prototype to clone.
uuidthe uuid to use for the created module. If you specify an empty string (default), a uuid will be created. This parameter is useful for the project loader.
Returns
the module created using the prototype.

Definition at line 117 of file WModuleFactory.cpp.

References checkPrototype(), wlog::debug(), WSharedObject< T >::getReadTicket(), initializeModule(), WSharedAssociativeContainer< T >::insert(), m_prototypes, and m_uuidModuleMap.

Referenced by create().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create() [2/2]

std::shared_ptr< WModule > WModuleFactory::create ( std::string  prototype,
std::string  uuid = "" 
)

Create a new and initialized module using the specified prototype.

This might fail if the prototype with this name cannot be found. Please refer to getPrototypeByName.

Parameters
prototypethe prototype to clone as name.
uuidthe uuid to use for the created module. If you specify an empty string (default), a uuid will be created. This parameter is useful for the project loader.
Returns
the module created using the prototype.

Definition at line 112 of file WModuleFactory.cpp.

References create(), and getPrototypeByName().

+ Here is the call graph for this function:

◆ findByUUID()

WModule::SPtr WModuleFactory::findByUUID ( std::string  uuid)
static

Find a module instance by UUID.

Parameters
uuidthe uuid to search for.
Returns
the module, or NULL if not found

Definition at line 319 of file WModuleFactory.cpp.

References getModuleFactory(), and WSharedObject< T >::getReadTicket().

Referenced by WModule::findByUUID().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAllPrototypes()

WCombinerTypes::WCompatiblesList WModuleFactory::getAllPrototypes ( )

Creates a list of WApplyCombiner for all modules known by the factory.

Returns
list of apply combiner.

Definition at line 289 of file WModuleFactory.cpp.

References WSharedObject< T >::getReadTicket(), and m_prototypes.

+ Here is the call graph for this function:

◆ getCompatiblePrototypes()

WCombinerTypes::WCompatiblesList WModuleFactory::getCompatiblePrototypes ( std::shared_ptr< WModule module = std::shared_ptr< WModule >())

Returns a set of module combiners with module combinations compatible with the specified one.

Parameters
modulethe module to find the compatibles for.
Note
as the default parameter denotes, providing a NULL pointer (or calling the method without a parameter) returns the list of modules which are compatible to every other module. In other words, it returns all modules without input connectors. If the specified module is not NULL, the modules without input are not listed.
Returns
set of compatible combiners.

Definition at line 225 of file WModuleFactory.cpp.

References WSharedObject< T >::getReadTicket(), and m_prototypes.

+ Here is the call graph for this function:

◆ getDataModulePrototypesByInput()

std::vector< WDataModule::SPtr > WModuleFactory::getDataModulePrototypesByInput ( WDataModuleInput::ConstSPtr  input) const

Query a list of WDataModule prototypes depending on given input.

Parameters
inputthe input to use for matching
Returns
the list (can be empty).

Definition at line 339 of file WModuleFactory.cpp.

References WDataModule::getInputFilter(), and getModuleFactory().

+ Here is the call graph for this function:

◆ getModuleFactory()

std::shared_ptr< WModuleFactory > WModuleFactory::getModuleFactory ( )
static

◆ getModuleLoader()

std::shared_ptr< WModuleLoader > WModuleFactory::getModuleLoader ( )
static

Returns instance of the module loader.

Returns
the running module loader.

Definition at line 57 of file WModuleFactory.cpp.

References getModuleFactory().

Referenced by WKernel::threadMain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPrototypeByInstance()

const std::shared_ptr< WModule > WModuleFactory::getPrototypeByInstance ( std::shared_ptr< WModule instance)

Finds a prototype using an instance of a module.

This uses the type_info to find a proper prototype.

Parameters
instancethe instance to use.
Returns
the prototype.
Exceptions
WPrototypeUnknownif prototype can not be found.

Definition at line 195 of file WModuleFactory.cpp.

References getPrototypeByName().

+ Here is the call graph for this function:

◆ getPrototypeByName()

const std::shared_ptr< WModule > WModuleFactory::getPrototypeByName ( std::string  name)

Finds a prototype using the specified name.

Parameters
namethe name.
Exceptions
WPrototypeUnknownif the prototype is not known. Use isPrototypeAvailable first to check.
Returns
the prototype whose name is equal to the specified one.

Definition at line 182 of file WModuleFactory.cpp.

References isPrototypeAvailable().

Referenced by create(), and getPrototypeByInstance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPrototypes()

WModuleFactory::PrototypeSharedContainerType::ReadTicket WModuleFactory::getPrototypes ( ) const

This method gives read access to the list of all prototypes.

Returns
the read ticket for the prototype list

Definition at line 220 of file WModuleFactory.cpp.

References WSharedObject< T >::getReadTicket(), and m_prototypes.

+ Here is the call graph for this function:

◆ getPrototypesByType() [1/2]

template<typename ModuleType >
std::vector< std::shared_ptr< ModuleType > > WModuleFactory::getPrototypesByType

Get all module prototypes which are of a certain type.

Template Parameters
ModuleTypethe type
Returns
the list of module prototypes.

Definition at line 301 of file WModuleFactory.h.

References WSharedObject< T >::getReadTicket(), and m_prototypes.

+ Here is the call graph for this function:

◆ getPrototypesByType() [2/2]

std::vector< WModule::ConstSPtr > WModuleFactory::getPrototypesByType ( MODULE_TYPE  type)

Finds a prototype using an type.

Parameters
typethe type of module.
Returns
the prototypes as list.

Definition at line 200 of file WModuleFactory.cpp.

References WSharedObject< T >::getReadTicket(), and m_prototypes.

+ Here is the call graph for this function:

◆ initializeModule()

void WModuleFactory::initializeModule ( std::shared_ptr< WModule module)
static

This method uses a newly created instance of WModule and initializes it properly.

After using this method, the module is properly initialized and ready to be used.

Parameters
modulethe module to initialize.

Definition at line 146 of file WModuleFactory.cpp.

Referenced by create(), and load().

+ Here is the caller graph for this function:

◆ isA()

template<typename T >
bool WModuleFactory::isA ( std::shared_ptr< WModule module)
static

Checks whether the first instance can be casted to the second one.

Parameters
modulethe module to check.
Returns
true if the dynamic_cast is successful

Definition at line 294 of file WModuleFactory.h.

◆ isPrototype()

bool WModuleFactory::isPrototype ( std::shared_ptr< WModule module)
static

Checks whether the specified module is a prototype or an instantiated module.

Parameters
modulethe module to check
Returns
true if it is a prototype

Definition at line 100 of file WModuleFactory.cpp.

References getModuleFactory().

Referenced by WApplyCombiner::apply().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isPrototypeAvailable()

const std::shared_ptr< WModule > WModuleFactory::isPrototypeAvailable ( std::string  name)

Searches a prototype by name.

It returns the prototype, or a NULL pointer if it is not found. The difference to getPrototypeByName() is, that an unavailable prototype does not throw an exception. This is nice for checking whether a prototype exists or not.

Parameters
namename of the prototype to search
Returns
the prototype if it exists, or NULL if not.

Definition at line 162 of file WModuleFactory.cpp.

References WSharedObject< T >::getReadTicket(), and m_prototypes.

Referenced by getPrototypeByName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load()

void WModuleFactory::load ( )

Loads the modules and creates prototypes.

Definition at line 62 of file WModuleFactory.cpp.

References WLogger::addLogMessage(), WLogger::getLogger(), WSharedObject< T >::getWriteTicket(), initializeModule(), m_moduleLoader, and m_prototypes.

+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ WModuleFactoryTest

friend class WModuleFactoryTest
friend

Access for test class.

Definition at line 48 of file WModuleFactory.h.

Member Data Documentation

◆ m_instance

std::shared_ptr< WModuleFactory > WModuleFactory::m_instance = std::shared_ptr< WModuleFactory >()
staticprivate

Singleton instance of WModuleFactory.

Definition at line 280 of file WModuleFactory.h.

Referenced by getModuleFactory().

◆ m_moduleLoader

WModuleLoader::SPtr WModuleFactory::m_moduleLoader
private

Loader class managing dynamically loaded modules in OpenWalnut.

Definition at line 275 of file WModuleFactory.h.

Referenced by load().

◆ m_prototypes

PrototypeSharedContainerType WModuleFactory::m_prototypes
protected

The module prototypes available.

Definition at line 259 of file WModuleFactory.h.

Referenced by create(), getAllPrototypes(), getCompatiblePrototypes(), getPrototypes(), getPrototypesByType(), isPrototypeAvailable(), and load().

◆ m_uuidModuleMap

WSharedAssociativeContainer< UuidModuleMap > WModuleFactory::m_uuidModuleMap
private

Keep track of uuids of each created module.

This is needed to find module pointers using uuid.

Definition at line 290 of file WModuleFactory.h.

Referenced by create().


The documentation for this class was generated from the following files: