papyrus logo

Papyrus::DrawableWatcher Class Reference

DrawableWatcher is similar to DrawableMultiContainer except that it does not own the drawables it is watching. More...

#include <drawablewatcher.h>

Inheritance diagram for Papyrus::DrawableWatcher:
Inheritance graph
[legend]

List of all members.

Public Types

typedef PapyrusPointer
< DrawableWatcher
pointer
typedef std::set
< Drawable::weak_pointer,
wp_lt_compare
Watched

Public Member Functions

 DrawableWatcher ()
virtual ~DrawableWatcher ()
virtual bool watch (Drawable::pointer item)
 Watches a particular drawable for changes.
virtual bool remove_watch (Drawable::pointer item)
 Stops watching a particular drawable for changes.
virtual void remove_all_watches ()
 Stops watching all drawables previously watched.
const Watchedwatched () const
 Returns the set of drawables being watched.
bool is_watched (Drawable::pointer item)
 True if the specified drawable is being watched.
virtual void link (DrawableSet::pointer s)
 Links this watcher to the drawable set causing the watcher to watch/remove watches as items are added to / removed from the set.
virtual void unlink (DrawableSet::pointer s)
 Unlinks the watcher and the DrawableSet.
sigc::signal< void,
Drawable::pointer > & 
signal_watch_added ()
 Signal emitted when a drawable is watched.
sigc::signal< void,
Drawable::pointer > & 
signal_watch_removed ()
 Signal emitted when a drawable is no longer watched.
sigc::signal< void,
Drawable::pointer > & 
signal_watched_changed ()
 Signal emitted when a watched drawable emits the changed signal.

Protected Types

typedef std::map
< Drawable::weak_pointer,
sigc::connection,
wp_lt_compare
Connections
 Map from a drawable to a signal connection.

Protected Member Functions

virtual void on_watched_changed (Drawable::pointer watched)
 Virtual method called when a watched child is changed.

Protected Attributes

Watched m_watched
 The set of drawables being watched.
Connections m_watched_changed_connections
Connections m_watched_destroyed_connections
std::map< DrawableSet::pointer,
sigc::connection > 
m_linked_added_conn_map
std::map< DrawableSet::pointer,
sigc::connection > 
m_linked_removed_conn_map
sigc::signal< void,
Drawable::pointer
m_signal_watch_added
sigc::signal< void,
Drawable::pointer
m_signal_watch_removed
sigc::signal< void,
Drawable::pointer
m_signal_watched_changed

Private Member Functions

void on_watched_changed_proxy (Drawable::weak_pointer watched)
 When a child is watched, this is the method connected to the child's changed signal which in turn calls on_watched_changed().
void on_watched_destroyed (Drawable::weak_pointer watched)
 This method is connected to a child's destroyed signal causing automatic removal of the child.
void on_linked_set_drawable_added (Drawable::pointer added)
void on_linked_set_drawable_removed (Drawable::pointer removed)

Detailed Description

DrawableWatcher is similar to DrawableMultiContainer except that it does not own the drawables it is watching.

DrawableWatcher, unlike DrawableMultiContainer, uses weak smart pointers and thus does not take ownership of the items it is watching. Therefore, unless the item is owned by a group or some container other than the DrawableWatcher the drawable will be destroyed.

DrawableWatcher observes the destroyed signal of the drawables it is watching and removes them immediately upon destruction.

Since the container stores weak pointers, as a side note on weak vs. strong smart pointers; you can create a strong (owner) pointer from a weak (non-owning) pointer through the lock() method.

Author:
Rick L Vinyard Jr <rvinyard@cs.nmsu.edu>

Member Typedef Documentation

typedef std::map<Drawable::weak_pointer, sigc::connection, wp_lt_compare> Papyrus::DrawableWatcher::Connections [protected]

Map from a drawable to a signal connection.

typedef std::set<Drawable::weak_pointer, wp_lt_compare> Papyrus::DrawableWatcher::Watched

Constructor & Destructor Documentation

Papyrus::DrawableWatcher::DrawableWatcher (  ) 
Papyrus::DrawableWatcher::~DrawableWatcher (  )  [virtual]

Member Function Documentation

bool Papyrus::DrawableWatcher::is_watched ( Drawable::pointer  item  ) 

True if the specified drawable is being watched.

References m_watched.

void Papyrus::DrawableWatcher::link ( DrawableSet::pointer  s  )  [virtual]

Links this watcher to the drawable set causing the watcher to watch/remove watches as items are added to / removed from the set.

References m_linked_added_conn_map, m_linked_removed_conn_map, on_linked_set_drawable_added(), on_linked_set_drawable_removed(), and watch().

void Papyrus::DrawableWatcher::on_linked_set_drawable_added ( Drawable::pointer  added  )  [private]

References watch().

Referenced by link().

void Papyrus::DrawableWatcher::on_linked_set_drawable_removed ( Drawable::pointer  removed  )  [private]

References remove_watch().

Referenced by link().

void Papyrus::DrawableWatcher::on_watched_changed ( Drawable::pointer  watched  )  [protected, virtual]

Virtual method called when a watched child is changed.

When a watch is added, the watched item's changed signal is actually connected to the private proxy method, which in turn calls the virtual method. This allows children to implement their own behavior by reimplementing this method without worrying about modifying the add() or remove() methods.

Referenced by on_watched_changed_proxy().

void Papyrus::DrawableWatcher::on_watched_changed_proxy ( Drawable::weak_pointer  watched  )  [private]

When a child is watched, this is the method connected to the child's changed signal which in turn calls on_watched_changed().

References m_signal_watched_changed, and on_watched_changed().

Referenced by watch().

void Papyrus::DrawableWatcher::on_watched_destroyed ( Drawable::weak_pointer  watched  )  [private]

This method is connected to a child's destroyed signal causing automatic removal of the child.

References remove_watch().

Referenced by watch().

void Papyrus::DrawableWatcher::remove_all_watches (  )  [virtual]

Stops watching all drawables previously watched.

References m_signal_watch_removed, m_watched, m_watched_changed_connections, and m_watched_destroyed_connections.

bool Papyrus::DrawableWatcher::remove_watch ( Drawable::pointer  item  )  [virtual]
sigc::signal< void, Drawable::pointer > & Papyrus::DrawableWatcher::signal_watch_added (  ) 

Signal emitted when a drawable is watched.

References m_signal_watch_added.

sigc::signal< void, Drawable::pointer > & Papyrus::DrawableWatcher::signal_watch_removed (  ) 

Signal emitted when a drawable is no longer watched.

References m_signal_watch_removed.

sigc::signal< void, Drawable::pointer > & Papyrus::DrawableWatcher::signal_watched_changed (  ) 

Signal emitted when a watched drawable emits the changed signal.

References m_signal_watched_changed.

void Papyrus::DrawableWatcher::unlink ( DrawableSet::pointer  s  )  [virtual]

Unlinks the watcher and the DrawableSet.

References m_linked_added_conn_map, and m_linked_removed_conn_map.

bool Papyrus::DrawableWatcher::watch ( Drawable::pointer  item  )  [virtual]
const DrawableWatcher::Watched & Papyrus::DrawableWatcher::watched (  )  const

Returns the set of drawables being watched.

References m_watched.


Member Data Documentation

Referenced by link(), and unlink().

Referenced by link(), and unlink().

The set of drawables being watched.

Referenced by Papyrus::Boxed::calculate_extents(), is_watched(), remove_all_watches(), remove_watch(), watch(), and watched().


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

Generated on Fri Apr 16 12:41:07 2010 for papyrus by doxygen 1.6.1