FastLED 3.9.15
Loading...
Searching...
No Matches
callback.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/namespace.h"
4
5namespace fl {
6
12template<typename ...Args>
13class Callback {
14public:
15 Callback() = default;
16 // Member function constructor.
17 Callback(void* self, void (*callback)(void* self, Args... args)) : self(self), callback(callback) {}
18 // Free function constructor.
19 explicit Callback(void* (*callback)(Args... args)) : self(nullptr), callback((void (*)(void*, Args...))callback) {}
20 Callback(const Callback&) = default;
21 operator bool() const { return callback != nullptr; }
22 void operator()(Args... args) const { if (callback) callback(self, args...); }
23 void clear() { callback = nullptr; self = nullptr; }
24 bool operator==(const Callback& other) const { return self == other.self && callback == other.callback; }
25 bool operator!=(const Callback& other) const { return !(*this == other); }
26 Callback& operator=(const Callback& other) { self = other.self; callback = other.callback; return *this; }
27 Callback& operator=(void* (*other)(Args... args)) { self = nullptr; callback = (void (*)(void*, Args...))other; return *this; }
28 Callback& operator=(void (*other)(void* self, Args... args)) { self = nullptr; callback = other; return *this; }
29 // operator < for set/map
30 bool operator<(const Callback& other) const { return self < other.self || (self == other.self && callback < other.callback); }
31private:
32 void* self = nullptr;
33 void (*callback)(void* self, Args... args) = nullptr;
34};
35
36} // namespace fl
void clear()
Definition callback.h:23
Callback(const Callback &)=default
bool operator!=(const Callback &other) const
Definition callback.h:25
void(* callback)(void *self, Args... args)
Definition callback.h:33
void operator()(Args... args) const
Definition callback.h:22
Callback(void *self, void(*callback)(void *self, Args... args))
Definition callback.h:17
bool operator==(const Callback &other) const
Definition callback.h:24
Callback()=default
void * self
Definition callback.h:32
Callback(void *(*callback)(Args... args))
Definition callback.h:19
Callback & operator=(void *(*other)(Args... args))
Definition callback.h:27
bool operator<(const Callback &other) const
Definition callback.h:30
Callback & operator=(const Callback &other)
Definition callback.h:26
Callback & operator=(void(*other)(void *self, Args... args))
Definition callback.h:28
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16