OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
WStrategyHelper< StrategyType > Class Template Reference

This class allows for an easy strategy pattern-based switching between properties and strategy instances using a WPropSelection. More...

#include <WStrategyHelper.h>

+ Inheritance diagram for WStrategyHelper< StrategyType >:
+ Collaboration diagram for WStrategyHelper< StrategyType >:

Public Types

typedef std::shared_ptr< WStrategyHelperSPtr
 Convenience typedef for a std::shared_ptr< WStrategyHelper >. More...
 
typedef std::shared_ptr< const WStrategyHelperConstSPtr
 Convenience typedef for a std::shared_ptr< const WStrategyHelper >. More...
 

Public Member Functions

 WStrategyHelper (std::string name, std::string description, const char **icon=NULL, std::string selectorName=std::string(), std::string selectorDescription=std::string())
 Constructs an empty strategy selector. More...
 
 ~WStrategyHelper ()
 Destructor. More...
 
std::string getName () const
 Gets the name of this strategy selector. More...
 
std::string getDescription () const
 Gets the description for this strategy selector. More...
 
const char ** getXPMIcon () const
 Get the icon for this strategy selectior in XPM format. More...
 
WProperties::SPtr getProperties () const
 Get this strategy selectors properties. More...
 
void addStrategy (typename StrategyType::SPtr strategy)
 Adds the given strategy to the list of all strategies. More...
 
StrategyType::ConstSPtr operator() () const
 Return the currently active strategy. More...
 
StrategyType::SPtr operator() ()
 Return the currently active strategy. More...
 

Private Types

typedef WSharedSequenceContainer< std::vector< typename StrategyType::SPtr > > ContainerType
 The type used to securely manage the strategies. More...
 

Private Member Functions

void update ()
 Update strategy's property hide status on updates in m_possibleSelectionProp. More...
 

Private Attributes

const char ** m_icon
 the icon pointer More...
 
WProperties::SPtr m_properties
 stores the selection property and the strategy property groups More...
 
WItemSelection::SPtr m_possibleSelections
 A list of items that can be selected. More...
 
WPropSelection m_possibleSelectionProp
 The property allowing the user to switch the strategy. More...
 
ContainerType m_strategies
 This is the list of all strategies. More...
 
boost::mutex m_addLock
 This lock is needed to protect the addStrategy function. More...
 
boost::signals2::connection m_updateConnection
 Connection between update and the update condition of m_possibleSelectionProp. More...
 

Detailed Description

template<class StrategyType>
class WStrategyHelper< StrategyType >

This class allows for an easy strategy pattern-based switching between properties and strategy instances using a WPropSelection.

The idea of this class is that you specify the type of some class you want to serve as the base class of several strategies. Each of these strategies has a name, description and several properties. An instance of this class automatically provides a WPropSelection containing an item for each strategy instance you add. A switch in this property causes to automatically hide all properties not belonging to this strategy. This class will ease the writing of modules that provide multiple "ways of doing it". If you utilize this class in your module, you should add ALL your strategies before you add this WStrategyHelper's properties to your module's properties.

Template Parameters
StrategyTypethe base class type of your strategies.

The type in StrategyType needs to comply to the following rules:

The cool thing is, this class complies to its own requirements on strategy base classes. This allows you to nest strategy selections.

Note
the class is thread-safe, although it might not be a nice idea to modify the strategy list while the user tries to select some. He will probably be very annoyed.
you should use WObjectNDIP which complies to this rules. This furthermore eases the task of writing strategies.

Definition at line 68 of file WStrategyHelper.h.

Member Typedef Documentation

◆ ConstSPtr

template<class StrategyType >
typedef std::shared_ptr< const WStrategyHelper > WStrategyHelper< StrategyType >::ConstSPtr

Convenience typedef for a std::shared_ptr< const WStrategyHelper >.

Definition at line 79 of file WStrategyHelper.h.

◆ ContainerType

template<class StrategyType >
typedef WSharedSequenceContainer< std::vector< typename StrategyType::SPtr > > WStrategyHelper< StrategyType >::ContainerType
private

The type used to securely manage the strategies.

Definition at line 166 of file WStrategyHelper.h.

◆ SPtr

template<class StrategyType >
typedef std::shared_ptr< WStrategyHelper > WStrategyHelper< StrategyType >::SPtr

Convenience typedef for a std::shared_ptr< WStrategyHelper >.

Definition at line 74 of file WStrategyHelper.h.

Constructor & Destructor Documentation

◆ WStrategyHelper()

template<typename StrategyType >
WStrategyHelper< StrategyType >::WStrategyHelper ( std::string  name,
std::string  description,
const char **  icon = NULL,
std::string  selectorName = std::string(),
std::string  selectorDescription = std::string() 
)

Constructs an empty strategy selector.

Use one of the addStrategy methods to register strategies.

Parameters
namename of this strategy selector
descriptiona description for this selection
iconan icon for this selection. Can be NULL.
selectorNamethe name of the selection property used to switch. If empty, the name of the WStrategyHelper will be used.
selectorDescriptionthe description of the selection property used to switch. If empty, description of the WStrategyHelper is used.

