From 82b48a7520a2eb83576ec16d68ff9ea6d3d5d5bd Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sat, 20 Aug 2022 22:36:15 -0600 Subject: [PATCH] Use `std::size_t` --- examples/vulkan/Vulkan.cpp | 2 +- src/SFML/Audio/SoundFileReaderOgg.cpp | 2 +- src/SFML/Main/MainAndroid.cpp | 4 ++-- src/SFML/Main/SFMLActivity.cpp | 10 +++++----- src/SFML/Network/Unix/SocketImpl.hpp | 2 +- src/SFML/System/Android/Activity.hpp | 4 ++-- src/SFML/System/Android/ResourceStream.cpp | 2 +- src/SFML/Window/Android/WindowImplAndroid.cpp | 8 ++++---- src/SFML/Window/DRM/InputImplUDev.cpp | 4 ++-- src/SFML/Window/FreeBSD/JoystickImpl.cpp | 4 ++-- src/SFML/Window/OSX/cg_sf_conversion.hpp | 4 ++-- src/SFML/Window/OSX/cg_sf_conversion.mm | 8 ++++---- src/SFML/Window/Win32/ClipboardImpl.cpp | 4 ++-- test/Graphics/Transform.cpp | 2 +- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index 7d66fda2c..e5826f42d 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -1611,7 +1611,7 @@ public: void setupUniformBuffers() { // Create a uniform buffer for every frame that might be in flight to prevent clobbering - for (size_t i = 0; i < swapchainImages.size(); ++i) + for (std::size_t i = 0; i < swapchainImages.size(); ++i) { uniformBuffers.push_back(0); uniformBuffersMemory.push_back(0); diff --git a/src/SFML/Audio/SoundFileReaderOgg.cpp b/src/SFML/Audio/SoundFileReaderOgg.cpp index 8c3bf7df3..05046d9dc 100644 --- a/src/SFML/Audio/SoundFileReaderOgg.cpp +++ b/src/SFML/Audio/SoundFileReaderOgg.cpp @@ -36,7 +36,7 @@ namespace { -size_t read(void* ptr, size_t size, size_t nmemb, void* data) +std::size_t read(void* ptr, std::size_t size, std::size_t nmemb, void* data) { auto* stream = static_cast(data); return static_cast(stream->read(ptr, static_cast(size * nmemb))); diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index 4fbf090c3..8afb32640 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -474,7 +474,7 @@ static void onConfigurationChanged(ANativeActivity* /* activity */) //////////////////////////////////////////////////////////// -static void* onSaveInstanceState(ANativeActivity* /* activity */, size_t* outLen) +static void* onSaveInstanceState(ANativeActivity* /* activity */, std::size_t* outLen) { *outLen = 0; @@ -489,7 +489,7 @@ static void onLowMemory(ANativeActivity* /* activity */) //////////////////////////////////////////////////////////// -JNIEXPORT void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize) +JNIEXPORT void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, std::size_t savedStateSize) { // Create an activity states (will keep us in the know, about events we care) auto* states = new sf::priv::ActivityStates; diff --git a/src/SFML/Main/SFMLActivity.cpp b/src/SFML/Main/SFMLActivity.cpp index ee66a757c..2841a6506 100644 --- a/src/SFML/Main/SFMLActivity.cpp +++ b/src/SFML/Main/SFMLActivity.cpp @@ -38,7 +38,7 @@ namespace { -using activityOnCreatePointer = void (*)(ANativeActivity*, void*, size_t); +using activityOnCreatePointer = void (*)(ANativeActivity*, void*, std::size_t); } const char* getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo) @@ -71,8 +71,8 @@ const char* getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo) } // Convert the application name to a C++ string and return it - const size_t applicationNameLength = static_cast(lJNIEnv->GetStringUTFLength(valueString)); - const char* applicationName = lJNIEnv->GetStringUTFChars(valueString, nullptr); + const std::size_t applicationNameLength = static_cast(lJNIEnv->GetStringUTFLength(valueString)); + const char* applicationName = lJNIEnv->GetStringUTFChars(valueString, nullptr); if (applicationNameLength >= 256) { @@ -80,7 +80,7 @@ const char* getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo) exit(1); } - strncpy(name, applicationName, static_cast(applicationNameLength)); + strncpy(name, applicationName, static_cast(applicationNameLength)); name[applicationNameLength] = '\0'; lJNIEnv->ReleaseStringUTFChars(valueString, applicationName); @@ -132,7 +132,7 @@ void* loadLibrary(const char* libraryName, JNIEnv* lJNIEnv, jobject& ObjectActiv return handle; } -void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_t savedStateSize) +void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, std::size_t savedStateSize) { // Before we can load a library, we need to find out its location. As // we're powerless here in C/C++, we need the JNI interface to communicate diff --git a/src/SFML/Network/Unix/SocketImpl.hpp b/src/SFML/Network/Unix/SocketImpl.hpp index 60fc40237..04568fc27 100644 --- a/src/SFML/Network/Unix/SocketImpl.hpp +++ b/src/SFML/Network/Unix/SocketImpl.hpp @@ -55,7 +55,7 @@ public: // Types //////////////////////////////////////////////////////////// using AddrLength = socklen_t; - using Size = size_t; + using Size = std::size_t; //////////////////////////////////////////////////////////// /// \brief Create an internal sockaddr_in address diff --git a/src/SFML/System/Android/Activity.hpp b/src/SFML/System/Android/Activity.hpp index d0f785f12..ac8982fb7 100644 --- a/src/SFML/System/Android/Activity.hpp +++ b/src/SFML/System/Android/Activity.hpp @@ -67,8 +67,8 @@ struct ActivityStates EGLDisplay display; EglContext* context; - void* savedState; - size_t savedStateSize; + void* savedState; + std::size_t savedStateSize; std::recursive_mutex mutex; diff --git a/src/SFML/System/Android/ResourceStream.cpp b/src/SFML/System/Android/ResourceStream.cpp index 7fe73199a..443d14f6c 100644 --- a/src/SFML/System/Android/ResourceStream.cpp +++ b/src/SFML/System/Android/ResourceStream.cpp @@ -61,7 +61,7 @@ Int64 ResourceStream::read(void* data, Int64 size) { if (m_file) { - return AAsset_read(m_file, data, static_cast(size)); + return AAsset_read(m_file, data, static_cast(size)); } else { diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index de14a6567..0b14dafd9 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -476,9 +476,9 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& s else if (static_cast(device) & AINPUT_SOURCE_TOUCHSCREEN) event.type = Event::TouchMoved; - size_t pointerCount = AMotionEvent_getPointerCount(_event); + std::size_t pointerCount = AMotionEvent_getPointerCount(_event); - for (size_t p = 0; p < pointerCount; ++p) + for (std::size_t p = 0; p < pointerCount; ++p) { int32_t id = AMotionEvent_getPointerId(_event, p); @@ -516,8 +516,8 @@ int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, Act int32_t device = AInputEvent_getSource(_event); int32_t action = AMotionEvent_getAction(_event); - size_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; - int32_t id = AMotionEvent_getPointerId(_event, index); + std::size_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + int32_t id = AMotionEvent_getPointerId(_event, index); int x = static_cast(AMotionEvent_getX(_event, index)); int y = static_cast(AMotionEvent_getY(_event, index)); diff --git a/src/SFML/Window/DRM/InputImplUDev.cpp b/src/SFML/Window/DRM/InputImplUDev.cpp index 8ec8a9f56..219a774e6 100644 --- a/src/SFML/Window/DRM/InputImplUDev.cpp +++ b/src/SFML/Window/DRM/InputImplUDev.cpp @@ -315,8 +315,8 @@ void pushEvent(sf::Event& event) TouchSlot& atSlot(int idx) { if (idx >= static_cast(touchSlots.size())) - touchSlots.resize(static_cast(idx + 1)); - return touchSlots.at(static_cast(idx)); + touchSlots.resize(static_cast(idx + 1)); + return touchSlots.at(static_cast(idx)); } void processSlots() diff --git a/src/SFML/Window/FreeBSD/JoystickImpl.cpp b/src/SFML/Window/FreeBSD/JoystickImpl.cpp index dc9c09175..59a4fed53 100644 --- a/src/SFML/Window/FreeBSD/JoystickImpl.cpp +++ b/src/SFML/Window/FreeBSD/JoystickImpl.cpp @@ -228,7 +228,7 @@ bool JoystickImpl::open(unsigned int index) // Then allocate a buffer for data retrieval m_length = hid_report_size(m_desc, hid_input, m_id); - m_buffer.resize(static_cast(m_length)); + m_buffer.resize(static_cast(m_length)); m_state.connected = true; @@ -300,7 +300,7 @@ Joystick::Identification JoystickImpl::getIdentification() const //////////////////////////////////////////////////////////// JoystickState JoystickImpl::JoystickImpl::update() { - while (read(m_file, m_buffer.data(), static_cast(m_length)) == m_length) + while (read(m_file, m_buffer.data(), static_cast(m_length)) == m_length) { hid_data_t data = hid_start_parse(m_desc, 1 << hid_input, m_id); diff --git a/src/SFML/Window/OSX/cg_sf_conversion.hpp b/src/SFML/Window/OSX/cg_sf_conversion.hpp index 1c7ef4ec5..4a2e9debd 100644 --- a/src/SFML/Window/OSX/cg_sf_conversion.hpp +++ b/src/SFML/Window/OSX/cg_sf_conversion.hpp @@ -44,7 +44,7 @@ namespace priv /// to represent video mode. Instead it uses a CGDisplayMode opaque type. /// //////////////////////////////////////////////////////////// -size_t modeBitsPerPixel(CGDisplayModeRef mode); +std::size_t modeBitsPerPixel(CGDisplayModeRef mode); //////////////////////////////////////////////////////////// /// \brief Get bpp for all OS X version @@ -53,7 +53,7 @@ size_t modeBitsPerPixel(CGDisplayModeRef mode); /// display bits per pixel information for a given display id. /// //////////////////////////////////////////////////////////// -size_t displayBitsPerPixel(CGDirectDisplayID displayId); +std::size_t displayBitsPerPixel(CGDirectDisplayID displayId); //////////////////////////////////////////////////////////// /// \brief Convert a Quartz video mode into a sf::VideoMode object diff --git a/src/SFML/Window/OSX/cg_sf_conversion.mm b/src/SFML/Window/OSX/cg_sf_conversion.mm index a5363927d..4800bb773 100644 --- a/src/SFML/Window/OSX/cg_sf_conversion.mm +++ b/src/SFML/Window/OSX/cg_sf_conversion.mm @@ -38,9 +38,9 @@ namespace priv { //////////////////////////////////////////////////////////// -size_t modeBitsPerPixel(CGDisplayModeRef mode) +std::size_t modeBitsPerPixel(CGDisplayModeRef mode) { - size_t bpp = 0; // no match + std::size_t bpp = 0; // no match // Compare encoding. CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(mode); @@ -59,13 +59,13 @@ size_t modeBitsPerPixel(CGDisplayModeRef mode) //////////////////////////////////////////////////////////// -size_t displayBitsPerPixel(CGDirectDisplayID displayId) +std::size_t displayBitsPerPixel(CGDirectDisplayID displayId) { // Get the display mode. CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId); // Get bpp for the mode. - const size_t bpp = modeBitsPerPixel(mode); + const std::size_t bpp = modeBitsPerPixel(mode); // Clean up Memory. CGDisplayModeRelease(mode); diff --git a/src/SFML/Window/Win32/ClipboardImpl.cpp b/src/SFML/Window/Win32/ClipboardImpl.cpp index 856f49aa3..5f9e5cab6 100644 --- a/src/SFML/Window/Win32/ClipboardImpl.cpp +++ b/src/SFML/Window/Win32/ClipboardImpl.cpp @@ -87,8 +87,8 @@ void ClipboardImpl::setString(const String& text) } // Create a Win32-compatible string - size_t string_size = (text.getSize() + 1) * sizeof(WCHAR); - HANDLE string_handle = GlobalAlloc(GMEM_MOVEABLE, string_size); + std::size_t string_size = (text.getSize() + 1) * sizeof(WCHAR); + HANDLE string_handle = GlobalAlloc(GMEM_MOVEABLE, string_size); if (string_handle) { diff --git a/test/Graphics/Transform.cpp b/test/Graphics/Transform.cpp index 33c4d1297..e2908541f 100644 --- a/test/Graphics/Transform.cpp +++ b/test/Graphics/Transform.cpp @@ -17,7 +17,7 @@ struct StringMaker> { assert(!vector.empty()); doctest::String out = "{ "; - for (size_t i = 0; i + 1 < vector.size(); ++i) + for (std::size_t i = 0; i + 1 < vector.size(); ++i) out += toString(vector[i]) + ", "; out += toString(vector.back()) + " }"; return out;