OpenWalnut  1.3.1
Public Types | Public Member Functions | Protected Attributes | List of all members
WFlag< T > Class Template Reference

Class to have a simple notification/condition system for simple flags. More...

#include <WFlag.h>

+ Inheritance diagram for WFlag< T >:

Public Types

typedef T ValueType
 The type for later access. More...
 
typedef boost::shared_ptr
< WFlag< T > > 
SPtr
 Convenience typedef for a boost::shared_ptr. More...
 
typedef boost::shared_ptr
< const WFlag< T > > 
ConstSPtr
 Convenience typedef for a boost::shared_ptr. More...
 

Public Member Functions

 WFlag (WCondition *condition, const T &initial)
 Constructor. More...
 
 WFlag (boost::shared_ptr< WCondition > condition, const T &initial)
 Constructor. More...
 
 WFlag (const WFlag &from)
 Copy constructor. More...
 
virtual ~WFlag ()
 Destructor. More...
 
virtual const Tget (bool resetChangeState=false)
 Operator returns value of the flag. More...
 
virtual const Tget () const
 Operator returns value of the flag. More...
 
virtual const Toperator() () const
 Operator returns value of the flag. More...
 
virtual operator T () const
 Operator returns value of the flag. More...
 
virtual void wait () const
 Wait for the flag to change its value. More...
 
virtual bool set (const T &value, bool suppressNotification=false)
 Sets the new value for this flag. More...
 
virtual void operator() (const T &value)
 Sets the new value for this flag. More...
 
boost::shared_ptr< WConditiongetCondition ()
 Returns the condition that is used by this flag. More...
 
boost::shared_ptr< WConditiongetValueChangeCondition ()
 Returns the condition denoting a value change. More...
 
virtual bool accept (const T &newValue)
 Determines whether the specified value is acceptable. More...
 
virtual bool isValid ()
 Tests whether a flag is currently valid. More...
 
virtual bool changed (bool reset=false)
 True whenever the value inside this flag has changed since the last reset. More...
 

Protected Attributes

boost::shared_ptr< WConditionm_condition
 The condition to be used for waiting/notifying. More...
 
boost::shared_ptr< WConditionm_valueChangeCondition
 This condition is fired whenever the value changes. More...
 
T m_flag
 The flag value. More...
 
bool m_changed
 Denotes whether the value has changed since the last reset. More...
 

Detailed Description

template<typename T>
class WFlag< T >

Class to have a simple notification/condition system for simple flags.

This is somewhat similar to the observer design pattern. The type of the flag is specified by the template parameter. Per default, it is of type bool.

Definition at line 37 of file WFlag.h.

Member Typedef Documentation

template<typename T>
typedef boost::shared_ptr< const WFlag< T > > WFlag< T >::ConstSPtr

Convenience typedef for a boost::shared_ptr.

Const.

Definition at line 53 of file WFlag.h.

template<typename T>
typedef boost::shared_ptr< WFlag< T > > WFlag< T >::SPtr

Convenience typedef for a boost::shared_ptr.

Definition at line 48 of file WFlag.h.

template<typename T>
typedef T WFlag< T >::ValueType

The type for later access.

Definition at line 43 of file WFlag.h.

Constructor & Destructor Documentation

template<typename T>
WFlag< T >::WFlag ( WCondition condition,
const T initial 
)

Constructor.

Uses a given condition to realize the wait/notify functionality. By using this constructor, the specified condition gets deleted whenever this WFlag is deleted.

Parameters
conditionthe condition to use.
Notes:
condition can also be a WConditionOneShot.
Parameters
initialthe initial value of this flag.

Definition at line 218 of file WFlag.h.

template<typename T>
WFlag< T >::WFlag ( boost::shared_ptr< WCondition condition,
const T initial 
)

Constructor.

Uses a given condition to realize the wait/notify functionality. By using this constructor, the specified condition gets NOT explicitely deleted when this WFlag gets deleted.

Parameters
conditionthe condition to use.
Notes:
condition can also be a WConditionOneShot.
Parameters
initialthe initial value of this flag.

Definition at line 227 of file WFlag.h.

template<typename T>
WFlag< T >::WFlag ( const WFlag< T > &  from)
explicit

Copy constructor.

Creates a deep copy of this property. As boost::signals2 and condition variables are non-copyable, new instances get created. The subscriptions to a signal are LOST as well as all listeners to a condition. The conditions you can grab using getValueChangeConditon and getCondition are not the same as in the original! This is because the class corresponds to the observer/observable pattern. You won't expect a clone to fire a condition if a original flag is changed (which after cloning is completely decoupled from the clone).

Parameters
fromthe instance to copy.

