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:
@@ -51,9 +51,12 @@ struct SendableRegistry::Impl {
|
||||
SendableRegistry::Impl::Component& SendableRegistry::Impl::GetOrAdd(
|
||||
void* sendable, UID* uid) {
|
||||
UID& compUid = componentMap[sendable];
|
||||
if (compUid == 0)
|
||||
if (compUid == 0) {
|
||||
compUid = components.emplace_back(std::make_unique<Component>()) + 1;
|
||||
if (uid) *uid = compUid;
|
||||
}
|
||||
if (uid) {
|
||||
*uid = compUid;
|
||||
}
|
||||
|
||||
return *components[compUid - 1];
|
||||
}
|
||||
@@ -146,13 +149,17 @@ void SendableRegistry::AddChild(Sendable* parent, void* child) {
|
||||
bool SendableRegistry::Remove(Sendable* sendable) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end()) return false;
|
||||
if (it == m_impl->componentMap.end()) {
|
||||
return false;
|
||||
}
|
||||
UID compUid = it->getSecond();
|
||||
m_impl->components.erase(compUid - 1);
|
||||
m_impl->componentMap.erase(it);
|
||||
// update any parent pointers
|
||||
for (auto&& comp : m_impl->components) {
|
||||
if (comp->parent == sendable) comp->parent = nullptr;
|
||||
if (comp->parent == sendable) {
|
||||
comp->parent = nullptr;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -161,8 +168,9 @@ void SendableRegistry::Move(Sendable* to, Sendable* from) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(from);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
UID compUid = it->getSecond();
|
||||
m_impl->componentMap.erase(it);
|
||||
m_impl->componentMap[to] = compUid;
|
||||
@@ -175,7 +183,9 @@ void SendableRegistry::Move(Sendable* to, Sendable* from) {
|
||||
}
|
||||
// update any parent pointers
|
||||
for (auto&& comp : m_impl->components) {
|
||||
if (comp->parent == from) comp->parent = to;
|
||||
if (comp->parent == from) {
|
||||
comp->parent = to;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,8 +198,9 @@ std::string SendableRegistry::GetName(const Sendable* sendable) const {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
return std::string{};
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return {};
|
||||
}
|
||||
return m_impl->components[it->getSecond() - 1]->name;
|
||||
}
|
||||
|
||||
@@ -197,8 +208,9 @@ void SendableRegistry::SetName(Sendable* sendable, const wpi::Twine& name) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->name = name.str();
|
||||
}
|
||||
|
||||
@@ -207,8 +219,9 @@ void SendableRegistry::SetName(Sendable* sendable, const wpi::Twine& moduleType,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->SetName(moduleType, channel);
|
||||
}
|
||||
|
||||
@@ -217,8 +230,9 @@ void SendableRegistry::SetName(Sendable* sendable, const wpi::Twine& moduleType,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->SetName(moduleType, moduleNumber,
|
||||
channel);
|
||||
}
|
||||
@@ -228,8 +242,9 @@ void SendableRegistry::SetName(Sendable* sendable, const wpi::Twine& subsystem,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
auto& comp = *m_impl->components[it->getSecond() - 1];
|
||||
comp.name = name.str();
|
||||
comp.subsystem = subsystem.str();
|
||||
@@ -239,8 +254,9 @@ std::string SendableRegistry::GetSubsystem(const Sendable* sendable) const {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
return std::string{};
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return {};
|
||||
}
|
||||
return m_impl->components[it->getSecond() - 1]->subsystem;
|
||||
}
|
||||
|
||||
@@ -249,8 +265,9 @@ void SendableRegistry::SetSubsystem(Sendable* sendable,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->subsystem = subsystem.str();
|
||||
}
|
||||
|
||||
@@ -265,14 +282,16 @@ std::shared_ptr<void> SendableRegistry::SetData(Sendable* sendable, int handle,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return nullptr;
|
||||
}
|
||||
auto& comp = *m_impl->components[it->getSecond() - 1];
|
||||
std::shared_ptr<void> rv;
|
||||
if (static_cast<size_t>(handle) < comp.data.size())
|
||||
if (static_cast<size_t>(handle) < comp.data.size()) {
|
||||
rv = std::move(comp.data[handle]);
|
||||
else
|
||||
} else {
|
||||
comp.data.resize(handle + 1);
|
||||
}
|
||||
comp.data[handle] = std::move(data);
|
||||
return rv;
|
||||
}
|
||||
@@ -283,10 +302,13 @@ std::shared_ptr<void> SendableRegistry::GetData(Sendable* sendable,
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return nullptr;
|
||||
}
|
||||
auto& comp = *m_impl->components[it->getSecond() - 1];
|
||||
if (static_cast<size_t>(handle) >= comp.data.size()) return nullptr;
|
||||
if (static_cast<size_t>(handle) >= comp.data.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
return comp.data[handle];
|
||||
}
|
||||
|
||||
@@ -294,8 +316,9 @@ void SendableRegistry::EnableLiveWindow(Sendable* sendable) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->liveWindow = true;
|
||||
}
|
||||
|
||||
@@ -303,8 +326,9 @@ void SendableRegistry::DisableLiveWindow(Sendable* sendable) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
auto it = m_impl->componentMap.find(sendable);
|
||||
if (it == m_impl->componentMap.end() ||
|
||||
!m_impl->components[it->getSecond() - 1])
|
||||
!m_impl->components[it->getSecond() - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[it->getSecond() - 1]->liveWindow = false;
|
||||
}
|
||||
|
||||
@@ -317,10 +341,13 @@ SendableRegistry::UID SendableRegistry::GetUniqueId(Sendable* sendable) {
|
||||
}
|
||||
|
||||
Sendable* SendableRegistry::GetSendable(UID uid) {
|
||||
if (uid == 0) return nullptr;
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
if ((uid - 1) >= m_impl->components.size() || !m_impl->components[uid - 1])
|
||||
if (uid == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
if ((uid - 1) >= m_impl->components.size() || !m_impl->components[uid - 1]) {
|
||||
return nullptr;
|
||||
}
|
||||
return m_impl->components[uid - 1]->sendable;
|
||||
}
|
||||
|
||||
@@ -328,8 +355,9 @@ void SendableRegistry::Publish(UID sendableUid,
|
||||
std::shared_ptr<NetworkTable> table) {
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
if (sendableUid == 0 || (sendableUid - 1) >= m_impl->components.size() ||
|
||||
!m_impl->components[sendableUid - 1])
|
||||
!m_impl->components[sendableUid - 1]) {
|
||||
return;
|
||||
}
|
||||
auto& comp = *m_impl->components[sendableUid - 1];
|
||||
comp.builder = SendableBuilderImpl{}; // clear any current builder
|
||||
comp.builder.SetTable(table);
|
||||
@@ -339,11 +367,14 @@ void SendableRegistry::Publish(UID sendableUid,
|
||||
}
|
||||
|
||||
void SendableRegistry::Update(UID sendableUid) {
|
||||
if (sendableUid == 0) return;
|
||||
if (sendableUid == 0) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
if ((sendableUid - 1) >= m_impl->components.size() ||
|
||||
!m_impl->components[sendableUid - 1])
|
||||
!m_impl->components[sendableUid - 1]) {
|
||||
return;
|
||||
}
|
||||
m_impl->components[sendableUid - 1]->builder.UpdateTable();
|
||||
}
|
||||
|
||||
@@ -353,11 +384,14 @@ void SendableRegistry::ForeachLiveWindow(
|
||||
assert(dataHandle >= 0);
|
||||
std::scoped_lock lock(m_impl->mutex);
|
||||
wpi::SmallVector<Impl::Component*, 128> components;
|
||||
for (auto&& comp : m_impl->components) components.emplace_back(comp.get());
|
||||
for (auto&& comp : m_impl->components) {
|
||||
components.emplace_back(comp.get());
|
||||
}
|
||||
for (auto comp : components) {
|
||||
if (comp && comp->sendable && comp->liveWindow) {
|
||||
if (static_cast<size_t>(dataHandle) >= comp->data.size())
|
||||
if (static_cast<size_t>(dataHandle) >= comp->data.size()) {
|
||||
comp->data.resize(dataHandle + 1);
|
||||
}
|
||||
CallbackData cbdata{comp->sendable, comp->name,
|
||||
comp->subsystem, comp->parent,
|
||||
comp->data[dataHandle], comp->builder};
|
||||
|
||||
Reference in New Issue
Block a user