mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +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:
@@ -87,7 +87,9 @@ THandle UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Allocate(
|
||||
return MakeHandle(i);
|
||||
}
|
||||
}
|
||||
if (i >= THandle::kIndexMax) return 0;
|
||||
if (i >= THandle::kIndexMax) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_structures.emplace_back(
|
||||
std::make_shared<TStruct>(std::forward<Args>(args)...));
|
||||
@@ -105,7 +107,9 @@ THandle UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Allocate(
|
||||
return MakeHandle(i);
|
||||
}
|
||||
}
|
||||
if (i >= THandle::kIndexMax) return 0;
|
||||
if (i >= THandle::kIndexMax) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_structures.push_back(structure);
|
||||
return MakeHandle(i);
|
||||
@@ -117,9 +121,13 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Get(
|
||||
THandle handle) {
|
||||
auto index =
|
||||
handle.GetTypedIndex(static_cast<typename THandle::Type>(typeValue));
|
||||
if (index < 0) return nullptr;
|
||||
if (index < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
std::scoped_lock sync(m_handleMutex);
|
||||
if (index >= static_cast<int>(m_structures.size())) return nullptr;
|
||||
if (index >= static_cast<int>(m_structures.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
return m_structures[index];
|
||||
}
|
||||
|
||||
@@ -129,9 +137,13 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Free(
|
||||
THandle handle) {
|
||||
auto index =
|
||||
handle.GetTypedIndex(static_cast<typename THandle::Type>(typeValue));
|
||||
if (index < 0) return nullptr;
|
||||
if (index < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
std::scoped_lock sync(m_handleMutex);
|
||||
if (index >= static_cast<int>(m_structures.size())) return nullptr;
|
||||
if (index >= static_cast<int>(m_structures.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
auto rv = std::move(m_structures[index]);
|
||||
m_structures[index].reset();
|
||||
return rv;
|
||||
@@ -161,7 +173,9 @@ inline void
|
||||
UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::ForEach(F func) {
|
||||
std::scoped_lock sync(m_handleMutex);
|
||||
for (size_t i = 0; i < m_structures.size(); i++) {
|
||||
if (m_structures[i] != nullptr) func(MakeHandle(i), *(m_structures[i]));
|
||||
if (m_structures[i] != nullptr) {
|
||||
func(MakeHandle(i), *(m_structures[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,8 +186,9 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::FindIf(F func) {
|
||||
std::scoped_lock sync(m_handleMutex);
|
||||
for (size_t i = 0; i < m_structures.size(); i++) {
|
||||
auto& structure = m_structures[i];
|
||||
if (structure != nullptr && func(*structure))
|
||||
if (structure != nullptr && func(*structure)) {
|
||||
return std::make_pair(MakeHandle(i), structure);
|
||||
}
|
||||
}
|
||||
return std::make_pair(0, nullptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user