FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
future::AbstractFuturesGroup< F > Class Template Reference

Abstract class to allow aggregation of several futures. More...

#include <fastarduino/future.h>

Inheritance diagram for future::AbstractFuturesGroup< F >:
Collaboration diagram for future::AbstractFuturesGroup< F >:

Protected Member Functions

 AbstractFuturesGroup (FutureNotification notifications=FutureNotification::NONE)
 Construct a new AbstractFuturesGroup. More...
 
void init (utils::range< F * > futures, uint16_t actual_size=0)
 Called from constructors of subclasses, this method allows this group to listen for the status of all its futures. More...
 
void on_status_change_pre_step (const F &future, FutureStatus status)
 This must be called by subclasses on_status_change() method, after checking that future is one of the futures handled by this instance, and before performing any further processing. More...
 

Static Protected Attributes

static constexpr const uint16_t NO_LIMIT = 0xFFFFU
 Specific size value indicating this group has an unlimited (and unknown at construction time) number of futures to handle. More...
 

Detailed Description

template<typename F>
class future::AbstractFuturesGroup< F >

Abstract class to allow aggregation of several futures.

This allows to await() for all futures, or query the overall status() of the group.

The following snippet shows how this must be used to create an actual group of futures:

class MyGroup : public AbstractFuturesGroup<AbstractFuture>
{
public:
MyGroup() : AbstractFuturesGroup<AbstractFuture>{{&f1_, &f2_, &f3_}}, f1_{}, f2_{}, f3_{} {
}
~MyGroup() {
}
F1& get_f1() { return f1_; }
F2& get_f2() { return f2_; }
F3& get_f3() { return f3_; }
private:
void on_status_change(const AbstractFuture& future, FutureStatus status) {
// Check future is one of our own futures
if (&future == &f1_ || &future == &f2_ || &future == &f3_) {
on_status_change_pre_step(future, status);
// Any further specific processing goes here...
}
}
MyFuture1 f1_;
MyFuture2 f2_;
MyFuture3 f3_;
};
...
// Register all future notification listeners
REGISTER_FUTURE_STATUS_LISTENERS(AbstractFuture, MyGroup)
Base class for all Futures.
Definition: future.h:426
Abstract class to allow aggregation of several futures.
Definition: future.h:1576
Contains the API around Future implementation.
Definition: future.h:312
void register_handler(Handler &handler)
Register a class instance containing methods that shall be called back by an ISR.
Definition: interrupts.h:185
void unregister_handler(Handler &handler)
Unregister a class instance that was previously registered with interrupt::register_handler.
Definition: interrupts.h:207

In that snippet, MyGroup embeds 3 different futures, each of a different type; the 3 futures are constructed at MyGroup construction time, and their pointers passed to the parent FuturesGroup. Three getter methods allow the application to access individual futures.

Note the calls to interrupt::register_handler() and interrupt::unregister_handler() in the constructor and the destructor.

Also note the on_status_change() method, that will be called whenever any individual future has its status modified.

Finally, for the notification mechanism to work MyGroup must be registered as a listener, which is done with REGISTER_FUTURE_STATUS_LISTENERS().

Template Parameters
Fthe type of Future to aggregate int this group; this shall be either AbstractFuture or AbstractFakeFuture.

Definition at line 1575 of file future.h.

Constructor & Destructor Documentation

◆ AbstractFuturesGroup()

template<typename F >
future::AbstractFuturesGroup< F >::AbstractFuturesGroup ( FutureNotification  notifications = FutureNotification::NONE)
inlineexplicitprotected

Construct a new AbstractFuturesGroup.

The created Group is in FutureStatus::NOT_READY status. The Future holds buffers to store both the input storage value and the output value. The subclass constructor must call init() with the list of futures in this group.

Parameters
notificationsdetermines if and which notifications should be dispatched by this Future; default is none.
See also
init()
FutureNotification
FutureStatus

Definition at line 1603 of file future.h.

Member Function Documentation

◆ init()

template<typename F >
void future::AbstractFuturesGroup< F >::init ( utils::range< F * >  futures,
uint16_t  actual_size = 0 
)
inlineprotected

Called from constructors of subclasses, this method allows this group to listen for the status of all its futures.

Parameters
futureslist of pointers to futures in this group
actual_sizereal number of futures; if 0 (default), this will match the size of futures; it may be bigger than the actual number of futures if e.g. a future is reused several times in this group; if NO_LIMIT, then the subclass does not know in advance how many times its futures shall be used, in this case, the subclass must itself indicate when this group of future is FutureStatus::READY.
See also
FutureStatus
Future::set_future_finish()

Definition at line 1620 of file future.h.

◆ on_status_change_pre_step()

template<typename F >
void future::AbstractFuturesGroup< F >::on_status_change_pre_step ( const F future,
FutureStatus  status 
)
inlineprotected

This must be called by subclasses on_status_change() method, after checking that future is one of the futures handled by this instance, and before performing any further processing.

Parameters
futurea reference to the future which status has changed
statusthe new status of future

Definition at line 1635 of file future.h.

Member Data Documentation

◆ NO_LIMIT

template<typename F >
constexpr const uint16_t future::AbstractFuturesGroup< F >::NO_LIMIT = 0xFFFFU
staticconstexprprotected

Specific size value indicating this group has an unlimited (and unknown at construction time) number of futures to handle.

See also
init()

Definition at line 1586 of file future.h.


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