OpenWalnut  1.5.0dev
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 >:
+ Collaboration diagram for WFlag< T >:

Public Types

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

Public Member Functions

 WFlag (WCondition *condition, const T &initial)
 Constructor. More...
 
 WFlag (std::shared_ptr< WCondition > condition, const T &initial)
 Constructor. More...
 
 WFlag (const WFlag &from)
 Copy constructor. More...
 
virtual ~WFlag ()
 Destructor. More...
 
virtual const T & get (bool resetChangeState=false)
 Operator returns value of the flag. More...
 
virtual const T & get () const
 Operator returns value of the flag. More...
 
virtual const T & operator() () 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...
 
std::shared_ptr< WConditiongetCondition ()
 Returns the condition that is used by this flag. More...
 
std::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

std::shared_ptr< WConditionm_condition
 The condition to be used for waiting/notifying. More...
 
std::shared_ptr< WConditionm_valueChangeCondition
 This condition is fired whenever the value changes. More...
 
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 38 of file WFlag.h.

Member Typedef Documentation

◆ ConstSPtr

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

Convenience typedef for a std::shared_ptr.

Const.

Definition at line 54 of file WFlag.h.

◆ SPtr

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

Convenience typedef for a std::shared_ptr.

Definition at line 49 of file WFlag.h.

◆ ValueType

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

The type for later access.

Definition at line 44 of file WFlag.h.

Constructor & Destructor Documentation

◆ WFlag() [1/3]

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.
Note
condition can also be a WConditionOneShot.
Parameters
initialthe initial value of this flag.

Definition at line 219 of file WFlag.h.

◆ WFlag() [2/3]

template<typename T >
WFlag< T >::WFlag ( std::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.
Note
condition can also be a WConditionOneShot.
Parameters
initialthe initial value of this flag.

Definition at line 228 of file WFlag.h.

◆ WFlag() [3/3]

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 237 of file WFlag.h.

◆ ~WFlag()

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

Destructor.

It deletes the instance of WCondition specified on construction.

Definition at line 246 of file WFlag.h.

Member Function Documentation

◆ accept()

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 331 of file WFlag.h.

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

+ Here is the caller graph for this function:

◆ changed()

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 344 of file WFlag.h.

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

+ Here is the caller graph for this function:

◆ get() [1/2]

template<typename T >
const T & WFlag< T >::get
virtual

Operator returns value of the flag.

Returns
the value.

Definition at line 267 of file WFlag.h.

◆ get() [2/2]

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

◆ getCondition()

template<typename T >
std::shared_ptr< WCondition > WFlag< T >::getCondition

Returns the condition that is used by this flag.

Returns
the condition

Definition at line 319 of file WFlag.h.

Referenced by WMEEGView::moduleMain(), WMEEGView::openCustomWidget(), WFlagTest::testCopyConstruction(), and WModule::WModule().

+ Here is the caller graph for this function:

◆ getValueChangeCondition()

template<typename T >
std::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 325 of file WFlag.h.

Referenced by WMHistogramView::moduleMain(), WMMultiHistogramView::moduleMain(), WMTemplateUI::moduleMain(), WFlagTest::testCopyConstruction(), and WPropertyVariable< T >::WPropertyVariable().

+ Here is the caller graph for this function:

◆ isValid()

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 338 of file WFlag.h.

◆ operator T()

template<typename T >
WFlag< T >::operator T
virtual

Operator returns value of the flag.

It does not reset the change flag.

Returns
the value.

Definition at line 273 of file WFlag.h.

◆ operator()() [1/2]

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

Operator returns value of the flag.

Returns
the value.

Definition at line 251 of file WFlag.h.

◆ operator()() [2/2]

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 285 of file WFlag.h.

◆ set()

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.
Note
set( get() ) == true

Reimplemented in WPropertyVariable< T >.

Definition at line 291 of file WFlag.h.

Referenced by WPropertyVariable< T >::ensureValidity(), WMEEGView::moduleMain(), WMEEGView::notifyConnectionEstablished(), WMEEGView::notifyDataChange(), WModule::reportRestoreComplete(), WPropertyVariable< T >::set(), WFlagTest::testChangeCondition(), and WFlagTest::testCopyConstruction().

+ Here is the caller graph for this function:

◆ wait()

template<typename T >
void WFlag< T >::wait
virtual

Wait for the flag to change its value.

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

Definition at line 279 of file WFlag.h.

Referenced by Callable::threadMain(), and WModule::waitRestored().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_changed

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

Denotes whether the value has changed since the last reset.

Definition at line 208 of file WFlag.h.

◆ m_condition

template<typename T >
std::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 192 of file WFlag.h.

◆ m_flag

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

The flag value.

Definition at line 203 of file WFlag.h.

◆ m_valueChangeCondition

template<typename T >
std::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 198 of file WFlag.h.


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