Definition at line 192 of file WStrategyHelper.h.

References WPropertyHelper::PC_SELECTONLYONE::addTo(), WPropertyHelper::PC_NOTEMPTY::addTo(), WStrategyHelper< StrategyType >::m_possibleSelectionProp, WStrategyHelper< StrategyType >::m_possibleSelections, WStrategyHelper< StrategyType >::m_properties, and WStrategyHelper< StrategyType >::m_updateConnection.

+ Here is the call graph for this function:

◆ ~WStrategyHelper()

template<typename StrategyType >
WStrategyHelper< StrategyType >::~WStrategyHelper

Destructor.

Definition at line 212 of file WStrategyHelper.h.

Member Function Documentation

◆ addStrategy()

template<typename StrategyType >
void WStrategyHelper< StrategyType >::addStrategy ( typename StrategyType::SPtr  strategy)

Adds the given strategy to the list of all strategies.

Parameters
strategythe strategy to add.

Definition at line 260 of file WStrategyHelper.h.

Referenced by WMDataCreatorFibers::WMDataCreatorFibers(), WMDataCreatorPoints::WMDataCreatorPoints(), WMDataCreatorScalar::WMDataCreatorScalar(), and WMDataCreatorVector::WMDataCreatorVector().

+ Here is the caller graph for this function:

◆ getDescription()

template<typename StrategyType >
std::string WStrategyHelper< StrategyType >::getDescription

Gets the description for this strategy selector.

Returns
the description

Definition at line 242 of file WStrategyHelper.h.

◆ getName()

template<typename StrategyType >
std::string WStrategyHelper< StrategyType >::getName

Gets the name of this strategy selector.

Returns
the name.

Definition at line 236 of file WStrategyHelper.h.

◆ getProperties()

template<typename StrategyType >
WProperties::SPtr WStrategyHelper< StrategyType >::getProperties

◆ getXPMIcon()

template<typename StrategyType >
const char ** WStrategyHelper< StrategyType >::getXPMIcon

Get the icon for this strategy selectior in XPM format.

Returns
The icon.

Definition at line 248 of file WStrategyHelper.h.

◆ operator()() [1/2]

template<typename StrategyType >
StrategyType::SPtr WStrategyHelper< StrategyType >::operator()

Return the currently active strategy.

Returns
the active strategy

Definition at line 302 of file WStrategyHelper.h.

◆ operator()() [2/2]

template<typename StrategyType >
StrategyType::ConstSPtr WStrategyHelper< StrategyType >::operator()

Return the currently active strategy.

Returns
the active strategy

Definition at line 293 of file WStrategyHelper.h.

◆ update()

template<typename StrategyType >
void WStrategyHelper< StrategyType >::update
private

Update strategy's property hide status on updates in m_possibleSelectionProp.

Definition at line 218 of file WStrategyHelper.h.

Member Data Documentation

◆ m_addLock

template<class StrategyType >
boost::mutex WStrategyHelper< StrategyType >::m_addLock
private

This lock is needed to protect the addStrategy function.

Although the m_strategies member is protected due to the use of a WSharedObject, an update in the selection (m_possibleSelectionProp) causes an update of the hide status of all property groups in m_strategies. This would cause a deadlock if m_strategies is still locked. This lock is only locked if addStrategy is called.

Definition at line 178 of file WStrategyHelper.h.

◆ m_icon

template<class StrategyType >
const char** WStrategyHelper< StrategyType >::m_icon
private

the icon pointer

Definition at line 150 of file WStrategyHelper.h.

◆ m_possibleSelectionProp

template<class StrategyType >
WPropSelection WStrategyHelper< StrategyType >::m_possibleSelectionProp
private

The property allowing the user to switch the strategy.

Will be extended for each added strategy.

Definition at line 161 of file WStrategyHelper.h.

Referenced by WStrategyHelper< StrategyType >::WStrategyHelper().

◆ m_possibleSelections

template<class StrategyType >
WItemSelection::SPtr WStrategyHelper< StrategyType >::m_possibleSelections
private

A list of items that can be selected.

Will be extended for each added strategy.

Definition at line 156 of file WStrategyHelper.h.

Referenced by WStrategyHelper< StrategyType >::WStrategyHelper().

◆ m_properties

template<class StrategyType >
WProperties::SPtr WStrategyHelper< StrategyType >::m_properties
private

stores the selection property and the strategy property groups

Definition at line 151 of file WStrategyHelper.h.

Referenced by WStrategyHelper< StrategyType >::WStrategyHelper().

◆ m_strategies

template<class StrategyType >
ContainerType WStrategyHelper< StrategyType >::m_strategies
private

This is the list of all strategies.

Definition at line 171 of file WStrategyHelper.h.

◆ m_updateConnection

template<class StrategyType >
boost::signals2::connection WStrategyHelper< StrategyType >::m_updateConnection
private

Connection between update and the update condition of m_possibleSelectionProp.

Definition at line 183 of file WStrategyHelper.h.

Referenced by WStrategyHelper< StrategyType >::WStrategyHelper().


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