Skip to content

Commit 3851ba3

Browse files
authored
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).
1 parent 22cd768 commit 3851ba3

24 files changed

+171
-58
lines changed

cpp/frc2/command/Command.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
using namespace frc2;
1919

20-
Command::~Command() { CommandScheduler::GetInstance().Cancel(this); }
20+
Command::~Command() {
21+
CommandScheduler::GetInstance().Cancel(this);
22+
}
2123

2224
Command::Command(const Command& rhs) : ErrorBase(rhs) {}
2325

@@ -83,13 +85,17 @@ PerpetualCommand Command::Perpetually() && {
8385
return PerpetualCommand(std::move(*this).TransferOwnership());
8486
}
8587

86-
ProxyScheduleCommand Command::AsProxy() { return ProxyScheduleCommand(this); }
88+
ProxyScheduleCommand Command::AsProxy() {
89+
return ProxyScheduleCommand(this);
90+
}
8791

8892
void Command::Schedule(bool interruptible) {
8993
CommandScheduler::GetInstance().Schedule(interruptible, this);
9094
}
9195

92-
void Command::Cancel() { CommandScheduler::GetInstance().Cancel(this); }
96+
void Command::Cancel() {
97+
CommandScheduler::GetInstance().Cancel(this);
98+
}
9399

