25 #ifndef WSTRATEGYHELPER_H
26 #define WSTRATEGYHELPER_H
32 #include <boost/thread.hpp>
34 #include "WItemSelection.h"
35 #include "WItemSelector.h"
37 #include "WProperties.h"
38 #include "WPropertyHelper.h"
39 #include "WSharedSequenceContainer.h"
67 template<
class StrategyType >
74 typedef std::shared_ptr< WStrategyHelper >
SPtr;
79 typedef std::shared_ptr< const WStrategyHelper >
ConstSPtr;
90 WStrategyHelper( std::string name, std::string description,
const char** icon = NULL, std::string selectorName = std::string(),
91 std::string selectorDescription = std::string() );
191 template<
typename StrategyType >
193 std::string selectorName, std::string selectorDescription ):
195 m_properties( new
WProperties( name, description ) ),
199 selectorName = selectorName.empty() ? name : selectorName;
200 selectorDescription = selectorDescription.empty() ? name : selectorDescription;
211 template<
typename StrategyType >
217 template<
typename StrategyType >
224 size_t currentID = 0;
225 size_t selectedID = m_possibleSelectionProp->get();
229 ( *i )->getProperties()->setHidden( currentID != selectedID );
235 template<
typename StrategyType >
238 return m_properties->getName();
241 template<
typename StrategyType >
244 return m_properties->getDescription();
247 template<
typename StrategyType >
253 template<
typename StrategyType >
259 template<
typename StrategyType >
263 boost::lock_guard< boost::mutex > lock( m_addLock );
267 w->get().push_back( strategy );
268 size_t size = w->get().size();
271 m_possibleSelections->addItem( strategy->getName(), strategy->getDescription(), strategy->getIcon() );
272 m_properties->addProperty( strategy->getProperties() );
282 m_possibleSelectionProp->set( m_possibleSelections->getSelectorFirst() );
286 m_possibleSelectionProp->set( m_possibleSelectionProp->get().newSelector() );
292 template<
typename StrategyType >
297 return r->get()[ m_possibleSelectionProp->get() ];
301 template<
typename StrategyType >
306 return w->get()[ m_possibleSelectionProp->get() ];
A class containing a list of named items.
std::shared_ptr< WItemSelection > SPtr
Convenience typedef for a std::shared_ptr< WItemSelection >
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
std::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
std::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
Type for write tickets.
This class provides a common interface for thread-safe access to sequence containers (list,...
S::iterator Iterator
A typedef for the correct iterator to traverse this sequence container.
This class allows for an easy strategy pattern-based switching between properties and strategy instan...
WProperties::SPtr getProperties() const
Get this strategy selectors properties.
StrategyType::ConstSPtr operator()() const
Return the currently active strategy.
void addStrategy(typename StrategyType::SPtr strategy)
Adds the given strategy to the list of all strategies.
std::shared_ptr< const WStrategyHelper > ConstSPtr
Convenience typedef for a std::shared_ptr< const WStrategyHelper >.
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.
WPropSelection m_possibleSelectionProp
The property allowing the user to switch the strategy.
std::shared_ptr< WStrategyHelper > SPtr
Convenience typedef for a std::shared_ptr< WStrategyHelper >.
std::string getName() const
Gets the name of this strategy selector.
const char ** getXPMIcon() const
Get the icon for this strategy selectior in XPM format.
const char ** m_icon
the icon pointer
ContainerType m_strategies
This is the list of all strategies.
~WStrategyHelper()
Destructor.
boost::mutex m_addLock
This lock is needed to protect the addStrategy function.
WProperties::SPtr m_properties
stores the selection property and the strategy property groups
boost::signals2::connection m_updateConnection
Connection between update and the update condition of m_possibleSelectionProp.
WItemSelection::SPtr m_possibleSelections
A list of items that can be selected.
StrategyType::SPtr operator()()
Return the currently active strategy.
void update()
Update strategy's property hide status on updates in m_possibleSelectionProp.
std::string getDescription() const
Gets the description for this strategy selector.
WSharedSequenceContainer< std::vector< typename StrategyType::SPtr > > ContainerType
The type used to securely manage the strategies.
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.