OpenWalnut  1.4.0
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
WPropertyObserver Class Reference

This class can observe properties inside a property group. More...

#include <WPropertyObserver.h>

+ Inheritance diagram for WPropertyObserver:

Public Types

typedef std::map< std::string,
boost::shared_ptr
< WPropertyBase > > 
PropertyNameMap
 Convenience type for a set of property instances.
typedef boost::shared_ptr
< WPropertyObserver
SPtr
 Convenience type for a shared pointer on property observers.
- Public Types inherited from WCondition
typedef boost::shared_ptr
< WCondition
SPtr
 Shared pointer type for WCondition.
typedef boost::shared_ptr
< const WCondition
ConstSPtr
 Const shared pointer type for WCondition.
typedef boost::function0< void > t_ConditionNotifierType
 Type used for signalling condition changes.

Public Member Functions

 WPropertyObserver ()
 Default constructor.
virtual ~WPropertyObserver ()
 Destructor.
void observe (boost::shared_ptr< WProperties > properties, std::set< std::string > names=std::set< std::string >())
 Defines the property group whose children should be watched.
bool updated () const
 Is true if one observed property fired.
PropertyNameMap handled ()
 Resets the update flag and the list of fired properties.
- Public Member Functions inherited from WCondition
 WCondition ()
 Default constructor.
virtual ~WCondition ()
 Destructor.
virtual void wait () const
 Wait for the condition.
virtual void notify ()
 Notifies all waiting threads.
boost::signals2::connection subscribeSignal (t_ConditionNotifierType notifier) const
 Subscribes a specified function to be notified on condition change.

Static Public Member Functions

static boost::shared_ptr
< WPropertyObserver
create ()
 Creates a new instance of WPropertyObserver.

Private Types

typedef
WSharedAssociativeContainer
< std::map< boost::shared_ptr
< WPropertyBase >
, boost::signals2::connection > > 
Subscriptions
 Type for shared container with signal connections.
typedef
WSharedAssociativeContainer
< PropertyNameMap
LastUpdated
 Type of shared container for the list of last updated properties.

Private Member Functions

 WPropertyObserver (const WPropertyObserver &rhs)
 Disallow copy construction.
WPropertyObserveroperator= (const WPropertyObserver &rhs)
 Disallow copy assignment.
void cancelSubscriptions ()
 Cancels all current subscriptions and cleans m_subscriptions.
void updateSubscriptions ()
 Subscribes each property update condition which matches an entry in m_propNames.
void propertyUpdated (boost::shared_ptr< WPropertyBase > property)
 Gets called by the update callback of the property.

Private Attributes

Subscriptions m_subscriptions
 The subscription to each property which was subscribed.
bool m_updated
 True if a property fired.
boost::shared_ptr< WPropertiesm_properties
 The properties handled by this observer.
std::set< std::string > m_propNames
 The names of the properties which shall be observed if they are or become available.
boost::signals2::scoped_connection m_updateConditionConnection
 The connection used to get notified about m_properties updates.
LastUpdated m_lastUpdated
 The queue of properties that fired before handled() is called.

Additional Inherited Members

- Protected Types inherited from WCondition
typedef
boost::signals2::signal< void(void)> 
t_ConditionSignalType
 Type used for condition notification.
- Protected Attributes inherited from WCondition
t_ConditionSignalType signal_ConditionFired
 Signal getting fired whenever the condition fires.
boost::condition_variable_any m_condition
 The condition.
boost::shared_mutex m_mutex
 The mutex used for the condition.

Detailed Description

This class can observe properties inside a property group.

The property group to observer can simply be set and replaced comfortably. Whenever one of the child properties updates, the observer fires too. If the observed property group itself changes (added properties, removed properties and so on), the observer gets updated automatically.

Definition at line 44 of file WPropertyObserver.h.

Member Typedef Documentation

Type of shared container for the list of last updated properties.

Definition at line 165 of file WPropertyObserver.h.

typedef std::map< std::string, boost::shared_ptr< WPropertyBase > > WPropertyObserver::PropertyNameMap

Convenience type for a set of property instances.

Definition at line 50 of file WPropertyObserver.h.

typedef boost::shared_ptr< WPropertyObserver > WPropertyObserver::SPtr

Convenience type for a shared pointer on property observers.

Definition at line 55 of file WPropertyObserver.h.

typedef WSharedAssociativeContainer< std::map< boost::shared_ptr< WPropertyBase >, boost::signals2::connection > > WPropertyObserver::Subscriptions
private

Type for shared container with signal connections.

Definition at line 135 of file WPropertyObserver.h.

