Class template active_function
poet::active_function — Create an active object from an ordinary function or object.
Synopsis
template<typename Signature> class active_function { public: // types typedef boost::function_traits<Signature>::result_type passive_result_type; typedef poet::future<passive_result_type> result_type; typedef boost::slot<Signature> passive_slot_type; // construct/copy/destruct active_function(const passive_slot_type &, boost::shared_ptr<scheduler_base> = boost::shared_ptr<scheduler_base>()); active_function(const active_function &); active_function(); active_function& operator=(const active_function &); virtual ~active_function(); // public member functions result_type operator()(future<T1>, future<T2>, ..., future<TN>); result_type operator()(future<T1>, future<T2>, ..., future<TN>) const; bool expired() const; };
Description
An active_function
can be created in one step from an ordinary function
or function object. By default, an active_function
is a fully functional active object
with its own scheduler. Multiple active_function
s may also share a scheduler and
be combined to form more complicated active objects.
In the following, the active_function is taken to have a signature of:
active_function<R (T1, T2, ..., TN)>
Example Code
active_function
public construct/copy/destruct
-
active_function(const passive_slot_type & passive_function, boost::shared_ptr<scheduler_base> scheduler = boost::shared_ptr<scheduler_base>());
Parameters:
passive_function
The underlying function this active_function object will call. The boost::slot class supports tracking of arbitrary boost::shared_ptr which are associated with the slot. For example, if the slot is constructed from a non-static member function, the lifetime of the member function's object can be tracked and the slot prevented from running after the object is destroyed.
scheduler
Specify a scheduler object for the active_function to post its method requests to. By default, a new Scheduler object is created for the active_function. If the active_function is providing a method as part of an active object class, you may wish for all the class' methods to share the same scheduler.
-
active_function(const active_function & other);
The copy constructor creates a shallow copy of
other
. Both copies share the same scheduler and passive function. -
active_function();
The default constructor creates an empty
active_function
which cannot be used until it is assigned a useableactive_function
. -
active_function& operator=(const active_function & rhs);
Assignment turns
*this
into a shallow copy ofrhs
. Both copies share the same scheduler and passive function. -
virtual ~active_function();
Virtual destructor.
active_function
public member functions
-
result_type operator()(future<T1> arg1, future<T2> arg2, ..., future<TN> argN); result_type operator()(future<T1> arg1, future<T2> arg2, ..., future<TN> argN) const;
Invocation creates a method request and sends it to the active_function's scheduler. The method request may be cancelled by calling
future::cancel
() on the returnedfuture
.Note the active_function takes futures as arguments, as well as returning a
future
. This allows future results to be passed from one active_function to another without waiting for the result to become ready. Since futures are constructible from their value types, the active_function can also take ordinary values not wrapped in futures as arguments. -
bool expired() const;
Calls the boost::slot::expired() query method on the slot this active_function was constructed from.