25 #ifndef WSTRATEGYHELPER_H
26 #define WSTRATEGYHELPER_H
32 #include <boost/shared_ptr.hpp>
35 #include <boost/thread.hpp>
39 #include "WItemSelection.h"
40 #include "WItemSelector.h"
41 #include "WSharedSequenceContainer.h"
42 #include "WProperties.h"
43 #include "WPropertyHelper.h"
71 template<
class StrategyType >
78 typedef boost::shared_ptr< WStrategyHelper >
SPtr;
83 typedef boost::shared_ptr< const WStrategyHelper >
ConstSPtr;
94 WStrategyHelper( std::string name, std::string description,
const char** icon = NULL, std::string selectorName = std::string(),
95 std::string selectorDescription = std::string() );
136 void addStrategy(
typename StrategyType::SPtr strategy );
143 typename StrategyType::ConstSPtr
operator()()
const;
195 template<
typename StrategyType >
197 std::string selectorName, std::string selectorDescription ):
199 m_properties( new
WProperties( name, description ) ),
203 selectorName = selectorName.empty() ? name : selectorName;
204 selectorDescription = selectorDescription.empty() ? name : selectorDescription;
215 template<
typename StrategyType >
221 template<
typename StrategyType >
228 size_t currentID = 0;
229 size_t selectedID = m_possibleSelectionProp->get();
233 ( *i )->getProperties()->setHidden( currentID != selectedID );
239 template<
typename StrategyType >
242 return m_properties->getName();
245 template<
typename StrategyType >
248 return m_properties->getDescription();
251 template<
typename StrategyType >
257 template<
typename StrategyType >
263 template<
typename StrategyType >
267 boost::lock_guard< boost::mutex > lock( m_addLock );
271 w->get().push_back( strategy );
272 size_t size = w->get().size();
275 m_possibleSelections->addItem( strategy->getName(), strategy->getDescription(), strategy->getIcon() );
276 m_properties->addProperty( strategy->getProperties() );
286 m_possibleSelectionProp->set( m_possibleSelections->getSelectorFirst() );
290 m_possibleSelectionProp->set( m_possibleSelectionProp->get().newSelector() );
296 template<
typename StrategyType >
301 return r->get()[ m_possibleSelectionProp->get() ];
305 template<
typename StrategyType >
310 return w->get()[ m_possibleSelectionProp->get() ];
314 #endif // WSTRATEGYHELPER_H
boost::shared_ptr< WSharedObjectTicketWrite< std::vector< typename StrategyType::SPtr > > > WriteTicket
Type for write tickets.
boost::shared_ptr< WItemSelection > SPtr
Convenience typedef for a boost::shared_ptr< WItemSelection >
boost::mutex m_addLock
This lock is needed to protect the addStrategy function.
WProperties::SPtr getProperties() const
Get this strategy selectors properties.
boost::signals2::connection m_updateConnection
Connection between update and the update condition of m_possibleSelectionProp.
const char ** m_icon
the icon pointer
StrategyType::ConstSPtr operator()() const
Return the currently active strategy.
This class provides a common interface for thread-safe access to sequence containers (list...
std::string getName() const
Gets the name of this strategy selector.
WItemSelection::SPtr m_possibleSelections
A list of items that can be selected.
~WStrategyHelper()
Destructor.
void update()
Update strategy's property hide status on updates in m_possibleSelectionProp.
std::string getDescription() const
Gets the description for this strategy selector.
const char ** getXPMIcon() const
Get the icon for this strategy selectior in XPM format.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
A class containing a list of named items.
WPropSelection m_possibleSelectionProp
The property allowing the user to switch the strategy.
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
This class allows for an easy strategy pattern-based switching between properties and strategy instan...
boost::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type
void addStrategy(typename StrategyType::SPtr strategy)
Adds the given strategy to the list of all strategies.
boost::shared_ptr< const WStrategyHelper > ConstSPtr
Convenience typedef for a boost::shared_ptr< const WStrategyHelper >.
ContainerType m_strategies
This is the list of all strategies.
boost::shared_ptr< WStrategyHelper > SPtr
Convenience typedef for a boost::shared_ptr< 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.
WSharedSequenceContainer< std::vector< typename StrategyType::SPtr > > ContainerType
The type used to securely manage the strategies.
std::vector< typename StrategyType::SPtr >::iterator Iterator
A typedef for the correct iterator to traverse this sequence container.
boost::shared_ptr< WSharedObjectTicketRead< std::vector< typename StrategyType::SPtr > > > ReadTicket
Type for read tickets.
WProperties::SPtr m_properties
stores the selection property and the strategy property groups
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.