OpenWalnut
1.4.0
|
This class can observe properties inside a property group. More...
#include <WPropertyObserver.h>
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 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. | |
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. | |
WPropertyObserver & | operator= (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< WProperties > | m_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. |
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.
typedef WSharedAssociativeContainer< PropertyNameMap > WPropertyObserver::LastUpdated [private] |
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.
Reimplemented from WCondition.
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.
WPropertyObserver::~WPropertyObserver | ( | ) | [virtual] |
Destructor.
Definition at line 42 of file WPropertyObserver.cpp.
WPropertyObserver::WPropertyObserver | ( | const WPropertyObserver & | rhs | ) | [private] |
Disallow copy construction.
rhs | the other threaded runner. |
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.
Definition at line 139 of file WPropertyObserver.cpp.
References WPropertyObserver().
Resets the update flag and the list of fired properties.
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.
properties | the group whose children should be watched. |
names | list 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.
rhs | the other threaded runner. |
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.
property | the 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.
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().
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().
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().