OpenWalnut  1.4.0
Public Types | Public Member Functions | Protected Attributes
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 >:

List of all members.

Public Types

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

Public Member Functions

 WFlag (WCondition *condition, const T &initial)
 Constructor.
 WFlag (boost::shared_ptr< WCondition > condition, const T &initial)
 Constructor.
 WFlag (const WFlag &from)
 Copy constructor.
virtual ~WFlag ()
 Destructor.
virtual const T & get (bool resetChangeState=false)
 Operator returns value of the flag.
virtual const T & get () const
 Operator returns value of the flag.
virtual const T & operator() () const
 Operator returns value of the flag.
virtual operator T () const
 Operator returns value of the flag.
virtual void wait () const
 Wait for the flag to change its value.
virtual bool set (const T &value, bool suppressNotification=false)
 Sets the new value for this flag.
virtual void operator() (const T &value)
 Sets the new value for this flag.
boost::shared_ptr< WConditiongetCondition ()
 Returns the condition that is used by this flag.
boost::shared_ptr< WConditiongetValueChangeCondition ()
 Returns the condition denoting a value change.
virtual bool accept (const T &newValue)
 Determines whether the specified value is acceptable.
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.

Protected Attributes

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

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.

Reimplemented in WPropertyVariable< T >.

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.

Reimplemented in WPropertyVariable< T >.

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(), WModule::reportRestoreComplete(), 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(), and WModule::waitRestored().


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: