pixled-lib  1.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
pixled::Function< Implem, R, Args > Class Template Reference

#include <function.h>

Inheritance diagram for pixled::Function< Implem, R, Args >:
Inheritance graph
[legend]
Collaboration diagram for pixled::Function< Implem, R, Args >:
Collaboration graph
[legend]

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
 

Detailed Description

template<typename Implem, typename R, typename... Args>
class pixled::Function< Implem, R, 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.

Example
class F : public pixled::Function<F, point, point, int, float> {
public:
// Import constructors
...
}
Definition: function.h:349

F can then be constructed passing base::Function instances that returns the specified type for each argument. Constants can also be passed.

Note
It is possible to pass function arguments in almost all the way available in C++, by l-value or r-value, since FctWrapper knows how to handle all those cases without memory issues. Moreover, notice that f is copyable, function parameters can be safely destroyed without altering the Function instance.
F build_f() {
// Required to use the * operator properly.
// This directive can also be called at the namespace level.
using namespace pixled;
// A function that returns a pixled::time
auto time_fct = 2 * pixled::chrono::T();
return F(
// A constant point, passed by r-value
// An function that returns a time, passed by l-value
time_fct,
// A function that returns a float, passed by r-value
);
}
int main(int argc, char** argv) {
// Builds an f instance
F f = build_f();
// Apply F on p=point(2, 0) at t=10
std::cout << f(pixled::led(pixled::point(2, 0), 10), 10) << std::endl;
}
Definition: chrono.h:14
Definition: geometry.h:13
Definition: animation.cpp:3
Definition: mapping.h:19
Definition: geometry.h:23

See the complete example below for the complete implementation and more details about the output.

Template Parameters
Implemfinal Function implementation (CRTP scheme)
Rbase::Function return type (fundamental type)
Argsargument types (fundamental types returned by other functions)
Examples
pixled/function/function.cpp.

Member Typedef Documentation

◆ Type

template<typename Implem , typename R , typename... Args>
using pixled::Function< Implem, R, Args >::Type = typename base::Function<R>::Type

Return type of this Function.

Constructor & Destructor Documentation

◆ Function()

template<typename Implem , typename R , typename... Args>
template<typename... Fcts>
pixled::Function< Implem, R, Args >::Function ( Fcts &&...  fcts)
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.

Template Parameters
FctsConstructor argument types (automatically deduced)
Parameters
fctsfunctionnal arguments

Member Function Documentation

◆ arg()

template<typename Implem , typename R , typename... Args>
template<std::size_t i>
const base::Function<typename std::tuple_element<i, decltype(args)>::type::Type>& pixled::Function< Implem, R, Args >::arg ( ) const
inline

Returns a reference to the functionnal argument at index i.

Indexing starts from 0, and follows the same order as specified in args.

Template Parameters
iargument index
Returns
functionnal argument at position i

◆ call()

template<typename Implem , typename R , typename... Args>
template<std::size_t i>
std::tuple_element<i, decltype(args)>::type::Type pixled::Function< Implem, R, Args >::call ( led  l,
time  t 
) const
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.

Template Parameters
iargument index
Parameters
lled
ttime
Returns
result of the call to functionnal argument at position i with the specified parameters
See also
base::Function::operator()(point, time)

◆ copy()

template<typename Implem , typename R , typename... Args>
base::Function<R>* pixled::Function< Implem, R, Args >::copy ( ) const
inlineoverrideprotectedvirtual

Returns a dynamically allocated copy of this function.

Returns
copy of this function

Implements pixled::base::Function< R >.

Member Data Documentation

◆ args

template<typename Implem , typename R , typename... Args>
std::tuple<const FctWrapper<Args>...> pixled::Function< Implem, R, Args >::args
protected

Tuple containing functionnal arguments, that are likely to be call by the call operator implementation defined in Implem.

They also be accessed with arg() and call() operators.


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