FastArduino  v1.8
C++ library to build fast but small Arduino/AVR projects
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 >:

Public Types

using STATUS_LISTENER = FutureStatusListener< F >
 The type to use for status listeners for this type of Future. More...
 

Protected Member Functions

 AbstractFuturesGroup (STATUS_LISTENER *status_listener=nullptr)
 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...
 
- Protected Member Functions inherited from future::FutureStatusListener< F >
virtual void on_status_change (const F &future, FutureStatus new_status)=0
 Called whenever a listened-to Future changes its FutureStatus. 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...
 

Additional Inherited Members

- Protected Attributes inherited from future::FutureStatusListener< F >
friend F
 

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_{} {}
F1& get_f1() { return f1_; }
F2& get_f2() { return f2_; }
F3& get_f3() { return f3_; }
private:
MyFuture1 f1_;
MyFuture2 f2_;
MyFuture3 f3_;
};

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 mehtods allow teh application to access individual futures.

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

Definition at line 1473 of file future.h.

Member Typedef Documentation

◆ STATUS_LISTENER

template<typename F >
using future::AbstractFuturesGroup< F >::STATUS_LISTENER = FutureStatusListener<F>

The type to use for status listeners for this type of Future.

See also
FutureStatusListener

Definition at line 1483 of file future.h.

Constructor & Destructor Documentation

◆ AbstractFuturesGroup()

template<typename F >
future::AbstractFuturesGroup< F >::AbstractFuturesGroup ( STATUS_LISTENER status_listener = nullptr)
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
status_listeneran optional listener to status changes on this future group
See also
init()
FutureStatus

Definition at line 1507 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 1524 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 1491 of file future.h.


The documentation for this class was generated from the following file:
future::AbstractFuturesGroup::AbstractFuturesGroup
AbstractFuturesGroup(STATUS_LISTENER *status_listener=nullptr)
Construct a new AbstractFuturesGroup.
Definition: future.h:1507