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:
Peter Johnson
2020-12-28 12:58:06 -08:00
committed by GitHub
parent 0291a3ff56
commit 2aed432b4b
634 changed files with 10716 additions and 3938 deletions

View File

@@ -31,8 +31,9 @@ Command::Command(Subsystem& subsystem) : Command("", -1.0) {
Command::Command(const wpi::Twine& name, double timeout) {
// We use -1.0 to indicate no timeout.
if (timeout < 0.0 && timeout != -1.0)
if (timeout < 0.0 && timeout != -1.0) {
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
}
m_timeout = timeout;
@@ -61,37 +62,45 @@ Command::Command(const wpi::Twine& name, double timeout, Subsystem& subsystem)
}
double Command::TimeSinceInitialized() const {
if (m_startTime < 0.0)
if (m_startTime < 0.0) {
return 0.0;
else
} else {
return Timer::GetFPGATimestamp() - m_startTime;
}
}
void Command::Requires(Subsystem* subsystem) {
if (!AssertUnlocked("Can not add new requirement to command")) return;
if (!AssertUnlocked("Can not add new requirement to command")) {
return;
}
if (subsystem != nullptr)
if (subsystem != nullptr) {
m_requirements.insert(subsystem);
else
} else {
wpi_setWPIErrorWithContext(NullParameter, "subsystem");
}
}
void Command::Start() {
LockChanges();
if (m_parent != nullptr)
if (m_parent != nullptr) {
wpi_setWPIErrorWithContext(
CommandIllegalUse,
"Can not start a command that is part of a command group");
}
m_completed = false;
Scheduler::GetInstance()->AddCommand(this);
}
bool Command::Run() {
if (!m_runWhenDisabled && m_parent == nullptr && RobotState::IsDisabled())
if (!m_runWhenDisabled && m_parent == nullptr && RobotState::IsDisabled()) {
Cancel();
}
if (IsCanceled()) return false;
if (IsCanceled()) {
return false;
}
if (!m_initialized) {
m_initialized = true;
@@ -105,23 +114,34 @@ bool Command::Run() {
}
void Command::Cancel() {
if (m_parent != nullptr)
if (m_parent != nullptr) {
wpi_setWPIErrorWithContext(
CommandIllegalUse,
"Can not cancel a command that is part of a command group");
}
_Cancel();
}
bool Command::IsRunning() const { return m_running; }
bool Command::IsRunning() const {
return m_running;
}
bool Command::IsInitialized() const { return m_initialized; }
bool Command::IsInitialized() const {
return m_initialized;
}
bool Command::IsCompleted() const { return m_completed; }
bool Command::IsCompleted() const {
return m_completed;
}
bool Command::IsCanceled() const { return m_canceled; }
bool Command::IsCanceled() const {
return m_canceled;
}
bool Command::IsInterruptible() const { return m_interruptible; }
bool Command::IsInterruptible() const {
return m_interruptible;
}
void Command::SetInterruptible(bool interruptible) {
m_interruptible = interruptible;
@@ -135,19 +155,28 @@ const Command::SubsystemSet& Command::GetRequirements() const {
return m_requirements;
}
CommandGroup* Command::GetGroup() const { return m_parent; }
CommandGroup* Command::GetGroup() const {
return m_parent;
}
void Command::SetRunWhenDisabled(bool run) { m_runWhenDisabled = run; }
void Command::SetRunWhenDisabled(bool run) {
m_runWhenDisabled = run;
}
bool Command::WillRunWhenDisabled() const { return m_runWhenDisabled; }
bool Command::WillRunWhenDisabled() const {
return m_runWhenDisabled;
}
int Command::GetID() const { return m_commandID; }
int Command::GetID() const {
return m_commandID;
}
void Command::SetTimeout(double timeout) {
if (timeout < 0.0)
if (timeout < 0.0) {
wpi_setWPIErrorWithContext(ParameterOutOfRange, "timeout < 0.0");
else
} else {
m_timeout = timeout;
}
}
bool Command::IsTimedOut() const {
@@ -177,9 +206,13 @@ void Command::SetParent(CommandGroup* parent) {
}
}
bool Command::IsParented() const { return m_parent != nullptr; }
bool Command::IsParented() const {
return m_parent != nullptr;
}
void Command::ClearRequirements() { m_requirements.clear(); }
void Command::ClearRequirements() {
m_requirements.clear();
}
void Command::Initialize() {}
@@ -187,21 +220,33 @@ void Command::Execute() {}
void Command::End() {}
void Command::Interrupted() { End(); }
void Command::Interrupted() {
End();
}
void Command::_Initialize() { m_completed = false; }
void Command::_Initialize() {
m_completed = false;
}
void Command::_Interrupted() { m_completed = true; }
void Command::_Interrupted() {
m_completed = true;
}
void Command::_Execute() {}
void Command::_End() { m_completed = true; }
void Command::_Cancel() {
if (IsRunning()) m_canceled = true;
void Command::_End() {
m_completed = true;
}
void Command::LockChanges() { m_locked = true; }
void Command::_Cancel() {
if (IsRunning()) {
m_canceled = true;
}
}
void Command::LockChanges() {
m_locked = true;
}
void Command::Removed() {
if (m_initialized) {
@@ -225,7 +270,9 @@ void Command::StartRunning() {
m_completed = false;
}
void Command::StartTiming() { m_startTime = Timer::GetFPGATimestamp(); }
void Command::StartTiming() {
m_startTime = Timer::GetFPGATimestamp();
}
std::string Command::GetName() const {
return SendableRegistry::GetInstance().GetName(this);
@@ -252,9 +299,13 @@ void Command::InitSendable(SendableBuilder& builder) {
"running", [=]() { return IsRunning(); },
[=](bool value) {
if (value) {
if (!IsRunning()) Start();
if (!IsRunning()) {
Start();
}
} else {
if (IsRunning()) Cancel();
if (IsRunning()) {
Cancel();
}
}
});
builder.AddBooleanProperty(