Commit 09e03166 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[ADD] - added some convenience methods to input and output connectors for lazy...

[ADD] - added some convenience methods to input and output connectors for lazy programmers. Have a look at the template module for details.
parent 5f907f53
......@@ -35,6 +35,8 @@
#include "WModuleInputConnector.h"
#include "WModuleOutputConnector.h"
#include "WModuleInputData.h"
#include "WModuleOutputData.h"
#include "WModuleConnectorSignals.h"
#include "WModuleContainer.h"
#include "WModuleFactory.h"
......
......@@ -60,6 +60,8 @@ class WModuleContainer;
class WModuleFactory;
class WModuleInputConnector;
class WModuleOutputConnector;
template < typename T > class WModuleInputData;
template < typename T > class WModuleOutputData;
/**
* Class representing a single module of OpenWalnut.
......@@ -70,6 +72,8 @@ class OWKERNEL_EXPORT WModule: public WThreadedRunner,
public boost::enable_shared_from_this< WModule >
{
friend class WModuleConnector; // requires access to notify members
template< typename T > friend class WModuleInputData; // requires access for convenience functions to automatically add a created connector
template< typename T > friend class WModuleOutputData; // requires access for convenience functions to automatically add a created connector
friend class WModuleFactory; // for proper creation of module instaces, the factory needs access to protected functions.
// (especially initialize)
friend class WModuleContainer; // for proper management of m_container WModuleContainer needs access.
......
......@@ -49,6 +49,48 @@ template < typename T >
class WModuleInputData: public WModuleInputConnector
{
public:
/**
* Pointer to this. For convenience.
*/
typedef boost::shared_ptr< WModuleInputData< T > > PtrType;
/**
* Reference to this type.
*/
typedef WModuleInputData< T >& RefType;
/**
* Type of the connector.
*/
typedef WModuleInputData< T > Type;
/**
* Typedef to the contained transferable.
*/
typedef T TransferType;
/**
* Convenience method to create a new instance of this in data connector with proper type.
*
* \param module the module owning this instance
* \param name the name of this connector.
* \param description the description of this connector.
*
* \return the pointer to the created connector.
*/
static PtrType create( boost::shared_ptr< WModule > module, std::string name = "", std::string description = "" );
/**
* Convenience method to create a new instance of this in data connector with proper type and add it to the list of connectors of the
* specified module.
*
* \param module the module owning this instance
* \param name the name of this connector.
* \param description the description of this connector.
*
* \return the pointer to the created connector.
*/
static PtrType createAndAdd( boost::shared_ptr< WModule > module, std::string name = "", std::string description = "" );
/**
* Constructor.
......@@ -57,7 +99,7 @@ public:
* \param name The name of this connector.
* \param description Short description of this connector.
*/
WModuleInputData( boost::shared_ptr< WModule > module, std::string name="", std::string description="" )
WModuleInputData( boost::shared_ptr< WModule > module, std::string name = "", std::string description = "" )
:WModuleInputConnector( module, name, description )
{
};
......@@ -130,5 +172,23 @@ protected:
private:
};
template < typename T >
typename WModuleInputData< T >::PtrType WModuleInputData< T >::create( boost::shared_ptr< WModule > module, std::string name,
std::string description )
{
typedef typename WModuleInputData< T >::PtrType PTR;
typedef typename WModuleInputData< T >::Type TYPE;
return PTR( new TYPE( module, name, description ) );
}
template < typename T >
typename WModuleInputData< T >::PtrType WModuleInputData< T >::createAndAdd( boost::shared_ptr< WModule > module, std::string name,
std::string description )
{
typename WModuleInputData< T >::PtrType c = create( module, name, description );
module->addConnector( c );
return c;
}
#endif // WMODULEINPUTDATA_H
......@@ -47,6 +47,48 @@ template < typename T >
class WModuleOutputData: public WModuleOutputConnector
{
public:
/**
* Pointer to this. For convenience.
*/
typedef boost::shared_ptr< WModuleOutputData< T > > PtrType;
/**
* Reference to this type.
*/
typedef WModuleOutputData< T >& RefType;
/**
* Type of the connector.
*/
typedef WModuleOutputData< T > Type;
/**
* Typedef to the contained transferable.
*/
typedef T TransferType;
/**
* Convenience method to create a new instance of this out data connector with proper type.
*
* \param module the module owning this instance
* \param name the name of this connector.
* \param description the description of this connector.
*
* \return the pointer to the created connector.
*/
static PtrType create( boost::shared_ptr< WModule > module, std::string name = "", std::string description = "" );
/**
* Convenience method to create a new instance of this out data connector with proper type and add it to the list of connectors of the
* specified module.
*
* \param module the module owning this instance
* \param name the name of this connector.
* \param description the description of this connector.
*
* \return the pointer to the created connector.
*/
static PtrType createAndAdd( boost::shared_ptr< WModule > module, std::string name = "", std::string description = "" );
/**
* Constructor.
......@@ -55,7 +97,7 @@ public:
* \param name The name of this connector.
* \param description Short description of this connector.
*/
WModuleOutputData( boost::shared_ptr< WModule > module, std::string name="", std::string description="" )
WModuleOutputData( boost::shared_ptr< WModule > module, std::string name = "", std::string description = "" )
:WModuleOutputConnector( module, name, description )
{
m_data = boost::shared_ptr< T >();
......@@ -144,5 +186,23 @@ private:
boost::shared_ptr< T > m_data;
};
template < typename T >
typename WModuleOutputData< T >::PtrType WModuleOutputData< T >::create( boost::shared_ptr< WModule > module, std::string name,
std::string description )
{
typedef typename WModuleOutputData< T >::PtrType PTR;
typedef typename WModuleOutputData< T >::Type TYPE;
return PTR( new TYPE( module, name, description ) );
}
template < typename T >
typename WModuleOutputData< T >::PtrType WModuleOutputData< T >::createAndAdd( boost::shared_ptr< WModule > module, std::string name,
std::string description )
{
typename WModuleOutputData< T >::PtrType c = create( module, name, description );
module->addConnector( c );
return c;
}
#endif // WMODULEOUTPUTDATA_H
......@@ -170,6 +170,10 @@ void WMTemplate::connectors()
// As properties, every connector needs to be added to the list of connectors.
addConnector( m_input );
// For all the lazy programmers, the creation and addition of the connector can be simplified to one type-less-compatible step:
// m_input = WModuleInputData< WDataSetSingle >::createAndAdd( shared_from_this(), "in", "The dataset to display" );
// This is fully equivalent to the above calls and works for output connectors too.
// Now, lets add an output connector. We want to provide data calculated here to other modules. The output connector is initialized the same
// way as input connectors. You need the type, the module-wide unique name and the description. The type you specify here also determines
// which input connectors can be connected to this output connector: only connectors with a type equal or lower in class hierarchy.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment