28 #include <boost/shared_ptr.hpp>
30 #include "WCondition.h"
36 template <
typename T >
48 typedef boost::shared_ptr< WFlag< T > >
SPtr;
53 typedef boost::shared_ptr< const WFlag< T > >
ConstSPtr;
73 WFlag( boost::shared_ptr< WCondition > condition,
const T& initial );
98 virtual const T&
get(
bool resetChangeState = false );
105 virtual const T&
get()
const;
119 virtual operator T()
const;
124 virtual void wait()
const;
136 virtual bool set(
const T& value,
bool suppressNotification =
false );
168 virtual bool accept(
const T& newValue );
185 virtual bool changed(
bool reset =
false );
217 template <
typename T >
219 m_condition( boost::shared_ptr<
WCondition >( condition ) ),
226 template <
typename T >
228 m_condition( condition ),
235 template <
typename T >
239 m_flag( from.m_flag ),
240 m_changed( from.m_changed )
244 template <
typename T >
249 template <
typename T >
255 template <
typename T >
258 if( resetChangeState )
265 template <
typename T >
271 template <
typename T >
277 template <
typename T >
283 template <
typename T >
289 template <
typename T >
293 if( m_flag == value )
299 if( !accept( value ) )
308 if( !suppressNotification )
310 m_condition->notify();
312 m_valueChangeCondition->notify();
317 template <
typename T >
323 template <
typename T >
326 return m_valueChangeCondition;
329 template <
typename T >
336 template <
typename T >
339 return accept(
get() );
342 template <
typename T >
345 bool tmp = m_changed;
Class to have a simple notification/condition system for simple flags.
virtual const T & operator()() const
Operator returns value of the flag.
boost::shared_ptr< WCondition > getCondition()
Returns the condition that is used by this flag.
virtual bool accept(const T &newValue)
Determines whether the specified value is acceptable.
boost::shared_ptr< WFlag< T > > SPtr
Convenience typedef for a boost::shared_ptr.
virtual bool isValid()
Tests whether a flag is currently valid.
virtual bool changed(bool reset=false)
True whenever the value inside this flag has changed since the last reset.
virtual const T & get() const
Operator returns value of the flag.
bool m_changed
Denotes whether the value has changed since the last reset.
virtual ~WFlag()
Destructor.
virtual void wait() const
Wait for the flag to change its value.
Class to encapsulate boost::condition_variable_any.
WFlag(WCondition *condition, const T &initial)
Constructor.
boost::shared_ptr< WCondition > m_valueChangeCondition
This condition is fired whenever the value changes.
boost::shared_ptr< WCondition > m_condition
The condition to be used for waiting/notifying.
virtual bool set(const T &value, bool suppressNotification=false)
Sets the new value for this flag.
T ValueType
The type for later access.
boost::shared_ptr< const WFlag< T > > ConstSPtr
Convenience typedef for a boost::shared_ptr.
boost::shared_ptr< WCondition > getValueChangeCondition()
Returns the condition denoting a value change.