mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01: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:
@@ -47,7 +47,9 @@ void DSCommPacket::SetAlliance(uint8_t station_code) {
|
||||
}
|
||||
|
||||
void DSCommPacket::ReadMatchtimeTag(wpi::ArrayRef<uint8_t> tagData) {
|
||||
if (tagData.size() < 6) return;
|
||||
if (tagData.size() < 6) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t store = tagData[2] << 24;
|
||||
store |= tagData[3] << 16;
|
||||
@@ -137,7 +139,9 @@ void DSCommPacket::DecodeTCP(wpi::ArrayRef<uint8_t> packet) {
|
||||
}
|
||||
|
||||
void DSCommPacket::DecodeUDP(wpi::ArrayRef<uint8_t> packet) {
|
||||
if (packet.size() < 6) return;
|
||||
if (packet.size() < 6) {
|
||||
return;
|
||||
}
|
||||
// Decode fixed header
|
||||
m_hi = packet[0];
|
||||
m_lo = packet[1];
|
||||
@@ -146,7 +150,9 @@ void DSCommPacket::DecodeUDP(wpi::ArrayRef<uint8_t> packet) {
|
||||
SetAlliance(packet[5]);
|
||||
|
||||
// Return if packet finished
|
||||
if (packet.size() == 6) return;
|
||||
if (packet.size() == 6) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Else, handle tagged data
|
||||
packet = packet.slice(6);
|
||||
@@ -173,7 +179,9 @@ void DSCommPacket::DecodeUDP(wpi::ArrayRef<uint8_t> packet) {
|
||||
|
||||
void DSCommPacket::ReadNewMatchInfoTag(wpi::ArrayRef<uint8_t> data) {
|
||||
// Size 2 bytes, tag 1 byte
|
||||
if (data.size() <= 3) return;
|
||||
if (data.size() <= 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
int nameLength = std::min<size_t>(data[3], sizeof(matchInfo.eventName) - 1);
|
||||
|
||||
@@ -185,7 +193,9 @@ void DSCommPacket::ReadNewMatchInfoTag(wpi::ArrayRef<uint8_t> data) {
|
||||
|
||||
data = data.slice(4 + nameLength);
|
||||
|
||||
if (data.size() < 4) return;
|
||||
if (data.size() < 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
matchInfo.matchType = static_cast<HAL_MatchType>(
|
||||
data[0]); // None, Practice, Qualification, Elimination, Test
|
||||
@@ -197,7 +207,9 @@ void DSCommPacket::ReadNewMatchInfoTag(wpi::ArrayRef<uint8_t> data) {
|
||||
|
||||
void DSCommPacket::ReadGameSpecificMessageTag(wpi::ArrayRef<uint8_t> data) {
|
||||
// Size 2 bytes, tag 1 byte
|
||||
if (data.size() <= 3) return;
|
||||
if (data.size() <= 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
int length = std::min<size_t>(((data[0] << 8) | data[1]) - 1,
|
||||
sizeof(matchInfo.gameSpecificMessage));
|
||||
@@ -210,7 +222,9 @@ void DSCommPacket::ReadGameSpecificMessageTag(wpi::ArrayRef<uint8_t> data) {
|
||||
HALSIM_SetMatchInfo(&matchInfo);
|
||||
}
|
||||
void DSCommPacket::ReadJoystickDescriptionTag(wpi::ArrayRef<uint8_t> data) {
|
||||
if (data.size() < 3) return;
|
||||
if (data.size() < 3) {
|
||||
return;
|
||||
}
|
||||
data = data.slice(3);
|
||||
int joystickNum = data[0];
|
||||
DSCommJoystickPacket& packet = m_joystick_packets[joystickNum];
|
||||
|
||||
@@ -57,7 +57,9 @@ static void HandleTcpDataStream(Buffer& buf, size_t size, DataStore& store) {
|
||||
size_t toCopy = (std::min)(2u - store.m_frame.size(), data.size());
|
||||
store.m_frame.append(data.bytes_begin(), data.bytes_begin() + toCopy);
|
||||
data = data.drop_front(toCopy);
|
||||
if (store.m_frame.size() < 2u) return; // need more data
|
||||
if (store.m_frame.size() < 2u) {
|
||||
return; // need more data
|
||||
}
|
||||
}
|
||||
store.m_frameSize = (static_cast<uint16_t>(store.m_frame[0]) << 8) |
|
||||
static_cast<uint16_t>(store.m_frame[1]);
|
||||
|
||||
Reference in New Issue
Block a user