OpenWalnut
1.5.0dev
|
Class to have a simple notification/condition system for simple flags. More...
#include <WFlag.h>
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< WCondition > | getCondition () |
Returns the condition that is used by this flag. More... | |
std::shared_ptr< WCondition > | getValueChangeCondition () |
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< WCondition > | m_condition |
The condition to be used for waiting/notifying. More... | |
std::shared_ptr< WCondition > | m_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... | |
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.
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.
condition | the condition to use. |
initial | the initial value of this flag. |
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.
condition | the condition to use. |
initial | the initial value of this flag. |
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).
from | the instance to copy. |
Destructor.
It deletes the instance of WCondition specified on construction.
|
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.
newValue | the new value. |
Reimplemented in WPropertyVariable< T >.
Definition at line 331 of file WFlag.h.
Referenced by WPropertyVariable< T >::accept().
|
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.
reset | if true, the change flag gets reset. |
Definition at line 344 of file WFlag.h.
Referenced by WFlagTest::testChangeFlagAndReset(), and WFlagTest::testCopyConstruction().
|
virtual |
|
virtual |
Operator returns value of the flag.
resetChangeState | when true, the changed() flag gets reset to false. |
Definition at line 257 of file WFlag.h.
Referenced by WPropertyVariable< T >::accept(), WPropertyVariable< T >::addConstraint(), WPropertyVariable< T >::countConstraint(), WFlagForwarder< T >::forward(), WPropertyVariable< T >::getFirstConstraint(), WPropertyVariable< T >::removeConstraint(), WPropertyVariable< T >::removeConstraints(), WPropertyVariable< T >::replaceConstraint(), WFlagTest::testChangeCondition(), WFlagTest::testChangeFlagAndReset(), WFlagTest::testCopyConstruction(), WPropertyVariable< T >::WPropertyVariable(), and WPropertyVariable< T >::~WPropertyVariable().
std::shared_ptr< WCondition > WFlag< T >::getCondition |
Returns the condition that is used by this flag.
Definition at line 319 of file WFlag.h.
Referenced by WMEEGView::moduleMain(), WMEEGView::openCustomWidget(), WFlagTest::testCopyConstruction(), and WModule::WModule().
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.
Definition at line 325 of file WFlag.h.
Referenced by WMHistogramView::moduleMain(), WMMultiHistogramView::moduleMain(), WMTemplateUI::moduleMain(), WFlagTest::testCopyConstruction(), and WPropertyVariable< T >::WPropertyVariable().
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
Sets the new value for this flag.
Also notifies waiting threads. After setting a value, changed() will be true.
value | the new value |
suppressNotification | true to avoid a firing condition. This is useful for resetting values. |
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().
|
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().
|
protected |
|
protected |
|
protected |
|
protected |