mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add braces to C++ single-line loops and conditionals (NFC) (#2973)
This makes code easier to read and more consistent between C++ and Java. Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
@@ -17,7 +17,9 @@
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
Command::~Command() { CommandScheduler::GetInstance().Cancel(this); }
|
||||
Command::~Command() {
|
||||
CommandScheduler::GetInstance().Cancel(this);
|
||||
}
|
||||
|
||||
Command::Command(const Command& rhs) : ErrorBase(rhs) {}
|
||||
|
||||
@@ -83,13 +85,17 @@ PerpetualCommand Command::Perpetually() && {
|
||||
return PerpetualCommand(std::move(*this).TransferOwnership());
|
||||
}
|
||||
|
||||
ProxyScheduleCommand Command::AsProxy() { return ProxyScheduleCommand(this); }
|
||||
ProxyScheduleCommand Command::AsProxy() {
|
||||
return ProxyScheduleCommand(this);
|
||||
}
|
||||
|
||||
void Command::Schedule(bool interruptible) {
|
||||
CommandScheduler::GetInstance().Schedule(interruptible, this);
|
||||
}
|
||||
|
||||
void Command::Cancel() { CommandScheduler::GetInstance().Cancel(this); }
|
||||
void Command::Cancel() {
|
||||
CommandScheduler::GetInstance().Cancel(this);
|
||||
}
|
||||
|
||||
bool Command::IsScheduled() const {
|
||||
return CommandScheduler::GetInstance().IsScheduled(this);
|
||||
@@ -103,11 +109,17 @@ bool Command::HasRequirement(Subsystem* requirement) const {
|
||||
return hasRequirement;
|
||||
}
|
||||
|
||||
std::string Command::GetName() const { return GetTypeName(*this); }
|
||||
std::string Command::GetName() const {
|
||||
return GetTypeName(*this);
|
||||
}
|
||||
|
||||
bool Command::IsGrouped() const { return m_isGrouped; }
|
||||
bool Command::IsGrouped() const {
|
||||
return m_isGrouped;
|
||||
}
|
||||
|
||||
void Command::SetGrouped(bool grouped) { m_isGrouped = grouped; }
|
||||
void Command::SetGrouped(bool grouped) {
|
||||
m_isGrouped = grouped;
|
||||
}
|
||||
|
||||
namespace frc2 {
|
||||
bool RequirementsDisjoint(Command* first, Command* second) {
|
||||
|
||||
@@ -99,7 +99,9 @@ void CommandScheduler::AddButton(wpi::unique_function<void()> button) {
|
||||
m_impl->buttons.emplace_back(std::move(button));
|
||||
}
|
||||
|
||||
void CommandScheduler::ClearButtons() { m_impl->buttons.clear(); }
|
||||
void CommandScheduler::ClearButtons() {
|
||||
m_impl->buttons.clear();
|
||||
}
|
||||
|
||||
void CommandScheduler::Schedule(bool interruptible, Command* command) {
|
||||
if (m_impl->inRunLoop) {
|
||||
@@ -152,7 +154,9 @@ void CommandScheduler::Schedule(bool interruptible, Command* command) {
|
||||
}
|
||||
}
|
||||
|
||||
void CommandScheduler::Schedule(Command* command) { Schedule(true, command); }
|
||||
void CommandScheduler::Schedule(Command* command) {
|
||||
Schedule(true, command);
|
||||
}
|
||||
|
||||
void CommandScheduler::Schedule(bool interruptible,
|
||||
wpi::ArrayRef<Command*> commands) {
|
||||
@@ -314,7 +318,9 @@ void CommandScheduler::Cancel(Command* command) {
|
||||
}
|
||||
|
||||
auto find = m_impl->scheduledCommands.find(command);
|
||||
if (find == m_impl->scheduledCommands.end()) return;
|
||||
if (find == m_impl->scheduledCommands.end()) {
|
||||
return;
|
||||
}
|
||||
command->End(true);
|
||||
for (auto&& action : m_impl->interruptActions) {
|
||||
action(*command);
|
||||
@@ -390,9 +396,13 @@ Command* CommandScheduler::Requiring(const Subsystem* subsystem) const {
|
||||
}
|
||||
}
|
||||
|
||||
void CommandScheduler::Disable() { m_impl->disabled = true; }
|
||||
void CommandScheduler::Disable() {
|
||||
m_impl->disabled = true;
|
||||
}
|
||||
|
||||
void CommandScheduler::Enable() { m_impl->disabled = false; }
|
||||
void CommandScheduler::Enable() {
|
||||
m_impl->disabled = false;
|
||||
}
|
||||
|
||||
void CommandScheduler::OnCommandInitialize(Action action) {
|
||||
m_impl->initActions.emplace_back(std::move(action));
|
||||
|
||||
@@ -16,7 +16,9 @@ CommandState::CommandState(bool interruptible)
|
||||
void CommandState::StartTiming() {
|
||||
m_startTime = frc::Timer::GetFPGATimestamp();
|
||||
}
|
||||
void CommandState::StartRunning() { m_startTime = -1; }
|
||||
void CommandState::StartRunning() {
|
||||
m_startTime = -1;
|
||||
}
|
||||
double CommandState::TimeSinceInitialized() const {
|
||||
return m_startTime != -1 ? frc::Timer::GetFPGATimestamp() - m_startTime : -1;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,9 @@ void ConditionalCommand::Initialize() {
|
||||
m_selectedCommand->Initialize();
|
||||
}
|
||||
|
||||
void ConditionalCommand::Execute() { m_selectedCommand->Execute(); }
|
||||
void ConditionalCommand::Execute() {
|
||||
m_selectedCommand->Execute();
|
||||
}
|
||||
|
||||
void ConditionalCommand::End(bool interrupted) {
|
||||
m_selectedCommand->End(interrupted);
|
||||
@@ -46,4 +48,6 @@ bool ConditionalCommand::IsFinished() {
|
||||
return m_selectedCommand->IsFinished();
|
||||
}
|
||||
|
||||
bool ConditionalCommand::RunsWhenDisabled() const { return m_runsWhenDisabled; }
|
||||
bool ConditionalCommand::RunsWhenDisabled() const {
|
||||
return m_runsWhenDisabled;
|
||||
}
|
||||
|
||||
@@ -29,10 +29,18 @@ FunctionalCommand::FunctionalCommand(std::function<void()> onInit,
|
||||
AddRequirements(requirements);
|
||||
}
|
||||
|
||||
void FunctionalCommand::Initialize() { m_onInit(); }
|
||||
void FunctionalCommand::Initialize() {
|
||||
m_onInit();
|
||||
}
|
||||
|
||||
void FunctionalCommand::Execute() { m_onExecute(); }
|
||||
void FunctionalCommand::Execute() {
|
||||
m_onExecute();
|
||||
}
|
||||
|
||||
void FunctionalCommand::End(bool interrupted) { m_onEnd(interrupted); }
|
||||
void FunctionalCommand::End(bool interrupted) {
|
||||
m_onEnd(interrupted);
|
||||
}
|
||||
|
||||
bool FunctionalCommand::IsFinished() { return m_isFinished(); }
|
||||
bool FunctionalCommand::IsFinished() {
|
||||
return m_isFinished();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@ InstantCommand::InstantCommand(std::function<void()> toRun,
|
||||
|
||||
InstantCommand::InstantCommand() : m_toRun{[] {}} {}
|
||||
|
||||
void InstantCommand::Initialize() { m_toRun(); }
|
||||
void InstantCommand::Initialize() {
|
||||
m_toRun();
|
||||
}
|
||||
|
||||
bool InstantCommand::IsFinished() { return true; }
|
||||
bool InstantCommand::IsFinished() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -335,7 +335,9 @@ void MecanumControllerCommand::Execute() {
|
||||
}
|
||||
}
|
||||
|
||||
void MecanumControllerCommand::End(bool interrupted) { m_timer.Stop(); }
|
||||
void MecanumControllerCommand::End(bool interrupted) {
|
||||
m_timer.Stop();
|
||||
}
|
||||
|
||||
bool MecanumControllerCommand::IsFinished() {
|
||||
return m_timer.HasElapsed(m_trajectory.TotalTime());
|
||||
|
||||
@@ -32,6 +32,10 @@ NotifierCommand::NotifierCommand(const NotifierCommand& other)
|
||||
m_notifier(frc::Notifier(other.m_toRun)),
|
||||
m_period(other.m_period) {}
|
||||
|
||||
void NotifierCommand::Initialize() { m_notifier.StartPeriodic(m_period); }
|
||||
void NotifierCommand::Initialize() {
|
||||
m_notifier.StartPeriodic(m_period);
|
||||
}
|
||||
|
||||
void NotifierCommand::End(bool interrupted) { m_notifier.Stop(); }
|
||||
void NotifierCommand::End(bool interrupted) {
|
||||
m_notifier.Stop();
|
||||
}
|
||||
|
||||
@@ -46,12 +46,18 @@ PIDCommand::PIDCommand(PIDController controller,
|
||||
controller, measurementSource, [setpoint] { return setpoint; },
|
||||
useOutput, requirements) {}
|
||||
|
||||
void PIDCommand::Initialize() { m_controller.Reset(); }
|
||||
void PIDCommand::Initialize() {
|
||||
m_controller.Reset();
|
||||
}
|
||||
|
||||
void PIDCommand::Execute() {
|
||||
m_useOutput(m_controller.Calculate(m_measurement(), m_setpoint()));
|
||||
}
|
||||
|
||||
void PIDCommand::End(bool interrupted) { m_useOutput(0); }
|
||||
void PIDCommand::End(bool interrupted) {
|
||||
m_useOutput(0);
|
||||
}
|
||||
|
||||
PIDController& PIDCommand::GetController() { return m_controller; }
|
||||
PIDController& PIDCommand::GetController() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,13 @@ void PIDSubsystem::Periodic() {
|
||||
}
|
||||
}
|
||||
|
||||
void PIDSubsystem::SetSetpoint(double setpoint) { m_setpoint = setpoint; }
|
||||
void PIDSubsystem::SetSetpoint(double setpoint) {
|
||||
m_setpoint = setpoint;
|
||||
}
|
||||
|
||||
double PIDSubsystem::GetSetpoint() const { return m_setpoint; }
|
||||
double PIDSubsystem::GetSetpoint() const {
|
||||
return m_setpoint;
|
||||
}
|
||||
|
||||
void PIDSubsystem::Enable() {
|
||||
m_controller.Reset();
|
||||
@@ -32,6 +36,10 @@ void PIDSubsystem::Disable() {
|
||||
m_enabled = false;
|
||||
}
|
||||
|
||||
bool PIDSubsystem::IsEnabled() { return m_enabled; }
|
||||
bool PIDSubsystem::IsEnabled() {
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
PIDController& PIDSubsystem::GetController() { return m_controller; }
|
||||
PIDController& PIDSubsystem::GetController() {
|
||||
return m_controller;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ void ParallelCommandGroup::Initialize() {
|
||||
|
||||
void ParallelCommandGroup::Execute() {
|
||||
for (auto& commandRunning : m_commands) {
|
||||
if (!commandRunning.second) continue;
|
||||
if (!commandRunning.second) {
|
||||
continue;
|
||||
}
|
||||
commandRunning.first->Execute();
|
||||
if (commandRunning.first->IsFinished()) {
|
||||
commandRunning.first->End(false);
|
||||
@@ -43,7 +45,9 @@ void ParallelCommandGroup::End(bool interrupted) {
|
||||
|
||||
bool ParallelCommandGroup::IsFinished() {
|
||||
for (auto& command : m_commands) {
|
||||
if (command.second) return false;
|
||||
if (command.second) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -55,7 +59,9 @@ bool ParallelCommandGroup::RunsWhenDisabled() const {
|
||||
void ParallelCommandGroup::AddCommands(
|
||||
std::vector<std::unique_ptr<Command>>&& commands) {
|
||||
for (auto&& command : commands) {
|
||||
if (!RequireUngrouped(*command)) return;
|
||||
if (!RequireUngrouped(*command)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
|
||||
@@ -23,7 +23,9 @@ void ParallelDeadlineGroup::Initialize() {
|
||||
|
||||
void ParallelDeadlineGroup::Execute() {
|
||||
for (auto& commandRunning : m_commands) {
|
||||
if (!commandRunning.second) continue;
|
||||
if (!commandRunning.second) {
|
||||
continue;
|
||||
}
|
||||
commandRunning.first->Execute();
|
||||
if (commandRunning.first->IsFinished()) {
|
||||
commandRunning.first->End(false);
|
||||
@@ -43,7 +45,9 @@ void ParallelDeadlineGroup::End(bool interrupted) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ParallelDeadlineGroup::IsFinished() { return m_finished; }
|
||||
bool ParallelDeadlineGroup::IsFinished() {
|
||||
return m_finished;
|
||||
}
|
||||
|
||||
bool ParallelDeadlineGroup::RunsWhenDisabled() const {
|
||||
return m_runWhenDisabled;
|
||||
|
||||
@@ -35,9 +35,13 @@ void ParallelRaceGroup::End(bool interrupted) {
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
bool ParallelRaceGroup::IsFinished() { return m_finished; }
|
||||
bool ParallelRaceGroup::IsFinished() {
|
||||
return m_finished;
|
||||
}
|
||||
|
||||
bool ParallelRaceGroup::RunsWhenDisabled() const { return m_runWhenDisabled; }
|
||||
bool ParallelRaceGroup::RunsWhenDisabled() const {
|
||||
return m_runWhenDisabled;
|
||||
}
|
||||
|
||||
void ParallelRaceGroup::AddCommands(
|
||||
std::vector<std::unique_ptr<Command>>&& commands) {
|
||||
|
||||
@@ -15,8 +15,14 @@ PerpetualCommand::PerpetualCommand(std::unique_ptr<Command>&& command) {
|
||||
AddRequirements(m_command->GetRequirements());
|
||||
}
|
||||
|
||||
void PerpetualCommand::Initialize() { m_command->Initialize(); }
|
||||
void PerpetualCommand::Initialize() {
|
||||
m_command->Initialize();
|
||||
}
|
||||
|
||||
void PerpetualCommand::Execute() { m_command->Execute(); }
|
||||
void PerpetualCommand::Execute() {
|
||||
m_command->Execute();
|
||||
}
|
||||
|
||||
void PerpetualCommand::End(bool interrupted) { m_command->End(interrupted); }
|
||||
void PerpetualCommand::End(bool interrupted) {
|
||||
m_command->End(interrupted);
|
||||
}
|
||||
|
||||
@@ -12,4 +12,6 @@ PrintCommand::PrintCommand(const wpi::Twine& message)
|
||||
: CommandHelper{[str = message.str()] { wpi::outs() << str << "\n"; }, {}} {
|
||||
}
|
||||
|
||||
bool PrintCommand::RunsWhenDisabled() const { return true; }
|
||||
bool PrintCommand::RunsWhenDisabled() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,4 +31,6 @@ void ProxyScheduleCommand::Execute() {
|
||||
}
|
||||
}
|
||||
|
||||
bool ProxyScheduleCommand::IsFinished() { return m_finished; }
|
||||
bool ProxyScheduleCommand::IsFinished() {
|
||||
return m_finished;
|
||||
}
|
||||
|
||||
@@ -102,10 +102,11 @@ void RamseteCommand::Execute() {
|
||||
auto dt = curTime - m_prevTime;
|
||||
|
||||
if (m_prevTime < 0_s) {
|
||||
if (m_usePID)
|
||||
if (m_usePID) {
|
||||
m_outputVolts(0_V, 0_V);
|
||||
else
|
||||
} else {
|
||||
m_outputVel(0_mps, 0_mps);
|
||||
}
|
||||
|
||||
m_prevTime = curTime;
|
||||
return;
|
||||
@@ -141,7 +142,9 @@ void RamseteCommand::Execute() {
|
||||
m_prevTime = curTime;
|
||||
}
|
||||
|
||||
void RamseteCommand::End(bool interrupted) { m_timer.Stop(); }
|
||||
void RamseteCommand::End(bool interrupted) {
|
||||
m_timer.Stop();
|
||||
}
|
||||
|
||||
bool RamseteCommand::IsFinished() {
|
||||
return m_timer.HasElapsed(m_trajectory.TotalTime());
|
||||
|
||||
@@ -18,4 +18,6 @@ RunCommand::RunCommand(std::function<void()> toRun,
|
||||
AddRequirements(requirements);
|
||||
}
|
||||
|
||||
void RunCommand::Execute() { m_toRun(); }
|
||||
void RunCommand::Execute() {
|
||||
m_toRun();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ void ScheduleCommand::Initialize() {
|
||||
}
|
||||
}
|
||||
|
||||
bool ScheduleCommand::IsFinished() { return true; }
|
||||
bool ScheduleCommand::IsFinished() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScheduleCommand::RunsWhenDisabled() const { return true; }
|
||||
bool ScheduleCommand::RunsWhenDisabled() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ void SequentialCommandGroup::Initialize() {
|
||||
}
|
||||
|
||||
void SequentialCommandGroup::Execute() {
|
||||
if (m_commands.empty()) return;
|
||||
if (m_commands.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& currentCommand = m_commands[m_currentCommandIndex];
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ StartEndCommand::StartEndCommand(const StartEndCommand& other)
|
||||
m_onEnd = other.m_onEnd;
|
||||
}
|
||||
|
||||
void StartEndCommand::Initialize() { m_onInit(); }
|
||||
void StartEndCommand::Initialize() {
|
||||
m_onInit();
|
||||
}
|
||||
|
||||
void StartEndCommand::End(bool interrupted) { m_onEnd(); }
|
||||
void StartEndCommand::End(bool interrupted) {
|
||||
m_onEnd();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ void SubsystemBase::InitSendable(frc::SendableBuilder& builder) {
|
||||
".default",
|
||||
[this]() -> std::string {
|
||||
auto command = GetDefaultCommand();
|
||||
if (command == nullptr) return "none";
|
||||
if (command == nullptr) {
|
||||
return "none";
|
||||
}
|
||||
return command->GetName();
|
||||
},
|
||||
nullptr);
|
||||
@@ -37,7 +39,9 @@ void SubsystemBase::InitSendable(frc::SendableBuilder& builder) {
|
||||
".command",
|
||||
[this]() -> std::string {
|
||||
auto command = GetCurrentCommand();
|
||||
if (command == nullptr) return "none";
|
||||
if (command == nullptr) {
|
||||
return "none";
|
||||
}
|
||||
return command->GetName();
|
||||
},
|
||||
nullptr);
|
||||
|
||||
@@ -16,8 +16,14 @@ void WaitCommand::Initialize() {
|
||||
m_timer.Start();
|
||||
}
|
||||
|
||||
void WaitCommand::End(bool interrupted) { m_timer.Stop(); }
|
||||
void WaitCommand::End(bool interrupted) {
|
||||
m_timer.Stop();
|
||||
}
|
||||
|
||||
bool WaitCommand::IsFinished() { return m_timer.HasElapsed(m_duration); }
|
||||
bool WaitCommand::IsFinished() {
|
||||
return m_timer.HasElapsed(m_duration);
|
||||
}
|
||||
|
||||
bool WaitCommand::RunsWhenDisabled() const { return true; }
|
||||
bool WaitCommand::RunsWhenDisabled() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@ WaitUntilCommand::WaitUntilCommand(std::function<bool()> condition)
|
||||
WaitUntilCommand::WaitUntilCommand(units::second_t time)
|
||||
: m_condition{[=] { return Timer::GetMatchTime() - time > 0_s; }} {}
|
||||
|
||||
bool WaitUntilCommand::IsFinished() { return m_condition(); }
|
||||
bool WaitUntilCommand::IsFinished() {
|
||||
return m_condition();
|
||||
}
|
||||
|
||||
bool WaitUntilCommand::RunsWhenDisabled() const { return true; }
|
||||
bool WaitUntilCommand::RunsWhenDisabled() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user