OpenWalnut  1.3.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | 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>

Public Types

typedef std::set
< boost::shared_ptr< WModule > > 
PrototypeContainerType
 For shortening: a type defining a shared set of WModule pointers. More...
 
typedef std::set
< boost::shared_ptr< WModule >
>::const_iterator 
PrototypeContainerConstIteratorType
 Const iterator for the prototype set. More...
 
typedef std::set
< boost::shared_ptr< WModule >
>::iterator 
PrototypeContainerIteratorType
 Iterator for the prototype set. More...
 
typedef
WSharedAssociativeContainer
< PrototypeContainerType
PrototypeSharedContainerType
 The alias for a shared container. More...
 

Public Member Functions

virtual ~WModuleFactory ()
 Destructor. More...
 
void load ()
 Loads the modules and creates prototypes. More...
 
boost::shared_ptr< WModulecreate (boost::shared_ptr< WModule > prototype)
 Create a new and initialized module using the specified prototype. More...
 
const boost::shared_ptr< WModuleisPrototypeAvailable (std::string name)
 Searches a prototype by name. More...
 
const boost::shared_ptr< WModulegetPrototypeByName (std::string name)
 Finds a prototype using the specified name. More...
 
const boost::shared_ptr< WModulegetPrototypeByInstance (boost::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 (boost::shared_ptr< WModule > module=boost::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 T >
bool isA (boost::shared_ptr< WModule > module)
 

Static Public Member Functions

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

Protected Member Functions

 WModuleFactory ()
 Constructors are protected because this is a Singleton. More...
 
bool checkPrototype (boost::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 Attributes

WModuleLoader m_moduleLoader
 Loader class managing dynamically loaded modules in OpenWalnut. More...
 

Static Private Attributes

static boost::shared_ptr
< WModuleFactory
m_instance = boost::shared_ptr< WModuleFactory >()
 Singleton instance of WModuleFactory. More...
 

Friends

class WModuleFactoryTest
 

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

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

Const iterator for the prototype set.

Definition at line 58 of file WModuleFactory.h.

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

Iterator for the prototype set.

Definition at line 63 of file WModuleFactory.h.

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

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

Definition at line 53 of file WModuleFactory.h.

The alias for a shared container.

Definition at line 68 of file WModuleFactory.h.

Constructor & Destructor Documentation

WModuleFactory::~WModuleFactory ( )
virtual

Destructor.

Definition at line 50 of file WModuleFactory.cpp.

WModuleFactory::WModuleFactory ( )
protected

Constructors are protected because this is a Singleton.

Definition at line 43 of file WModuleFactory.cpp.

Referenced by getModuleFactory().

Member Function Documentation

bool WModuleFactory::checkPrototype ( boost::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 100 of file WModuleFactory.cpp.

Referenced by create().

boost::shared_ptr< WModule > WModuleFactory::create ( boost::shared_ptr< WModule prototype)

Create a new and initialized module using the specified prototype.

Parameters
prototypethe prototype to clone.
Returns
the module created using the prototype.

Definition at line 105 of file WModuleFactory.cpp.

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

WCombinerTypes::WCompatiblesList WModuleFactory::getAllPrototypes ( )

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

Returns
list of apply combiner.

Definition at line 266 of file WModuleFactory.cpp.

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

WCombinerTypes::WCompatiblesList WModuleFactory::getCompatiblePrototypes ( boost::shared_ptr< WModule module = boost::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.
Notes:
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 208 of file WModuleFactory.cpp.

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

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

Returns instance of the module factory to use to create modules.

Returns
the running module factory.

Definition at line 134 of file WModuleFactory.cpp.

References m_instance, and WModuleFactory().

Referenced by WApplyCombiner::apply(), WModuleContainer::applyModule(), WModuleContainer::createAndAdd(), WKernel::init(), WPrototypeRequirement::isComplied(), isPrototype(), WModuleProjectFileCombiner::parse(), and WBatchLoader::threadMain().

const boost::shared_ptr< WModule > WModuleFactory::getPrototypeByInstance ( boost::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 178 of file WModuleFactory.cpp.

References getPrototypeByName().

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

Finds a prototype using the specified name.

Parameters
namethe name.
Returns
the prototype whose name is equal to the specified one.

Definition at line 165 of file WModuleFactory.cpp.

References isPrototypeAvailable().

Referenced by getPrototypeByInstance().

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 203 of file WModuleFactory.cpp.

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

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 183 of file WModuleFactory.cpp.

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

void WModuleFactory::initializeModule ( boost::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 129 of file WModuleFactory.cpp.

Referenced by create(), and load().

template<typename T >
static bool WModuleFactory::isA ( boost::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
bool WModuleFactory::isPrototype ( boost::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 93 of file WModuleFactory.cpp.

References getModuleFactory().

Referenced by WApplyCombiner::apply().

const boost::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 145 of file WModuleFactory.cpp.

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

Referenced by getPrototypeByName().

void WModuleFactory::load ( )

Member Data Documentation

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

Singleton instance of WModuleFactory.

Definition at line 221 of file WModuleFactory.h.

Referenced by getModuleFactory().

WModuleLoader WModuleFactory::m_moduleLoader
private

Loader class managing dynamically loaded modules in OpenWalnut.

Definition at line 216 of file WModuleFactory.h.

Referenced by load().

PrototypeSharedContainerType WModuleFactory::m_prototypes
protected

The module prototypes available.

Definition at line 200 of file WModuleFactory.h.

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


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