Files
allwpilib/wpilibc/src/main/native/include/frc/event/EventLoop.h
Dustin Spicuzza 0190301e09 [wpilibc] Explicitly mark EventLoop as non-copyable/non-movable (#4579)
It's already not movable because m_bindings isn't copyable, but pybind11
isn't able to detect that
2022-11-07 09:30:03 -08:00

51 lines
1.1 KiB
C++

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <functional>
#include <vector>
#include <wpi/FunctionExtras.h>
namespace frc {
/** The loop polling BooleanEvent objects and executing the actions bound to
* them. */
class EventLoop {
public:
EventLoop();
EventLoop(const EventLoop&) = delete;
EventLoop& operator=(const EventLoop&) = delete;
/**
* Bind a new action to run whenever the condition is true.
*
* @param condition the condition to listen to.
* @param action the action to run.
*/
void Bind(std::function<bool()> condition,
wpi::unique_function<void()> action);
/**
* Poll all bindings.
*/
void Poll();
/**
* Clear all bindings.
*/
void Clear();
private:
struct Binding {
std::function<bool()> condition;
wpi::unique_function<void()> action;
void Poll();
};
std::vector<Binding> m_bindings;
};
} // namespace frc