OpenWalnut
1.2.5
|
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. | |
typedef std::set < boost::shared_ptr< WModule > >::const_iterator | PrototypeContainerConstIteratorType |
Const iterator for the prototype set. | |
typedef std::set < boost::shared_ptr< WModule > >::iterator | PrototypeContainerIteratorType |
Iterator for the prototype set. | |
typedef WSharedAssociativeContainer < PrototypeContainerType > | PrototypeSharedContainerType |
The alias for a shared container. |
Public Member Functions | |
virtual | ~WModuleFactory () |
Destructor. | |
void | load () |
Loads the modules and creates prototypes. | |
boost::shared_ptr< WModule > | create (boost::shared_ptr< WModule > prototype) |
Create a new and initialized module using the specified prototype. | |
const boost::shared_ptr< WModule > | isPrototypeAvailable (std::string name) |
Searches a prototype by name. | |
const boost::shared_ptr< WModule > | getPrototypeByName (std::string name) |
Finds a prototype using the specified name. | |
const boost::shared_ptr< WModule > | getPrototypeByInstance (boost::shared_ptr< WModule > instance) |
Finds a prototype using an instance of a module. | |
std::vector< WModule::ConstSPtr > | getPrototypesByType (MODULE_TYPE type) |
Finds a prototype using an type. | |
PrototypeSharedContainerType::ReadTicket | getPrototypes () const |
This method gives read access to the list of all prototypes. | |
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. |
Static Public Member Functions | |
static boost::shared_ptr < WModuleFactory > | getModuleFactory () |
Returns instance of the module factory to use to create modules. | |
template<typename T > | |
static bool | isA (boost::shared_ptr< WModule > module) |
Checks whether the first instance can be casted to the second one. | |
static void | initializeModule (boost::shared_ptr< WModule > module) |
This method uses a newly created instance of WModule and initializes it properly. | |
static bool | isPrototype (boost::shared_ptr< WModule > module) |
Checks whether the specified module is a prototype or an instantiated module. |
Protected Member Functions | |
WModuleFactory () | |
Constructors are protected because this is a Singleton. | |
bool | checkPrototype (boost::shared_ptr< WModule > module, PrototypeSharedContainerType::ReadTicket ticket) |
Checks whether the specified module is a prototype or an instantiated module. |
Protected Attributes | |
PrototypeSharedContainerType | m_prototypes |
The module prototypes available. |
Private Attributes | |
WModuleLoader | m_moduleLoader |
Loader class managing dynamically loaded modules in OpenWalnut. |
Static Private Attributes | |
static boost::shared_ptr < WModuleFactory > | m_instance = boost::shared_ptr< WModuleFactory >() |
Singleton instance of WModuleFactory. |
Friends | |
class | WModuleFactoryTest |
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.
typedef std::set< boost::shared_ptr< WModule > >::const_iterator WModuleFactory::PrototypeContainerConstIteratorType |
Const iterator for the prototype set.
Definition at line 59 of file WModuleFactory.h.
typedef std::set< boost::shared_ptr< WModule > >::iterator WModuleFactory::PrototypeContainerIteratorType |
Iterator for the prototype set.
Definition at line 64 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 54 of file WModuleFactory.h.
typedef WSharedAssociativeContainer< PrototypeContainerType > WModuleFactory::PrototypeSharedContainerType |
The alias for a shared container.
Definition at line 69 of file WModuleFactory.h.
|
virtual |
Destructor.
Definition at line 50 of file WModuleFactory.cpp.
|
protected |
Constructors are protected because this is a Singleton.
Definition at line 43 of file WModuleFactory.cpp.
Referenced by getModuleFactory().
|
protected |
Checks whether the specified module is a prototype or an instantiated module.
Use isPrototype if no ticket acquired yet.
module | the module to check |
ticket | ticket which already has read lock. |
Definition at line 98 of file WModuleFactory.cpp.
Referenced by create().
Create a new and initialized module using the specified prototype.
prototype | the prototype to clone. |
Definition at line 103 of file WModuleFactory.cpp.
References checkPrototype(), wlog::debug(), WSharedObject< T >::getReadTicket(), initializeModule(), 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.
module | the module to find the compatibles for. |
Definition at line 206 of file WModuleFactory.cpp.
References WSharedObject< T >::getReadTicket(), and m_prototypes.
|
static |
Returns instance of the module factory to use to create modules.
Definition at line 132 of file WModuleFactory.cpp.
References m_instance, and WModuleFactory().
Referenced by WApplyCombiner::apply(), WModuleContainer::applyModule(), 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.
instance | the instance to use. |
WPrototypeUnknown | if prototype can not be found. |
Definition at line 176 of file WModuleFactory.cpp.
References getPrototypeByName().
const boost::shared_ptr< WModule > WModuleFactory::getPrototypeByName | ( | std::string | name | ) |
Finds a prototype using the specified name.
name | the name. |
Definition at line 163 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.
Definition at line 201 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.
type | the type of module. |
Definition at line 181 of file WModuleFactory.cpp.
References WSharedObject< T >::getReadTicket(), and m_prototypes.
|
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.
module | the module to initialize. |
Definition at line 127 of file WModuleFactory.cpp.
|
static |
Checks whether the first instance can be casted to the second one.
module | the module to check. |
Definition at line 219 of file WModuleFactory.h.
|
static |
Checks whether the specified module is a prototype or an instantiated module.
module | the module to check |
Definition at line 91 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.
name | name of the prototype to search |
Definition at line 143 of file WModuleFactory.cpp.
References WSharedObject< T >::getReadTicket(), and m_prototypes.
Referenced by getPrototypeByName().
void WModuleFactory::load | ( | ) |
Loads the modules and creates prototypes.
Definition at line 55 of file WModuleFactory.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), WSharedObject< T >::getReadTicket(), WSharedObject< T >::getWriteTicket(), initializeModule(), WModuleLoader::load(), m_moduleLoader, and m_prototypes.
|
staticprivate |
Singleton instance of WModuleFactory.
Definition at line 215 of file WModuleFactory.h.
Referenced by getModuleFactory().
|
private |
Loader class managing dynamically loaded modules in OpenWalnut.
Definition at line 210 of file WModuleFactory.h.
Referenced by load().
|
protected |
The module prototypes available.
Definition at line 193 of file WModuleFactory.h.
Referenced by create(), getCompatiblePrototypes(), getPrototypes(), getPrototypesByType(), isPrototypeAvailable(), and load().