Constructor & Destructor Documentation

WPropertyObserver::WPropertyObserver ( )

Default constructor.

Definition at line 31 of file WPropertyObserver.cpp.

Referenced by create().

WPropertyObserver::~WPropertyObserver ( )
virtual

Destructor.

Definition at line 42 of file WPropertyObserver.cpp.

WPropertyObserver::WPropertyObserver ( const WPropertyObserver rhs)
private

Disallow copy construction.

Parameters
rhsthe other threaded runner.

Member Function Documentation

void WPropertyObserver::cancelSubscriptions ( )
private

Cancels all current subscriptions and cleans m_subscriptions.

Definition at line 95 of file WPropertyObserver.cpp.

References WSharedObject< T >::getWriteTicket(), and m_subscriptions.

Referenced by observe().

boost::shared_ptr< WPropertyObserver > WPropertyObserver::create ( )
static

Creates a new instance of WPropertyObserver.

Useful to save some typing as it creates an shared pointer for you.

Returns
the new instance.

Definition at line 139 of file WPropertyObserver.cpp.

References WPropertyObserver().

WPropertyObserver::PropertyNameMap WPropertyObserver::handled ( )

Resets the update flag and the list of fired properties.

Returns
the set of properties fired until the last call of handled.

Definition at line 52 of file WPropertyObserver.cpp.

References WSharedObject< T >::getWriteTicket(), m_lastUpdated, and m_updated.

void WPropertyObserver::observe ( boost::shared_ptr< WProperties properties,
std::set< std::string >  names = std::set< std::string >() 
)

Defines the property group whose children should be watched.

You can define a list of names manually if you are not interested in updates of ALL properties.

Notes:
this also resets the updated flag and the list of the last fired properties.
Parameters
propertiesthe group whose children should be watched.
nameslist of names. If specified, only these properties are observed.

Definition at line 66 of file WPropertyObserver.cpp.

References cancelSubscriptions(), WSharedObject< T >::getWriteTicket(), m_lastUpdated, m_properties, m_propNames, m_updateConditionConnection, m_updated, and updateSubscriptions().

WPropertyObserver& WPropertyObserver::operator= ( const WPropertyObserver rhs)
private

Disallow copy assignment.

Parameters
rhsthe other threaded runner.
Returns
this.
void WPropertyObserver::propertyUpdated ( boost::shared_ptr< WPropertyBase property)
private

Gets called by the update callback of the property.

The property given as parameter was the property that fired.

Parameters
propertythe property that fired.

Definition at line 130 of file WPropertyObserver.cpp.

References WSharedObject< T >::getWriteTicket(), m_lastUpdated, m_updated, and WCondition::notify().

Referenced by updateSubscriptions().

bool WPropertyObserver::updated ( ) const

Is true if one observed property fired.

This is reset by the handled method.

Returns
true if one property fired.

Definition at line 47 of file WPropertyObserver.cpp.

References m_updated.

void WPropertyObserver::updateSubscriptions ( )
private

Subscribes each property update condition which matches an entry in m_propNames.

Definition at line 110 of file WPropertyObserver.cpp.

References WSharedObject< T >::getWriteTicket(), m_properties, m_propNames, m_subscriptions, and propertyUpdated().

Referenced by observe().

Member Data Documentation

LastUpdated WPropertyObserver::m_lastUpdated
private

The queue of properties that fired before handled() is called.

Definition at line 170 of file WPropertyObserver.h.

Referenced by handled(), observe(), and propertyUpdated().

boost::shared_ptr< WProperties > WPropertyObserver::m_properties
private

The properties handled by this observer.

Definition at line 150 of file WPropertyObserver.h.

Referenced by observe(), and updateSubscriptions().

std::set< std::string > WPropertyObserver::m_propNames
private

The names of the properties which shall be observed if they are or become available.

Definition at line 155 of file WPropertyObserver.h.

Referenced by observe(), and updateSubscriptions().

Subscriptions WPropertyObserver::m_subscriptions
private

The subscription to each property which was subscribed.

Definition at line 140 of file WPropertyObserver.h.

Referenced by cancelSubscriptions(), and updateSubscriptions().

boost::signals2::scoped_connection WPropertyObserver::m_updateConditionConnection
private

The connection used to get notified about m_properties updates.

Definition at line 160 of file WPropertyObserver.h.

Referenced by observe().

bool WPropertyObserver::m_updated
private

True if a property fired.

Definition at line 145 of file WPropertyObserver.h.

Referenced by handled(), observe(), propertyUpdated(), and updated().


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