94100
bool Command::IsScheduled() const {
95101
return CommandScheduler::GetInstance().IsScheduled(this);
@@ -103,11 +109,17 @@ bool Command::HasRequirement(Subsystem* requirement) const {
103109
return hasRequirement;
104110
}
105111

106-
std::string Command::GetName() const { return GetTypeName(*this); }
112+
std::string Command::GetName() const {
113+
return GetTypeName(*this);
114+
}
107115

108-
bool Command::IsGrouped() const { return m_isGrouped; }
116+
bool Command::IsGrouped() const {
117+
return m_isGrouped;
118+
}
109119

110-
void Command::SetGrouped(bool grouped) { m_isGrouped = grouped; }
120+
void Command::SetGrouped(bool grouped) {
121+
m_isGrouped = grouped;
122+
}
111123

112124
namespace frc2 {
113125
bool RequirementsDisjoint(Command* first, Command* second) {

cpp/frc2/command/CommandScheduler.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ void CommandScheduler::AddButton(wpi::unique_function<void()> button) {
9999
m_impl->buttons.emplace_back(std::move(button));
100100
}
101101

102-
void CommandScheduler::ClearButtons() { m_impl->buttons.clear(); }
102+
void CommandScheduler::ClearButtons() {
103+
m_impl->buttons.clear();
104+
}
103105

104106
void CommandScheduler::Schedule(bool interruptible, Command* command) {
105107
if (m_impl->inRunLoop) {
@@ -152,7 +154,9 @@ void CommandScheduler::Schedule(bool interruptible, Command* command) {
152154
}
153155
}
154156

155-
void CommandScheduler::Schedule(Command* command) { Schedule(true, command); }
157+
void CommandScheduler::Schedule(Command* command) {
158+
Schedule(true, command);
159+
}
156160

157161
void CommandScheduler::Schedule(bool interruptible,
158162
wpi::ArrayRef<Command*> commands) {
@@ -314,7 +318,9 @@ void CommandScheduler::Cancel(Command* command) {
314318
}
315319

316320
auto find = m_impl->scheduledCommands.find(command);
317-
if (find == m_impl->scheduledCommands.end()) return;
321+
if (find == m_impl->scheduledCommands.end()) {
322+
return;
323+
}
318324
command->End(true);
319325
for (auto&& action : m_impl->interruptActions) {
320326
action(*command);
@@ -390,9 +396,13 @@ Command* CommandScheduler::Requiring(const Subsystem* subsystem) const {
390396
}
391397
}
392398

393-
void CommandScheduler::Disable() { m_impl->disabled = true; }
399+
void CommandScheduler::Disable() {
400+
m_impl->disabled = true;
401+
}
394402

395-
void CommandScheduler::Enable() { m_impl->disabled = false; }
403+
void CommandScheduler::Enable() {
404+
m_impl->disabled = false;
405+
}
396406

397407
void CommandScheduler::OnCommandInitialize(Action action) {
398408
m_impl->initActions.emplace_back(std::move(action));

cpp/frc2/command/CommandState.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ CommandState::CommandState(bool interruptible)
1616
void CommandState::StartTiming() {
1717
m_startTime = frc::Timer::GetFPGATimestamp();
1818
}
19-
void CommandState::StartRunning() { m_startTime = -1; }
19+
void CommandState::StartRunning() {
20+
m_startTime = -1;
21+
}
2022
double CommandState::TimeSinceInitialized() const {
2123
return m_startTime != -1 ? frc::Timer::GetFPGATimestamp() - m_startTime : -1;
2224
}

cpp/frc2/command/ConditionalCommand.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ void ConditionalCommand::Initialize() {
3636
m_selectedCommand->Initialize();
3737
}
3838

39-
void ConditionalCommand::Execute() { m_selectedCommand->Execute(); }
39+
void ConditionalCommand::Execute() {
40+
m_selectedCommand->Execute();
41+
}
4042

4143
void ConditionalCommand::End(bool interrupted) {
4244
m_selectedCommand->End(interrupted);
@@ -46,4 +48,6 @@ bool ConditionalCommand::IsFinished() {
4648
return m_selectedCommand->IsFinished();
4749
}
4850

49-
bool ConditionalCommand::RunsWhenDisabled() const { return m_runsWhenDisabled; }
51+
bool ConditionalCommand::RunsWhenDisabled() const {
52+
return m_runsWhenDisabled;
53+
}

cpp/frc2/command/FunctionalCommand.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ FunctionalCommand::FunctionalCommand(std::function<void()> onInit,
2929
AddRequirements(requirements);
3030
}
3131

32-
void FunctionalCommand::Initialize() { m_onInit(); }
32+
void FunctionalCommand::Initialize() {
33+
m_onInit();
34+
}
3335

34-
void FunctionalCommand::Execute() { m_onExecute(); }
36+
void FunctionalCommand::Execute() {
37+
m_onExecute();
38+
}
3539

36-
void FunctionalCommand::End(bool interrupted) { m_onEnd(interrupted); }
40+
void FunctionalCommand::End(bool interrupted) {
41+
m_onEnd(interrupted);
42+
}
3743

38-
bool FunctionalCommand::IsFinished() { return m_isFinished(); }
44+
bool FunctionalCommand::IsFinished() {
45+
return m_isFinished();
46+
}

cpp/frc2/command/InstantCommand.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ InstantCommand::InstantCommand(std::function<void()> toRun,
2020

2121
InstantCommand::InstantCommand() : m_toRun{[] {}} {}
2222

23-
void InstantCommand::Initialize() { m_toRun(); }
23+
void InstantCommand::Initialize() {
24+
m_toRun();
25+
}
2426

25-
bool InstantCommand::IsFinished() { return true; }
27+
bool InstantCommand::IsFinished() {
28+
return true;
29+
}

cpp/frc2/command/MecanumControllerCommand.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ void MecanumControllerCommand::Execute() {
335335
}
336336
}
337337

338-
void MecanumControllerCommand::End(bool interrupted) { m_timer.Stop(); }
338+
void MecanumControllerCommand::End(bool interrupted) {
339+
m_timer.Stop();
340+
}
339341

340342
bool MecanumControllerCommand::IsFinished() {
341343
return m_timer.HasElapsed(m_trajectory.TotalTime());

cpp/frc2/command/NotifierCommand.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ NotifierCommand::NotifierCommand(const NotifierCommand& other)
3232
m_notifier(frc::Notifier(other.m_toRun)),
3333
m_period(other.m_period) {}
3434

35-
void NotifierCommand::Initialize() { m_notifier.StartPeriodic(m_period); }
35+
void NotifierCommand::Initialize() {
36+
m_notifier.StartPeriodic(m_period);
37+
}
3638

37-
void NotifierCommand::End(bool interrupted) { m_notifier.Stop(); }
39+
void NotifierCommand::End(bool interrupted) {
40+
m_notifier.Stop();
41+
}

cpp/frc2/command/PIDCommand.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ PIDCommand::PIDCommand(PIDController controller,
4646
controller, measurementSource, [setpoint] { return setpoint; },
4747
useOutput, requirements) {}
4848

49-
void PIDCommand::Initialize() { m_controller.Reset(); }
49+
void PIDCommand::Initialize() {
50+
m_controller.Reset();
51+
}
5052

5153
void PIDCommand::Execute() {
5254
m_useOutput(m_controller.Calculate(m_measurement(), m_setpoint()));
5355
}
5456

55-
void PIDCommand::End(bool interrupted) { m_useOutput(0); }
57+
void PIDCommand::End(bool interrupted) {
58+
m_useOutput(0);
59+
}
5660

57-
PIDController& PIDCommand::GetController() { return m_controller; }
61+
PIDController& PIDCommand::GetController() {
62+
return m_controller;
63+
}

cpp/frc2/command/PIDSubsystem.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ void PIDSubsystem::Periodic() {
1818
}
1919
}
2020

21-
void PIDSubsystem::SetSetpoint(double setpoint) { m_setpoint = setpoint; }
21+
void PIDSubsystem::SetSetpoint(double setpoint) {
22+
m_setpoint = setpoint;
23+
}
2224

23-
double PIDSubsystem::GetSetpoint() const { return m_setpoint; }
25+
double PIDSubsystem::GetSetpoint() const {
26+
return m_setpoint;
27+
}
2428

2529
void PIDSubsystem::Enable() {
2630
m_controller.Reset();
@@ -32,6 +36,10 @@ void PIDSubsystem::Disable() {
3236
m_enabled = false;
3337
}
3438

35-
bool PIDSubsystem::IsEnabled() { return m_enabled; }
39+
bool PIDSubsystem::IsEnabled() {
40+
return m_enabled;
41+
}
3642

37-
PIDController& PIDSubsystem::GetController() { return m_controller; }
43+
PIDController& PIDSubsystem::GetController() {
44+
return m_controller;
45+
}

0 commit comments

Comments
 (0)