33 lines
980 B
C++
33 lines
980 B
C++
#ifndef ACTION_H
|
|
#define ACTION_H
|
|
|
|
#include "Arduino.h"
|
|
#include "functional"
|
|
#include "StreamEvent.h"
|
|
|
|
template <typename T>
|
|
class Action {
|
|
public:
|
|
Action(function<bool(StreamEvent*)> _funcEventMatchesAction, function<T*(StreamEvent*)> _funcInvokeAction,
|
|
function<void(Print*)> _funcDescribeAction) : funcEventMatchesAction(_funcEventMatchesAction),
|
|
funcInvokeAction(_funcInvokeAction), funcDescribeAction(_funcDescribeAction) {}
|
|
|
|
bool eventMatchesAction(StreamEvent* event) {
|
|
return funcEventMatchesAction(event);
|
|
}
|
|
|
|
void describeAction(Print* printStream) {
|
|
funcDescribeAction(printStream);
|
|
}
|
|
|
|
T* invokeAction(StreamEvent* event) {
|
|
return funcInvokeAction(event);
|
|
}
|
|
|
|
private:
|
|
function<bool(StreamEvent*)> funcEventMatchesAction;
|
|
function<T*(StreamEvent*)> funcInvokeAction;
|
|
function<void(Print*)> funcDescribeAction;
|
|
};
|
|
|
|
#endif |