pixled-lib
1.0
|
#include <function.h>
Public Types | |
using | Type = typename base::Function< R >::Type |
Public Types inherited from pixled::base::Function< R > | |
typedef R | Type |
Public Member Functions | |
template<typename... Fcts> | |
Function (Fcts &&... fcts) | |
template<std::size_t i> | |
const base::Function< typename std::tuple_element< i, decltype(args)>::type::Type > & | arg () const |
template<std::size_t i> | |
std::tuple_element< i, decltype(args)>::type::Type | call (led l, time t) const |
Public Member Functions inherited from pixled::base::Function< R > | |
virtual R | operator() (led l, time t) const =0 |
Protected Member Functions | |
base::Function< R > * | copy () const override |
Protected Attributes | |
std::tuple< const FctWrapper< Args >... > | args |
Generic pixled function, the base of any animation components.
R
denotes the return type of this Function.
Args
is a list of primitive arguments of the function, e.g. float
, int
, std::string
, or any other type defined in the pixled namespace, e.g. pixled::point, pixled::line, pixled::time, pixled::color...
Particularly interesting Function implementations are base::Function<color> implementations, i.e. functions that return colors, since they define pixled animations that can be passed to a pixled::Runtime.
The purpose of the Function class is that it can be built using a list of other base::Functions that return instances of primitive types defined by Args
.
For this mechanism to work properly, the currently derived class (Implem
) should import Function constructors with a using
directive.
F
can then be constructed passing base::Function instances that returns the specified type for each argument. Constants can also be passed.
See the complete example below for the complete implementation and more details about the output.
Implem | final Function implementation (CRTP scheme) |
R | base::Function return type (fundamental type) |
Args | argument types (fundamental types returned by other functions) |
using pixled::Function< Implem, R, Args >::Type = typename base::Function<R>::Type |
Return type of this Function.
|
inline |
Function constructor.
The specified arguments list should be the same size as Args
, and each specified argument should be either a constant of the corresponding type in Args
, or a base::Function returning this type.
Functions specified as arguments can be passed either by l-value or r-value.
Fcts | Constructor argument types (automatically deduced) |
fcts | functionnal arguments |
|
inline |
Returns a reference to the functionnal argument at index i.
Indexing starts from 0, and follows the same order as specified in args
.
i | argument index |
|
inline |
Calls the functionnal argument at index i with the specified arguments.
This helper method is very useful to implement the call operator of this base::Function.
Indexing starts from 0, and follows the same order as specified in args
.
See the Function example for an example use case.
i | argument index |
l | led |
t | time |
|
inlineoverrideprotectedvirtual |
Returns a dynamically allocated copy of this function.
Implements pixled::base::Function< R >.
|
protected |