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

@@ -57,15 +57,19 @@ class EncoderSimModel : public glass::EncoderModel {
HALSIM_GetEncoderDigitalChannelB(index)) {}
~EncoderSimModel() {
if (m_distancePerPulseCallback != 0)
if (m_distancePerPulseCallback != 0) {
HALSIM_CancelEncoderDistancePerPulseCallback(m_index,
m_distancePerPulseCallback);
if (m_countCallback != 0)
}
if (m_countCallback != 0) {
HALSIM_CancelEncoderCountCallback(m_index, m_countCallback);
if (m_periodCallback != 0)
}
if (m_periodCallback != 0) {
HALSIM_CancelEncoderCountCallback(m_index, m_periodCallback);
if (m_directionCallback != 0)
}
if (m_directionCallback != 0) {
HALSIM_CancelEncoderCountCallback(m_index, m_directionCallback);
}
}
void Update() override {}
@@ -75,10 +79,11 @@ class EncoderSimModel : public glass::EncoderModel {
int32_t GetIndex() const { return m_index; }
const char* GetSimDevice() const override {
if (auto simDevice = HALSIM_GetEncoderSimDevice(m_index))
if (auto simDevice = HALSIM_GetEncoderSimDevice(m_index)) {
return HALSIM_GetSimDeviceName(simDevice);
else
} else {
return nullptr;
}
}
int GetChannelA() const override { return m_channelA; }
@@ -127,12 +132,13 @@ class EncoderSimModel : public glass::EncoderModel {
self->m_distancePerPulse.SetValue(distPerPulse);
self->m_distance.SetValue(self->m_count.GetValue() * distPerPulse);
double period = self->m_period.GetValue();
if (period == 0)
if (period == 0) {
self->m_rate.SetValue(std::numeric_limits<double>::infinity());
else if (period == std::numeric_limits<double>::infinity())
} else if (period == std::numeric_limits<double>::infinity()) {
self->m_rate.SetValue(0);
else
} else {
self->m_rate.SetValue(static_cast<float>(distPerPulse / period));
}
}
}
@@ -152,13 +158,14 @@ class EncoderSimModel : public glass::EncoderModel {
auto self = static_cast<EncoderSimModel*>(param);
double period = value->data.v_double;
self->m_period.SetValue(period);
if (period == 0)
if (period == 0) {
self->m_rate.SetValue(std::numeric_limits<double>::infinity());
else if (period == std::numeric_limits<double>::infinity())
} else if (period == std::numeric_limits<double>::infinity()) {
self->m_rate.SetValue(0);
else
} else {
self->m_rate.SetValue(
static_cast<float>(self->m_distancePerPulse.GetValue() / period));
}
}
}
@@ -230,7 +237,9 @@ void EncodersSimModel::ForEachEncoder(
static bool EncodersAnyInitialized() {
static const int32_t num = HAL_GetNumEncoders();
for (int32_t i = 0; i < num; ++i) {
if (HALSIM_GetEncoderInitialized(i)) return true;
if (HALSIM_GetEncoderInitialized(i)) {
return true;
}
}
return false;
}