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

@@ -82,7 +82,9 @@ void LiveWindow::DisableAllTelemetry() {
std::scoped_lock lock(m_impl->mutex);
m_impl->telemetryEnabled = false;
m_impl->registry.ForeachLiveWindow(m_impl->dataHandle, [&](auto& cbdata) {
if (!cbdata.data) cbdata.data = std::make_shared<Impl::Component>();
if (!cbdata.data) {
cbdata.data = std::make_shared<Impl::Component>();
}
std::static_pointer_cast<Impl::Component>(cbdata.data)->telemetryEnabled =
false;
});
@@ -95,18 +97,24 @@ bool LiveWindow::IsEnabled() const {
void LiveWindow::SetEnabled(bool enabled) {
std::scoped_lock lock(m_impl->mutex);
if (m_impl->liveWindowEnabled == enabled) return;
if (m_impl->liveWindowEnabled == enabled) {
return;
}
m_impl->startLiveWindow = enabled;
m_impl->liveWindowEnabled = enabled;
// Force table generation now to make sure everything is defined
UpdateValuesUnsafe();
if (enabled) {
if (this->enabled) this->enabled();
if (this->enabled) {
this->enabled();
}
} else {
m_impl->registry.ForeachLiveWindow(m_impl->dataHandle, [&](auto& cbdata) {
cbdata.builder.StopLiveWindowMode();
});
if (this->disabled) this->disabled();
if (this->disabled) {
this->disabled();
}
}
m_impl->enabledEntry.SetBoolean(enabled);
}
@@ -118,30 +126,41 @@ void LiveWindow::UpdateValues() {
void LiveWindow::UpdateValuesUnsafe() {
// Only do this if either LiveWindow mode or telemetry is enabled.
if (!m_impl->liveWindowEnabled && !m_impl->telemetryEnabled) return;
if (!m_impl->liveWindowEnabled && !m_impl->telemetryEnabled) {
return;
}
m_impl->registry.ForeachLiveWindow(m_impl->dataHandle, [&](auto& cbdata) {
if (!cbdata.sendable || cbdata.parent) return;
if (!cbdata.sendable || cbdata.parent) {
return;
}
if (!cbdata.data) cbdata.data = std::make_shared<Impl::Component>();
if (!cbdata.data) {
cbdata.data = std::make_shared<Impl::Component>();
}
auto& comp = *std::static_pointer_cast<Impl::Component>(cbdata.data);
if (!m_impl->liveWindowEnabled && !comp.telemetryEnabled) return;
if (!m_impl->liveWindowEnabled && !comp.telemetryEnabled) {
return;
}
if (comp.firstTime) {
// By holding off creating the NetworkTable entries, it allows the
// components to be redefined. This allows default sensor and actuator
// values to be created that are replaced with the custom names from
// users calling setName.
if (cbdata.name.empty()) return;
if (cbdata.name.empty()) {
return;
}
auto ssTable = m_impl->liveWindowTable->GetSubTable(cbdata.subsystem);
std::shared_ptr<NetworkTable> table;
// Treat name==subsystem as top level of subsystem
if (cbdata.name == cbdata.subsystem)
if (cbdata.name == cbdata.subsystem) {
table = ssTable;
else
} else {
table = ssTable->GetSubTable(cbdata.name);
}
table->GetEntry(".name").SetString(cbdata.name);
cbdata.builder.SetTable(table);
cbdata.sendable->InitSendable(cbdata.builder);
@@ -150,7 +169,9 @@ void LiveWindow::UpdateValuesUnsafe() {
comp.firstTime = false;
}
if (m_impl->startLiveWindow) cbdata.builder.StartLiveWindowMode();
if (m_impl->startLiveWindow) {
cbdata.builder.StartLiveWindowMode();
}
cbdata.builder.UpdateTable();
});