From 8c3f07de8008787b2da191a8202fed2ca8d2832b Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sat, 7 Jan 2023 13:57:58 -0700 Subject: [PATCH] Add clang-tidy modernize-loop-convert check --- .clang-tidy | 1 + src/SFML/Window/DRM/InputImplUDev.cpp | 50 +++++++++++++------------- src/SFML/Window/OSX/HIDInputManager.mm | 6 ++-- src/SFML/Window/OSX/JoystickImpl.cpp | 4 +-- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 003e3a5cf..34718be35 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,6 +2,7 @@ Checks: > -*, clang-analyzer-*, modernize-concat-nested-namespaces, + modernize-loop-convert, modernize-use-equals-default, modernize-use-equals-delete, modernize-use-nullptr, diff --git a/src/SFML/Window/DRM/InputImplUDev.cpp b/src/SFML/Window/DRM/InputImplUDev.cpp index 1bd415b00..9704de67a 100644 --- a/src/SFML/Window/DRM/InputImplUDev.cpp +++ b/src/SFML/Window/DRM/InputImplUDev.cpp @@ -87,8 +87,8 @@ bool systemDown() void uninitFileDescriptors() { - for (std::vector::iterator itr = fileDescriptors.begin(); itr != fileDescriptors.end(); ++itr) - close(*itr); + for (const auto& fileDescriptor : fileDescriptors) + close(fileDescriptor); } #define BITS_PER_LONG (sizeof(unsigned long) * 8) @@ -317,35 +317,35 @@ TouchSlot& atSlot(int idx) void processSlots() { - for (std::vector::iterator slot = touchSlots.begin(); slot != touchSlots.end(); ++slot) + for (auto& slot : touchSlots) { sf::Event event; - event.touch.x = slot->pos.x; - event.touch.y = slot->pos.y; + event.touch.x = slot.pos.x; + event.touch.y = slot.pos.y; - if (slot->oldId == slot->id) + if (slot.oldId == slot.id) { event.type = sf::Event::TouchMoved; - event.touch.finger = static_cast(slot->id); + event.touch.finger = static_cast(slot.id); pushEvent(event); } else { - if (slot->oldId != -1) + if (slot.oldId != -1) { event.type = sf::Event::TouchEnded; - event.touch.finger = static_cast(slot->oldId); + event.touch.finger = static_cast(slot.oldId); pushEvent(event); } - if (slot->id != -1) + if (slot.id != -1) { event.type = sf::Event::TouchBegan; - event.touch.finger = static_cast(slot->id); + event.touch.finger = static_cast(slot.id); pushEvent(event); } - slot->oldId = slot->id; + slot.oldId = slot.id; } } } @@ -371,10 +371,10 @@ bool eventProcess(sf::Event& event) ssize_t bytesRead; // Check all the open file descriptors for the next event - for (std::vector::iterator itr = fileDescriptors.begin(); itr != fileDescriptors.end(); ++itr) + for (auto& fileDescriptor : fileDescriptors) { input_event inputEvent; - bytesRead = read(*itr, &inputEvent, sizeof(inputEvent)); + bytesRead = read(fileDescriptor, &inputEvent, sizeof(inputEvent)); while (bytesRead > 0) { @@ -467,30 +467,30 @@ bool eventProcess(sf::Event& event) { case ABS_MT_SLOT: currentSlot = inputEvent.value; - touchFd = *itr; + touchFd = fileDescriptor; break; case ABS_MT_TRACKING_ID: atSlot(currentSlot).id = inputEvent.value; - touchFd = *itr; + touchFd = fileDescriptor; break; case ABS_MT_POSITION_X: atSlot(currentSlot).pos.x = inputEvent.value; - touchFd = *itr; + touchFd = fileDescriptor; break; case ABS_MT_POSITION_Y: atSlot(currentSlot).pos.y = inputEvent.value; - touchFd = *itr; + touchFd = fileDescriptor; break; } } - else if (inputEvent.type == EV_SYN && inputEvent.code == SYN_REPORT && *itr == touchFd) + else if (inputEvent.type == EV_SYN && inputEvent.code == SYN_REPORT && fileDescriptor == touchFd) { // This pushes events directly to the queue, because it // can generate more than one event. processSlots(); } - bytesRead = read(*itr, &inputEvent, sizeof(inputEvent)); + bytesRead = read(fileDescriptor, &inputEvent, sizeof(inputEvent)); } if ((bytesRead < 0) && (errno != EAGAIN)) @@ -628,9 +628,9 @@ void InputImpl::setMousePosition(const Vector2i& position, const WindowBase& /*r //////////////////////////////////////////////////////////// bool InputImpl::isTouchDown(unsigned int finger) { - for (std::vector::iterator slot = touchSlots.begin(); slot != touchSlots.end(); ++slot) + for (const auto& slot : touchSlots) { - if (slot->id == static_cast(finger)) + if (slot.id == static_cast(finger)) return true; } @@ -641,10 +641,10 @@ bool InputImpl::isTouchDown(unsigned int finger) //////////////////////////////////////////////////////////// Vector2i InputImpl::getTouchPosition(unsigned int finger) { - for (std::vector::iterator slot = touchSlots.begin(); slot != touchSlots.end(); ++slot) + for (const auto& slot : touchSlots) { - if (slot->id == static_cast(finger)) - return slot->pos; + if (slot.id == static_cast(finger)) + return slot.pos; } return Vector2i(); diff --git a/src/SFML/Window/OSX/HIDInputManager.mm b/src/SFML/Window/OSX/HIDInputManager.mm index 40e17c13a..296503cd3 100644 --- a/src/SFML/Window/OSX/HIDInputManager.mm +++ b/src/SFML/Window/OSX/HIDInputManager.mm @@ -314,12 +314,12 @@ void HIDInputManager::freeUp() m_manager = nil; - for (unsigned int i = 0; i < Keyboard::KeyCount; ++i) + for (auto& key : m_keys) { - for (IOHIDElementRef iohidElementRef : m_keys[i]) + for (IOHIDElementRef iohidElementRef : key) CFRelease(iohidElementRef); - m_keys[i].clear(); + key.clear(); } } diff --git a/src/SFML/Window/OSX/JoystickImpl.cpp b/src/SFML/Window/OSX/JoystickImpl.cpp index a1e96984b..f2c5cdc22 100644 --- a/src/SFML/Window/OSX/JoystickImpl.cpp +++ b/src/SFML/Window/OSX/JoystickImpl.cpp @@ -126,9 +126,9 @@ bool JoystickImpl::isConnected(unsigned int index) // opened joystick devices then we find the new one. unsigned int openedCount = 0; - for (unsigned int i(0); i < sf::Joystick::Count; ++i) + for (const auto& locationID : m_locationIDs) { - if (m_locationIDs[i] != 0) + if (locationID != 0) ++openedCount; }