1 #ifndef ROSE_Callbacks_H
2 #define ROSE_Callbacks_H
4 #include <boost/thread/locks.hpp>
5 #include <boost/thread/mutex.hpp>
85 typedef std::list<CallbackType*>
CBList;
88 mutable boost::mutex mutex_;
95 boost::lock_guard<boost::mutex> lock(other.mutex_);
99 explicit List(CallbackType *callback) {
107 boost::lock_guard<boost::mutex> lock(mutex_);
117 boost::lock_guard<boost::mutex> lock(mutex_);
129 boost::lock_guard<boost::mutex> lock(mutex_);
142 boost::lock_guard<boost::mutex> lock(mutex_);
156 boost::lock_guard<boost::mutex> lock(mutex_);
157 for (
typename CBList::iterator li=list.begin(); li!=list.end() && nreplacements>0; ++li) {
158 if (*li==relative_to) {
159 li = list.insert(++li, cb);
173 boost::lock_guard<boost::mutex> lock(mutex_);
174 for (
typename CBList::iterator li=list.begin(); li!=list.end() && nreplacements>0; ++li) {
175 if (*li==relative_to) {
176 li = list.insert(li, cb);
193 assert(new_cb!=NULL);
194 boost::lock_guard<boost::mutex> lock(mutex_);
196 for (
typename CBList::iterator li=list.begin(); li!=list.end() && nreplacements>0; ++li) {
203 for (
typename CBList::reverse_iterator li=list.rbegin(); li!=list.rend() && nreplacements>0; ++li) {
221 boost::lock_guard<boost::mutex> lock(mutex_);
223 for (
typename CBList::iterator li=list.begin(); li!=list.end(); ++li) {
230 for (
typename CBList::reverse_iterator li=list.rbegin(); li!=list.rend(); ++li) {
232 list.erase((++li).base());
245 boost::lock_guard<boost::mutex> lock(mutex_);
254 boost::lock_guard<boost::mutex> lock(mutex_);
270 template<
class ArgumentType>
274 for (
typename CBList::iterator li=list.begin(); li!=list.end(); ++li) {
278 for (
typename CBList::reverse_iterator li=list.rbegin(); li!=list.rend(); ++li) {
std::list< CallbackType * > callbacks() const
Returns a copy of the underlying STL vector of functors.
List of callback functors.
List & prepend(CallbackType *cb)
Prepend callback to beginning of list without copying it.
Traverse the list from back to front.
List & replace(CallbackType *old_cb, CallbackType *new_cb, size_t nreplacements=UNLIMITED, Direction dir=FORWARD)
Replace one callback with another.
Main namespace for the ROSE library.
std::list< CallbackType * > CBList
Standard vector of functor pointers.
Direction
Direction of callback list traversal.
const size_t UNLIMITED(static_cast< size_t >(-1))
Effictively unlimited size.
List & before(CallbackType *relative_to, CallbackType *cb, size_t nreplacements=UNLIMITED)
Insert a callback before another.
bool erase(CallbackType *cb, Direction dir=FORWARD)
Remove a callback from a list without destroying it.
bool empty() const
Predicate to test whether the list is empty.
Traverse the list from front to back.
size_t size() const
Returns the number of callbacks in the list.
List & append(CallbackType *cb)
Append a functor to the end of the list without copying it.
List & clear()
Remove all callbacks from list without destroying them.
T CallbackType
Functor class.
List & after(CallbackType *relative_to, CallbackType *cb, size_t nreplacements=UNLIMITED)
Insert a callback after another.
bool apply(bool b, const ArgumentType &args, Direction dir=FORWARD) const
Invokes all functors in the callback list.