From ff9c9131b38da710979e5fd5caa4afeb1f74380d Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sat, 3 Sep 2022 18:34:59 -0600 Subject: [PATCH] Replace `sf::Uint16` with `std::uint16_t` --- examples/shader/Shader.cpp | 6 +++--- include/SFML/Config.hpp | 3 --- include/SFML/Graphics/Color.inl | 3 ++- include/SFML/Network/Packet.hpp | 4 ++-- include/SFML/System/String.hpp | 2 +- include/SFML/System/Utf.hpp | 2 +- include/SFML/System/Utf.inl | 10 +++++----- src/SFML/Audio/SoundFileReaderWav.cpp | 20 ++++++++++---------- src/SFML/Audio/SoundFileWriterWav.cpp | 10 +++++----- src/SFML/Network/Packet.cpp | 10 +++++----- src/SFML/System/String.cpp | 4 ++-- src/SFML/Window/Win32/WindowImplWin32.cpp | 4 ++-- src/SFML/Window/Win32/WindowImplWin32.hpp | 8 ++++---- test/System/Config.cpp | 2 -- 14 files changed, 42 insertions(+), 46 deletions(-) diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index 7986b8a3..77ca2cf3 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -135,9 +135,9 @@ public: bool onLoad() override { - std::uniform_real_distribution x_distribution(0, 800); - std::uniform_real_distribution y_distribution(0, 600); - std::uniform_int_distribution color_distribution(0, 255); + std::uniform_real_distribution x_distribution(0, 800); + std::uniform_real_distribution y_distribution(0, 600); + std::uniform_int_distribution color_distribution(0, 255); // Create the points m_points.setPrimitiveType(sf::Points); diff --git a/include/SFML/Config.hpp b/include/SFML/Config.hpp index d404b4f4..84cbacc2 100644 --- a/include/SFML/Config.hpp +++ b/include/SFML/Config.hpp @@ -167,9 +167,6 @@ //////////////////////////////////////////////////////////// namespace sf { -// 16 bits integer types -using Uint16 = std::uint16_t; - // 32 bits integer types using Int32 = std::int32_t; using Uint32 = std::uint32_t; diff --git a/include/SFML/Graphics/Color.inl b/include/SFML/Graphics/Color.inl index ad24747b..50abb81b 100644 --- a/include/SFML/Graphics/Color.inl +++ b/include/SFML/Graphics/Color.inl @@ -107,7 +107,8 @@ constexpr Color operator*(const Color& left, const Color& right) { const auto scaledMul = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t { - const auto uint16Result = static_cast(static_cast(lhs) * static_cast(rhs)); + const auto uint16Result = static_cast( + static_cast(lhs) * static_cast(rhs)); return static_cast(uint16Result / 255u); }; diff --git a/include/SFML/Network/Packet.hpp b/include/SFML/Network/Packet.hpp index 663a1292..d835c50d 100644 --- a/include/SFML/Network/Packet.hpp +++ b/include/SFML/Network/Packet.hpp @@ -228,7 +228,7 @@ public: //////////////////////////////////////////////////////////// /// \overload //////////////////////////////////////////////////////////// - Packet& operator>>(Uint16& data); + Packet& operator>>(std::uint16_t& data); //////////////////////////////////////////////////////////// /// \overload @@ -309,7 +309,7 @@ public: //////////////////////////////////////////////////////////// /// \overload //////////////////////////////////////////////////////////// - Packet& operator<<(Uint16 data); + Packet& operator<<(std::uint16_t data); //////////////////////////////////////////////////////////// /// \overload diff --git a/include/SFML/System/String.hpp b/include/SFML/System/String.hpp index 1aaa8cf5..80973936 100644 --- a/include/SFML/System/String.hpp +++ b/include/SFML/System/String.hpp @@ -296,7 +296,7 @@ public: /// \see toUtf8, toUtf32 /// //////////////////////////////////////////////////////////// - std::basic_string toUtf16() const; + std::basic_string toUtf16() const; //////////////////////////////////////////////////////////// /// \brief Convert the Unicode string to a UTF-32 string diff --git a/include/SFML/System/Utf.hpp b/include/SFML/System/Utf.hpp index cabfc263..75b1e9c8 100644 --- a/include/SFML/System/Utf.hpp +++ b/include/SFML/System/Utf.hpp @@ -292,7 +292,7 @@ public: /// //////////////////////////////////////////////////////////// template - static Out encode(Uint32 input, Out output, Uint16 replacement = 0); + static Out encode(Uint32 input, Out output, std::uint16_t replacement = 0); //////////////////////////////////////////////////////////// /// \brief Advance to the next UTF-16 character diff --git a/include/SFML/System/Utf.inl b/include/SFML/System/Utf.inl index eef35813..929f96c9 100644 --- a/include/SFML/System/Utf.inl +++ b/include/SFML/System/Utf.inl @@ -301,7 +301,7 @@ Out Utf<8>::toUtf32(In begin, In end, Out output) template In Utf<16>::decode(In begin, In end, Uint32& output, Uint32 replacement) { - Uint16 first = *begin++; + std::uint16_t first = *begin++; // If it's a surrogate pair, first convert to a single UTF-32 character if ((first >= 0xD800) && (first <= 0xDBFF)) @@ -339,7 +339,7 @@ In Utf<16>::decode(In begin, In end, Uint32& output, Uint32 replacement) //////////////////////////////////////////////////////////// template -Out Utf<16>::encode(Uint32 input, Out output, Uint16 replacement) +Out Utf<16>::encode(Uint32 input, Out output, std::uint16_t replacement) { if (input <= 0xFFFF) { @@ -353,7 +353,7 @@ Out Utf<16>::encode(Uint32 input, Out output, Uint16 replacement) else { // Valid character directly convertible to a single UTF-16 character - *output++ = static_cast(input); + *output++ = static_cast(input); } } else if (input > 0x0010FFFF) @@ -366,8 +366,8 @@ Out Utf<16>::encode(Uint32 input, Out output, Uint16 replacement) { // The input character will be converted to two UTF-16 elements input -= 0x0010000; - *output++ = static_cast((input >> 10) + 0xD800); - *output++ = static_cast((input & 0x3FFUL) + 0xDC00); + *output++ = static_cast((input >> 10) + 0xD800); + *output++ = static_cast((input & 0x3FFUL) + 0xDC00); } return output; diff --git a/src/SFML/Audio/SoundFileReaderWav.cpp b/src/SFML/Audio/SoundFileReaderWav.cpp index f6270ab1..86e5110d 100644 --- a/src/SFML/Audio/SoundFileReaderWav.cpp +++ b/src/SFML/Audio/SoundFileReaderWav.cpp @@ -57,13 +57,13 @@ bool decode(sf::InputStream& stream, std::int16_t& value) return true; } -bool decode(sf::InputStream& stream, sf::Uint16& value) +bool decode(sf::InputStream& stream, std::uint16_t& value) { unsigned char bytes[sizeof(value)]; if (static_cast(stream.read(bytes, static_cast(sizeof(bytes)))) != sizeof(bytes)) return false; - value = static_cast(bytes[0] | (bytes[1] << 8)); + value = static_cast(bytes[0] | (bytes[1] << 8)); return true; } @@ -92,9 +92,9 @@ bool decode(sf::InputStream& stream, sf::Uint32& value) const sf::Uint64 mainChunkSize = 12; -const sf::Uint16 waveFormatPcm = 1; +const std::uint16_t waveFormatPcm = 1; -const sf::Uint16 waveFormatExtensible = 65534; +const std::uint16_t waveFormatExtensible = 65534; const char* waveSubformatPcm = "\x01\x00\x00\x00\x00\x00\x10\x00" @@ -249,14 +249,14 @@ bool SoundFileReaderWav::parseHeader(Info& info) // "fmt" chunk // Audio format - Uint16 format = 0; + std::uint16_t format = 0; if (!decode(*m_stream, format)) return false; if ((format != waveFormatPcm) && (format != waveFormatExtensible)) return false; // Channel count - Uint16 channelCount = 0; + std::uint16_t channelCount = 0; if (!decode(*m_stream, channelCount)) return false; info.channelCount = channelCount; @@ -273,12 +273,12 @@ bool SoundFileReaderWav::parseHeader(Info& info) return false; // Block align - Uint16 blockAlign = 0; + std::uint16_t blockAlign = 0; if (!decode(*m_stream, blockAlign)) return false; // Bits per sample - Uint16 bitsPerSample = 0; + std::uint16_t bitsPerSample = 0; if (!decode(*m_stream, bitsPerSample)) return false; if (bitsPerSample != 8 && bitsPerSample != 16 && bitsPerSample != 24 && bitsPerSample != 32) @@ -292,12 +292,12 @@ bool SoundFileReaderWav::parseHeader(Info& info) if (format == waveFormatExtensible) { // Extension size - Uint16 extensionSize = 0; + std::uint16_t extensionSize = 0; if (!decode(*m_stream, extensionSize)) return false; // Valid bits per sample - Uint16 validBitsPerSample = 0; + std::uint16_t validBitsPerSample = 0; if (!decode(*m_stream, validBitsPerSample)) return false; diff --git a/src/SFML/Audio/SoundFileWriterWav.cpp b/src/SFML/Audio/SoundFileWriterWav.cpp index 9940b908..6a9112d8 100644 --- a/src/SFML/Audio/SoundFileWriterWav.cpp +++ b/src/SFML/Audio/SoundFileWriterWav.cpp @@ -44,7 +44,7 @@ void encode(std::ostream& stream, std::int16_t value) stream.write(reinterpret_cast(bytes), sizeof(bytes)); } -void encode(std::ostream& stream, sf::Uint16 value) +void encode(std::ostream& stream, std::uint16_t value) { unsigned char bytes[] = {static_cast(value & 0xFF), static_cast(value >> 8)}; stream.write(reinterpret_cast(bytes), sizeof(bytes)); @@ -139,17 +139,17 @@ bool SoundFileWriterWav::writeHeader(unsigned int sampleRate, unsigned int chann encode(m_file, fmtChunkSize); // Write the format (PCM) - Uint16 format = 1; + std::uint16_t format = 1; encode(m_file, format); // Write the sound attributes - encode(m_file, static_cast(channelCount)); + encode(m_file, static_cast(channelCount)); encode(m_file, sampleRate); Uint32 byteRate = sampleRate * channelCount * 2; encode(m_file, byteRate); - auto blockAlign = static_cast(channelCount * 2); + auto blockAlign = static_cast(channelCount * 2); encode(m_file, blockAlign); - Uint16 bitsPerSample = 16; + std::uint16_t bitsPerSample = 16; encode(m_file, bitsPerSample); // Write the sub-chunk 2 ("data") id and size diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index ab751aa3..c202cb76 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -160,7 +160,7 @@ Packet& Packet::operator>>(std::int16_t& data) if (checkSize(sizeof(data))) { std::memcpy(&data, &m_data[m_readPos], sizeof(data)); - data = static_cast(ntohs(static_cast(data))); + data = static_cast(ntohs(static_cast(data))); m_readPos += sizeof(data); } @@ -169,7 +169,7 @@ Packet& Packet::operator>>(std::int16_t& data) //////////////////////////////////////////////////////////// -Packet& Packet::operator>>(Uint16& data) +Packet& Packet::operator>>(std::uint16_t& data) { if (checkSize(sizeof(data))) { @@ -418,16 +418,16 @@ Packet& Packet::operator<<(std::uint8_t data) //////////////////////////////////////////////////////////// Packet& Packet::operator<<(std::int16_t data) { - auto toWrite = static_cast(htons(static_cast(data))); + auto toWrite = static_cast(htons(static_cast(data))); append(&toWrite, sizeof(toWrite)); return *this; } //////////////////////////////////////////////////////////// -Packet& Packet::operator<<(Uint16 data) +Packet& Packet::operator<<(std::uint16_t data) { - Uint16 toWrite = htons(data); + std::uint16_t toWrite = htons(data); append(&toWrite, sizeof(toWrite)); return *this; } diff --git a/src/SFML/System/String.cpp b/src/SFML/System/String.cpp index 75778326..930aed0e 100644 --- a/src/SFML/System/String.cpp +++ b/src/SFML/System/String.cpp @@ -196,10 +196,10 @@ std::basic_string String::toUtf8() const //////////////////////////////////////////////////////////// -std::basic_string String::toUtf16() const +std::basic_string String::toUtf16() const { // Prepare the output string - std::basic_string output; + std::basic_string output; output.reserve(m_string.length()); // Convert diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 9129bf50..0704142e 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -718,7 +718,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) if ((character >= 0xD800) && (character <= 0xDBFF)) { // First part of a surrogate pair: store it and wait for the second one - m_surrogate = static_cast(character); + m_surrogate = static_cast(character); } else { @@ -726,7 +726,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) if ((character >= 0xDC00) && (character <= 0xDFFF)) { // Convert the UTF-16 surrogate pair to a single UTF-32 value - Uint16 utf16[] = {m_surrogate, static_cast(character)}; + std::uint16_t utf16[] = {m_surrogate, static_cast(character)}; sf::Utf16::toUtf32(utf16, utf16 + 2, &character); m_surrogate = 0; } diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index dafb2892..474b40d9 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -277,10 +277,10 @@ private: bool m_keyRepeatEnabled; //!< Automatic key-repeat state for keydown events Vector2u m_lastSize; //!< The last handled size of the window bool m_resizing; //!< Is the window being resized? - Uint16 m_surrogate; //!< First half of the surrogate pair, in case we're receiving a Unicode character in two events - bool m_mouseInside; //!< Mouse is inside the window? - bool m_fullscreen; //!< Is the window fullscreen? - bool m_cursorGrabbed; //!< Is the mouse cursor trapped? + std::uint16_t m_surrogate; //!< First half of the surrogate pair, in case we're receiving a Unicode character in two events + bool m_mouseInside; //!< Mouse is inside the window? + bool m_fullscreen; //!< Is the window fullscreen? + bool m_cursorGrabbed; //!< Is the mouse cursor trapped? }; } // namespace priv diff --git a/test/System/Config.cpp b/test/System/Config.cpp index c9a9ad98..1c610714 100644 --- a/test/System/Config.cpp +++ b/test/System/Config.cpp @@ -14,8 +14,6 @@ TEST_CASE("SFML/Config.hpp") SUBCASE("Fixed width types") { - CHECK(sizeof(sf::Uint16) == 2); - CHECK(sizeof(sf::Int32) == 4); CHECK(sizeof(sf::Uint32) == 4);