mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +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:
@@ -21,7 +21,9 @@ SinkImpl::SinkImpl(const wpi::Twine& name, wpi::Logger& logger,
|
||||
|
||||
SinkImpl::~SinkImpl() {
|
||||
if (m_source) {
|
||||
if (m_enabledCount > 0) m_source->DisableSink();
|
||||
if (m_enabledCount > 0) {
|
||||
m_source->DisableSink();
|
||||
}
|
||||
m_source->RemoveSink();
|
||||
}
|
||||
}
|
||||
@@ -41,7 +43,9 @@ void SinkImpl::Enable() {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
++m_enabledCount;
|
||||
if (m_enabledCount == 1) {
|
||||
if (m_source) m_source->EnableSink();
|
||||
if (m_source) {
|
||||
m_source->EnableSink();
|
||||
}
|
||||
m_notifier.NotifySink(*this, CS_SINK_ENABLED);
|
||||
}
|
||||
}
|
||||
@@ -50,7 +54,9 @@ void SinkImpl::Disable() {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
--m_enabledCount;
|
||||
if (m_enabledCount == 0) {
|
||||
if (m_source) m_source->DisableSink();
|
||||
if (m_source) {
|
||||
m_source->DisableSink();
|
||||
}
|
||||
m_notifier.NotifySink(*this, CS_SINK_DISABLED);
|
||||
}
|
||||
}
|
||||
@@ -58,11 +64,15 @@ void SinkImpl::Disable() {
|
||||
void SinkImpl::SetEnabled(bool enabled) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
if (enabled && m_enabledCount == 0) {
|
||||
if (m_source) m_source->EnableSink();
|
||||
if (m_source) {
|
||||
m_source->EnableSink();
|
||||
}
|
||||
m_enabledCount = 1;
|
||||
m_notifier.NotifySink(*this, CS_SINK_ENABLED);
|
||||
} else if (!enabled && m_enabledCount > 0) {
|
||||
if (m_source) m_source->DisableSink();
|
||||
if (m_source) {
|
||||
m_source->DisableSink();
|
||||
}
|
||||
m_enabledCount = 0;
|
||||
m_notifier.NotifySink(*this, CS_SINK_DISABLED);
|
||||
}
|
||||
@@ -71,15 +81,21 @@ void SinkImpl::SetEnabled(bool enabled) {
|
||||
void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
|
||||
{
|
||||
std::scoped_lock lock(m_mutex);
|
||||
if (m_source == source) return;
|
||||
if (m_source == source) {
|
||||
return;
|
||||
}
|
||||
if (m_source) {
|
||||
if (m_enabledCount > 0) m_source->DisableSink();
|
||||
if (m_enabledCount > 0) {
|
||||
m_source->DisableSink();
|
||||
}
|
||||
m_source->RemoveSink();
|
||||
}
|
||||
m_source = source;
|
||||
if (m_source) {
|
||||
m_source->AddSink();
|
||||
if (m_enabledCount > 0) m_source->EnableSink();
|
||||
if (m_enabledCount > 0) {
|
||||
m_source->EnableSink();
|
||||
}
|
||||
}
|
||||
}
|
||||
SetSourceImpl(source);
|
||||
@@ -87,13 +103,17 @@ void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
|
||||
|
||||
std::string SinkImpl::GetError() const {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
if (!m_source) return "no source connected";
|
||||
if (!m_source) {
|
||||
return "no source connected";
|
||||
}
|
||||
return m_source->GetCurFrame().GetError();
|
||||
}
|
||||
|
||||
wpi::StringRef SinkImpl::GetError(wpi::SmallVectorImpl<char>& buf) const {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
if (!m_source) return "no source connected";
|
||||
if (!m_source) {
|
||||
return "no source connected";
|
||||
}
|
||||
// Make a copy as it's shared data
|
||||
wpi::StringRef error = m_source->GetCurFrame().GetError();
|
||||
buf.clear();
|
||||
@@ -115,8 +135,9 @@ bool SinkImpl::SetConfigJson(wpi::StringRef config, CS_Status* status) {
|
||||
}
|
||||
|
||||
bool SinkImpl::SetConfigJson(const wpi::json& config, CS_Status* status) {
|
||||
if (config.count("properties") != 0)
|
||||
if (config.count("properties") != 0) {
|
||||
SetPropertiesJson(config.at("properties"), m_logger, GetName(), status);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -133,7 +154,9 @@ wpi::json SinkImpl::GetConfigJsonObject(CS_Status* status) {
|
||||
wpi::json j;
|
||||
|
||||
wpi::json props = GetPropertiesJsonObject(status);
|
||||
if (props.is_array()) j.emplace("properties", props);
|
||||
if (props.is_array()) {
|
||||
j.emplace("properties", props);
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
@@ -143,21 +166,25 @@ void SinkImpl::NotifyPropertyCreated(int propIndex, PropertyImpl& prop) {
|
||||
propIndex, prop.propKind, prop.value,
|
||||
prop.valueStr);
|
||||
// also notify choices updated event for enum types
|
||||
if (prop.propKind == CS_PROP_ENUM)
|
||||
if (prop.propKind == CS_PROP_ENUM) {
|
||||
m_notifier.NotifySinkProperty(*this, CS_SINK_PROPERTY_CHOICES_UPDATED,
|
||||
prop.name, propIndex, prop.propKind,
|
||||
prop.value, wpi::Twine{});
|
||||
}
|
||||
}
|
||||
|
||||
void SinkImpl::UpdatePropertyValue(int property, bool setString, int value,
|
||||
const wpi::Twine& valueStr) {
|
||||
auto prop = GetProperty(property);
|
||||
if (!prop) return;
|
||||
if (!prop) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (setString)
|
||||
if (setString) {
|
||||
prop->SetValue(valueStr);
|
||||
else
|
||||
} else {
|
||||
prop->SetValue(value);
|
||||
}
|
||||
|
||||
// Only notify updates after we've notified created
|
||||
if (m_properties_cached) {
|
||||
|
||||
Reference in New Issue
Block a user