29 #include <boost/shared_ptr.hpp>
32 #include "WCondition.h"
38 template <
typename T >
50 typedef boost::shared_ptr< WFlag< T > >
SPtr;
55 typedef boost::shared_ptr< const WFlag< T > >
ConstSPtr;
75 WFlag( boost::shared_ptr< WCondition > condition,
const T& initial );
100 virtual const T&
get(
bool resetChangeState = false );
107 virtual const T&
get()
const;
121 virtual operator T()
const;
126 virtual void wait()
const;
138 virtual bool set(
const T& value,
bool suppressNotification =
false );
170 virtual bool accept(
const T& newValue );
187 virtual bool changed(
bool reset =
false );
219 template <
typename T >
221 m_condition( boost::shared_ptr<
WCondition >( condition ) ),
228 template <
typename T >
230 m_condition( condition ),
237 template <
typename T >
241 m_flag( from.m_flag ),
242 m_changed( from.m_changed )
246 template <
typename T >
251 template <
typename T >
257 template <
typename T >
260 if( resetChangeState )
267 template <
typename T >
273 template <
typename T >
279 template <
typename T >
285 template <
typename T >
291 template <
typename T >
295 if( m_flag == value )
301 if( !accept( value ) )
310 if( !suppressNotification )
312 m_condition->notify();
314 m_valueChangeCondition->notify();
319 template <
typename T >
325 template <
typename T >
328 return m_valueChangeCondition;
331 template <
typename T >
338 template <
typename T >
341 return accept(
get() );
344 template <
typename T >
347 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.