1#ifndef ROSE_Callbacks_H
2#define ROSE_Callbacks_H
3#include <Rose/Constants.h>
5#include <boost/thread/locks.hpp>
6#include <boost/thread/mutex.hpp>
86 typedef std::list<CallbackType*>
CBList;
89 mutable boost::mutex mutex_;
96 boost::lock_guard<boost::mutex> lock(other.mutex_);
108 boost::lock_guard<boost::mutex> lock(mutex_);
118 boost::lock_guard<boost::mutex> lock(mutex_);
130 boost::lock_guard<boost::mutex> lock(mutex_);
143 boost::lock_guard<boost::mutex> lock(mutex_);
157 boost::lock_guard<boost::mutex> lock(mutex_);
158 for (
typename CBList::iterator li=list.begin(); li!=list.end() && nreplacements>0; ++li) {
159 if (*li==relative_to) {
160 li = list.insert(++li, cb);
174 boost::lock_guard<boost::mutex> lock(mutex_);
175 for (
typename CBList::iterator li=list.begin(); li!=list.end() && nreplacements>0; ++li) {
176 if (*li==relative_to) {
177 li = list.insert(li, cb);
194 assert(new_cb!=NULL);
195 boost::lock_guard<boost::mutex> lock(mutex_);
197 for (
typename CBList::iterator li=list.begin(); li!=list.end() && nreplacements>0; ++li) {
204 for (
typename CBList::reverse_iterator li=list.rbegin(); li!=list.rend() && nreplacements>0; ++li) {
222 boost::lock_guard<boost::mutex> lock(mutex_);
224 for (
typename CBList::iterator li=list.begin(); li!=list.end(); ++li) {
231 for (
typename CBList::reverse_iterator li=list.rbegin(); li!=list.rend(); ++li) {
233 list.erase((++li).base());
246 boost::lock_guard<boost::mutex> lock(mutex_);
255 boost::lock_guard<boost::mutex> lock(mutex_);
271 template<
class ArgumentType>
275 for (
typename CBList::iterator li=list.begin(); li!=list.end(); ++li) {
279 for (
typename CBList::reverse_iterator li=list.rbegin(); li!=list.rend(); ++li) {
List of callback functors.
List & replace(CallbackType *old_cb, CallbackType *new_cb, size_t nreplacements=UNLIMITED, Direction dir=FORWARD)
Replace one callback with another.
List & clear()
Remove all callbacks from list without destroying them.
List & prepend(CallbackType *cb)
Prepend callback to beginning of list without copying it.
bool erase(CallbackType *cb, Direction dir=FORWARD)
Remove a callback from a list without destroying it.
std::list< CallbackType * > CBList
Standard vector of functor pointers.
size_t size() const
Returns the number of callbacks in the list.
bool apply(bool b, const ArgumentType &args, Direction dir=FORWARD) const
Invokes all functors in the callback list.
bool empty() const
Predicate to test whether the list is empty.
T CallbackType
Functor class.
List & append(CallbackType *cb)
Append a functor to the end of the list without copying it.
List & after(CallbackType *relative_to, CallbackType *cb, size_t nreplacements=UNLIMITED)
Insert a callback after another.
List & before(CallbackType *relative_to, CallbackType *cb, size_t nreplacements=UNLIMITED)
Insert a callback before another.
std::list< CallbackType * > callbacks() const
Returns a copy of the underlying STL vector of functors.
Direction
Direction of callback list traversal.
@ BACKWARD
Traverse the list from back to front.
@ FORWARD
Traverse the list from front to back.
const size_t UNLIMITED
Effectively unlimited size.