FastLED 3.9.15
Loading...
Searching...
No Matches
function_list.h
Go to the documentation of this file.
1#pragma once
2#include "fl/function.h"
3#include "fl/pair.h"
4#include "fl/vector.h"
5
6namespace fl {
7
8template <typename FunctionType> class FunctionListBase {
9 protected:
11 int mCounter = 0;
12
13 public:
14 FunctionListBase() = default;
15 ~FunctionListBase() = default;
16
17 int add(FunctionType function) {
18 int id = mCounter++;
20 mFunctions.push_back(entry);
21 return id;
22 }
23
24 void remove(int id) {
25 for (int i = mFunctions.size() - 1; i >= 0; --i) {
26 if (mFunctions[i].first == id) {
27 mFunctions.erase(mFunctions.begin() + i);
28 }
29 }
30 }
31
32 void clear() { mFunctions.clear(); }
33};
34
35template <typename... Args>
36class FunctionList : public FunctionListBase<function<void(Args...)>> {
37 public:
38 void invoke(Args... args) {
39 for (const auto &pair : this->mFunctions) {
40 auto &function = pair.second;
41 function(args...);
42 }
43 }
44};
45
46template <>
47class FunctionList<void> : public FunctionListBase<function<void()>> {
48 public:
49 void invoke() {
50 for (const auto &pair : this->mFunctions) {
51 auto &function = pair.second;
52 function();
53 }
54 }
55};
56
57} // namespace fl
void invoke(Args... args)
~FunctionListBase()=default
FunctionListBase()=default
int add(FunctionType function)
fl::vector< pair< int, FunctionType > > mFunctions
Pair< Key, Value > pair
Definition pair.h:13
HeapVector< T > vector
Definition vector.h:1028
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16