Definition at line 236 of file WFlag.h.

template<typename T >
WFlag< T >::~WFlag ( )
virtual

Destructor.

It deletes the instance of WCondition specified on construction.

Definition at line 245 of file WFlag.h.

Member Function Documentation

template<typename T>
bool WFlag< T >::accept ( const T newValue)
virtual

Determines whether the specified value is acceptable.

In WFlags, this always returns true. To modify the behaviour, implement this function in an appropriate way.

Parameters
newValuethe new value.
Returns
true if it is a valid/acceptable value.

Reimplemented in WPropertyVariable< T >.

Definition at line 330 of file WFlag.h.

Referenced by WPropertyVariable< T >::accept().

template<typename T >
bool WFlag< T >::changed ( bool  reset = false)
virtual

True whenever the value inside this flag has changed since the last reset.

It stays true until get( true ) is called or the reset value is true.

Parameters
resetif true, the change flag gets reset.
Returns
true when the value has changed and not yet been reseted.

Definition at line 343 of file WFlag.h.

Referenced by WFlagTest::testChangeFlagAndReset(), and WFlagTest::testCopyConstruction().

template<typename T >
const T & WFlag< T >::get ( bool  resetChangeState = false)
virtual
template<typename T >
const T & WFlag< T >::get ( ) const
virtual

Operator returns value of the flag.

Returns
the value.

Definition at line 266 of file WFlag.h.

template<typename T >
boost::shared_ptr< WCondition > WFlag< T >::getCondition ( )

Returns the condition that is used by this flag.

Returns
the condition

Definition at line 318 of file WFlag.h.

Referenced by WFlagTest::testCopyConstruction(), and WModule::WModule().

template<typename T >
boost::shared_ptr< WCondition > WFlag< T >::getValueChangeCondition ( )

Returns the condition denoting a value change.

In contrast to getCondition, this condition fires regardless of notification is suppressed during set() or not.

Returns
the condition denoting a value change.

Definition at line 324 of file WFlag.h.

Referenced by WFlagTest::testCopyConstruction(), and WPropertyVariable< T >::WPropertyVariable().

template<typename T >
bool WFlag< T >::isValid ( )
virtual

Tests whether a flag is currently valid.

It is equal to accept( get() );

Returns
true if current value is valid.

Definition at line 337 of file WFlag.h.

template<typename T >
WFlag< T >::operator T ( ) const
virtual

Operator returns value of the flag.

It does not reset the change flag.

Returns
the value.

Definition at line 272 of file WFlag.h.

template<typename T >
const T & WFlag< T >::operator() ( ) const
virtual

Operator returns value of the flag.

Returns
the value.

Definition at line 250 of file WFlag.h.

template<typename T>
void WFlag< T >::operator() ( const T value)
virtual

Sets the new value for this flag.

Also notifies waiting threads.

Parameters
valuethe new value

Definition at line 284 of file WFlag.h.

template<typename T>
bool WFlag< T >::set ( const T value,
bool  suppressNotification = false 
)
virtual

Sets the new value for this flag.

Also notifies waiting threads. After setting a value, changed() will be true.

Parameters
valuethe new value
suppressNotificationtrue to avoid a firing condition. This is useful for resetting values.
Returns
true if the value has been set successfully.
Notes:
set( get() ) == true

Reimplemented in WPropertyVariable< T >.

Definition at line 290 of file WFlag.h.

Referenced by WPropertyVariable< T >::ensureValidity(), WPropertyVariable< T >::set(), WFlagTest::testChangeCondition(), and WFlagTest::testCopyConstruction().

template<typename T >
void WFlag< T >::wait ( ) const
virtual

Wait for the flag to change its value.

For WConditionOneShot is also recognizes if the flag has changed before.

Definition at line 278 of file WFlag.h.

Referenced by WThreadedRunner::waitForStop().

Member Data Documentation

template<typename T>
bool WFlag< T >::m_changed
protected

Denotes whether the value has changed since the last reset.

Definition at line 207 of file WFlag.h.

template<typename T>
boost::shared_ptr< WCondition > WFlag< T >::m_condition
protected

The condition to be used for waiting/notifying.

Please note, that it gets deleted during destruction.

Definition at line 191 of file WFlag.h.

template<typename T>
T WFlag< T >::m_flag
protected

The flag value.

Definition at line 202 of file WFlag.h.

template<typename T>
boost::shared_ptr< WCondition > WFlag< T >::m_valueChangeCondition
protected

This condition is fired whenever the value changes.

In contrast to m_condition, this also fires if set() is called with suppressNotification=true.

Definition at line 197 of file WFlag.h.


The documentation for this class was generated from the following file: