ROSE 0.11.145.147
|
List of callback functors.
This template defines ordered containers of callback functors and thread-safe functions for accessing the containers.
The first step is to create a functor class having one or more callbacks (operator() methods), each of which takes a struct reference containing the data to which the callback is applied.
The second step is to create a list to hold these callbacks. Our example callback was derived from a base class, so we'll use that base class as the list element type.
Add some callbacks to the list. We'll just add one for this example.
Finally, invoke all the callbacks in the list, supplying some arguments that will be used for each callback.
Definition at line 83 of file callbacks.h.
#include <roseSupport/callbacks.h>
Public Types | |
typedef T | CallbackType |
Functor class. | |
typedef std::list< CallbackType * > | CBList |
Standard vector of functor pointers. | |
Public Member Functions | |
List (const List &other) | |
List (CallbackType *callback) | |
size_t | size () const |
Returns the number of callbacks in the list. | |
bool | empty () const |
Predicate to test whether the list is empty. | |
List & | append (CallbackType *cb) |
Append a functor to the end of the list without copying it. | |
List & | prepend (CallbackType *cb) |
Prepend callback to beginning of 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. | |
List & | replace (CallbackType *old_cb, CallbackType *new_cb, size_t nreplacements=UNLIMITED, Direction dir=FORWARD) |
Replace one callback with another. | |
bool | erase (CallbackType *cb, Direction dir=FORWARD) |
Remove a callback from a list without destroying it. | |
List & | clear () |
Remove all callbacks from list without destroying them. | |
std::list< CallbackType * > | callbacks () const |
Returns a copy of the underlying STL vector of functors. | |
template<class ArgumentType > | |
bool | apply (bool b, const ArgumentType &args, Direction dir=FORWARD) const |
Invokes all functors in the callback list. | |
typedef T Rose::Callbacks::List< T >::CallbackType |
Functor class.
Definition at line 85 of file callbacks.h.
typedef std::list<CallbackType*> Rose::Callbacks::List< T >::CBList |
Standard vector of functor pointers.
Definition at line 86 of file callbacks.h.
|
inline |
Definition at line 93 of file callbacks.h.
|
inline |
Definition at line 95 of file callbacks.h.
|
inlineexplicit |
Definition at line 100 of file callbacks.h.
|
inline |
Returns the number of callbacks in the list.
Thread safety: This method is thread safe.
Definition at line 107 of file callbacks.h.
|
inline |
Predicate to test whether the list is empty.
Returns true if the list is empty, false otherwise.
Thread safety: This method is thread safe.
Definition at line 117 of file callbacks.h.
|
inline |
Append a functor to the end of the list without copying it.
Functors can be inserted more than once into a list, and each occurrence will be called by the apply() method.
Thread safety: This method is thread safe. In fact, it is safe to modify the list while apply() is calling the functors on that list.
Definition at line 128 of file callbacks.h.
|
inline |
Prepend callback to beginning of list without copying it.
Functors can be inserted more than once into a list, and each occurrence will be called by the apply() method.
Thread safety: This method is thread safe. In fact, it is safe to modify the list while apply() is calling the functors on that list.
Definition at line 141 of file callbacks.h.
|
inline |
Insert a callback after another.
The callback is inserted after each occurrence of the relative_to
callback. Up to nreplacement
insertions are made beginning at the front of the list.
Thread safety: This method is thread safe. In fact, it is safe to modify the list while apply() is calling the functors on that list.
Definition at line 155 of file callbacks.h.
|
inline |
Insert a callback before another.
The callback is inserted before each occurrence of the relative_to
callback. Up to nreplacement
insertions are made begin$ning at the front of the list.
Thread safety: This method is thread safe. In fact, it is safe to modify the list while apply() is calling the functors on that list.
Definition at line 172 of file callbacks.h.
|
inline |
Replace one callback with another.
The replaced callback is removed from the list as if by erase() without deleting it, and its replacement is inserted at the same position without copying it. At most nreplacements
are performed (the default is unlimited). Replacements are performed in the direction specified.
Thread safety: This method is thread safe. In fact, it is safe to modify the list while apply() is calling the functors on that list.
Definition at line 193 of file callbacks.h.
References Rose::Callbacks::FORWARD.
|
inline |
Remove a callback from a list without destroying it.
The list is traversed in the specified direction and the first functor that matches (by pointer comparison) the specified callback is removed from the list. Returns true if a functor was removed, false otherwise.
Thread safety: This method is thread safe. In fact, it is safe to modify the list while apply() is calling the functors on that list.
Definition at line 221 of file callbacks.h.
References Rose::Callbacks::FORWARD.
|
inline |
Remove all callbacks from list without destroying them.
Thread safety: This method is thread safe. In fact, it is safe to modify the list while apply() is calling the functors on that list.
Definition at line 245 of file callbacks.h.
Referenced by Rose::BinaryAnalysis::AsmUnparser::CallbackLists::clear().
|
inline |
Returns a copy of the underlying STL vector of functors.
Thread safety: This method is thread safe.
Definition at line 254 of file callbacks.h.
Referenced by Rose::Callbacks::List< T >::apply().
|
inline |
Invokes all functors in the callback list.
The functors are invoked sequentially in the order specified by calling its operator() method. Two arguments are provided: a boolean value, and an additional argument with parameterized type. The boolean argument for the first callback is the b
argument of this method; the boolean argument of the subsequent callbacks is the return value of the previous callback; the return value of this method is the return value of the last callback (or the initial value of b
if no callbacks were made).
Thread safety: This method is thread safe. If this list is modified by one or more of the functors on this list or by another thread, those changes do not affect which callbacks are made by this invocation of apply(). The callbacks should not assume that any particular mutexes or other thread synchronization resources are held. It is possible for a single callback to be invoked concurrently if two or more threads invoke apply() concurrently.
Definition at line 272 of file callbacks.h.
References Rose::Callbacks::List< T >::callbacks(), and Rose::Callbacks::FORWARD.