OpenWalnut
1.5.0dev
|
This class allows for an easy strategy pattern-based switching between properties and strategy instances using a WPropSelection. More...
#include <WStrategyHelper.h>
Public Types | |
typedef std::shared_ptr< WStrategyHelper > | SPtr |
Convenience typedef for a std::shared_ptr< WStrategyHelper >. More... | |
typedef std::shared_ptr< const WStrategyHelper > | ConstSPtr |
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... | |
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.
StrategyType | the 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.
Definition at line 68 of file WStrategyHelper.h.
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.
|
private |
The type used to securely manage the strategies.
Definition at line 166 of file WStrategyHelper.h.
typedef std::shared_ptr< WStrategyHelper > WStrategyHelper< StrategyType >::SPtr |
Convenience typedef for a std::shared_ptr< WStrategyHelper >.
Definition at line 74 of file WStrategyHelper.h.
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.
name | name of this strategy selector |
description | a description for this selection |
icon | an icon for this selection. Can be NULL. |
selectorName | the name of the selection property used to switch. If empty, the name of the WStrategyHelper will be used. |
selectorDescription | the 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.
WStrategyHelper< StrategyType >::~WStrategyHelper |
Destructor.
Definition at line 212 of file WStrategyHelper.h.
void WStrategyHelper< StrategyType >::addStrategy | ( | typename StrategyType::SPtr | strategy | ) |
Adds the given strategy to the list of all strategies.
strategy | the strategy to add. |
Definition at line 260 of file WStrategyHelper.h.
Referenced by WMDataCreatorFibers::WMDataCreatorFibers(), WMDataCreatorPoints::WMDataCreatorPoints(), WMDataCreatorScalar::WMDataCreatorScalar(), and WMDataCreatorVector::WMDataCreatorVector().
std::string WStrategyHelper< StrategyType >::getDescription |
Gets the description for this strategy selector.
Definition at line 242 of file WStrategyHelper.h.
std::string WStrategyHelper< StrategyType >::getName |
Gets the name of this strategy selector.
Definition at line 236 of file WStrategyHelper.h.
WProperties::SPtr WStrategyHelper< StrategyType >::getProperties |
Get this strategy selectors properties.
This group contains the WPropSelection property to switch the strategy as well as groups for all registered strategies.
Definition at line 254 of file WStrategyHelper.h.
Referenced by WMDataCreatorFibers::moduleMain(), WMDataCreatorPoints::moduleMain(), WMDataCreatorScalar::moduleMain(), WMDataCreatorVector::moduleMain(), WMDatasetManipulator::moduleMain(), WMDiffTensorScalars::moduleMain(), WMFiberResampling::moduleMain(), WMDataCreatorFibers::properties(), WMDataCreatorPoints::properties(), WMDataCreatorScalar::properties(), WMDataCreatorVector::properties(), WMDatasetManipulator::properties(), WMDiffTensorScalars::properties(), WMFiberResampling::properties(), and WMReadMesh::properties().
const char ** WStrategyHelper< StrategyType >::getXPMIcon |
Get the icon for this strategy selectior in XPM format.
Definition at line 248 of file WStrategyHelper.h.
StrategyType::SPtr WStrategyHelper< StrategyType >::operator() |
Return the currently active strategy.
Definition at line 302 of file WStrategyHelper.h.
StrategyType::ConstSPtr WStrategyHelper< StrategyType >::operator() |
Return the currently active strategy.
Definition at line 293 of file WStrategyHelper.h.
|
private |
Update strategy's property hide status on updates in m_possibleSelectionProp.
Definition at line 218 of file WStrategyHelper.h.
|
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.
|
private |
the icon pointer
Definition at line 150 of file WStrategyHelper.h.
|
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().
|
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().
|
private |
stores the selection property and the strategy property groups
Definition at line 151 of file WStrategyHelper.h.
Referenced by WStrategyHelper< StrategyType >::WStrategyHelper().
|
private |
This is the list of all strategies.
Definition at line 171 of file WStrategyHelper.h.
|
private |
Connection between update and the update condition of m_possibleSelectionProp.
Definition at line 183 of file WStrategyHelper.h.
Referenced by WStrategyHelper< StrategyType >::WStrategyHelper().