From 50d86e4755cfb0fecc191bd9d5e226f6a7ebf18a Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Fri, 12 Aug 2022 23:49:44 -0600 Subject: [PATCH] Use in-class member initializers --- include/SFML/Network/Http.hpp | 20 ++++++-------------- include/SFML/Network/Packet.hpp | 8 ++++---- include/SFML/Network/Socket.hpp | 6 +++--- include/SFML/Network/TcpSocket.hpp | 8 +++----- include/SFML/Network/UdpSocket.hpp | 2 +- src/SFML/Network/Http.cpp | 10 +--------- src/SFML/Network/Packet.cpp | 4 +--- src/SFML/Network/Socket.cpp | 2 +- src/SFML/Network/TcpSocket.cpp | 6 ------ src/SFML/Network/UdpSocket.cpp | 2 +- 10 files changed, 21 insertions(+), 47 deletions(-) diff --git a/include/SFML/Network/Http.hpp b/include/SFML/Network/Http.hpp index fe9421d0..51b01e8e 100644 --- a/include/SFML/Network/Http.hpp +++ b/include/SFML/Network/Http.hpp @@ -232,14 +232,6 @@ public: ConnectionFailed = 1001 //!< Connection with server failed }; - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - /// Constructs an empty response. - /// - //////////////////////////////////////////////////////////// - Response(); - //////////////////////////////////////////////////////////// /// \brief Get the value of a field /// @@ -335,11 +327,11 @@ public: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - FieldTable m_fields; //!< Fields of the header - Status m_status; //!< Status code - unsigned int m_majorVersion; //!< Major HTTP version - unsigned int m_minorVersion; //!< Minor HTTP version - std::string m_body; //!< Body of the response + FieldTable m_fields; //!< Fields of the header + Status m_status{Status::ConnectionFailed}; //!< Status code + unsigned int m_majorVersion{0}; //!< Major HTTP version + unsigned int m_minorVersion{0}; //!< Minor HTTP version + std::string m_body; //!< Body of the response }; //////////////////////////////////////////////////////////// @@ -420,7 +412,7 @@ private: TcpSocket m_connection; //!< Connection to the host std::optional m_host; //!< Web host address std::string m_hostName; //!< Web host name - unsigned short m_port; //!< Port used for connection with host + unsigned short m_port{0}; //!< Port used for connection with host }; } // namespace sf diff --git a/include/SFML/Network/Packet.hpp b/include/SFML/Network/Packet.hpp index 077f34bb..1467175d 100644 --- a/include/SFML/Network/Packet.hpp +++ b/include/SFML/Network/Packet.hpp @@ -432,10 +432,10 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - std::vector m_data; //!< Data stored in the packet - std::size_t m_readPos; //!< Current reading position in the packet - std::size_t m_sendPos; //!< Current send position in the packet (for handling partial sends) - bool m_isValid; //!< Reading state of the packet + std::vector m_data; //!< Data stored in the packet + std::size_t m_readPos{0}; //!< Current reading position in the packet + std::size_t m_sendPos{0}; //!< Current send position in the packet (for handling partial sends) + bool m_isValid{true}; //!< Reading state of the packet }; } // namespace sf diff --git a/include/SFML/Network/Socket.hpp b/include/SFML/Network/Socket.hpp index c47f61d4..d934f1a7 100644 --- a/include/SFML/Network/Socket.hpp +++ b/include/SFML/Network/Socket.hpp @@ -182,9 +182,9 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - Type m_type; //!< Type of the socket (TCP or UDP) - SocketHandle m_socket; //!< Socket descriptor - bool m_isBlocking; //!< Current blocking mode of the socket + Type m_type; //!< Type of the socket (TCP or UDP) + SocketHandle m_socket; //!< Socket descriptor + bool m_isBlocking{true}; //!< Current blocking mode of the socket }; } // namespace sf diff --git a/include/SFML/Network/TcpSocket.hpp b/include/SFML/Network/TcpSocket.hpp index aeb9eb84..4491da7b 100644 --- a/include/SFML/Network/TcpSocket.hpp +++ b/include/SFML/Network/TcpSocket.hpp @@ -219,11 +219,9 @@ private: //////////////////////////////////////////////////////////// struct PendingPacket { - PendingPacket(); - - std::uint32_t Size; //!< Data of packet size - std::size_t SizeReceived; //!< Number of size bytes received so far - std::vector Data; //!< Data of the packet + std::uint32_t Size{0}; //!< Data of packet size + std::size_t SizeReceived{0}; //!< Number of size bytes received so far + std::vector Data; //!< Data of the packet }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/Network/UdpSocket.hpp b/include/SFML/Network/UdpSocket.hpp index 0d4439e0..2f28c963 100644 --- a/include/SFML/Network/UdpSocket.hpp +++ b/include/SFML/Network/UdpSocket.hpp @@ -199,7 +199,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - std::vector m_buffer; //!< Temporary buffer holding the received data in Receive(Packet) + std::vector m_buffer{std::vector(MaxDatagramSize)}; //!< Temporary buffer holding the received data in Receive(Packet) }; } // namespace sf diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp index 82535570..b14f9b5f 100644 --- a/src/SFML/Network/Http.cpp +++ b/src/SFML/Network/Http.cpp @@ -140,12 +140,6 @@ bool Http::Request::hasField(const std::string& field) const } -//////////////////////////////////////////////////////////// -Http::Response::Response() : m_status(Status::ConnectionFailed), m_majorVersion(0), m_minorVersion(0) -{ -} - - //////////////////////////////////////////////////////////// const std::string& Http::Response::getField(const std::string& field) const { @@ -292,9 +286,7 @@ void Http::Response::parseFields(std::istream& in) //////////////////////////////////////////////////////////// -Http::Http() : m_host(), m_port(0) -{ -} +Http::Http() = default; //////////////////////////////////////////////////////////// diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index ee0c6184..08205d31 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -36,9 +36,7 @@ namespace sf { //////////////////////////////////////////////////////////// -Packet::Packet() : m_readPos(0), m_sendPos(0), m_isValid(true) -{ -} +Packet::Packet() = default; //////////////////////////////////////////////////////////// diff --git a/src/SFML/Network/Socket.cpp b/src/SFML/Network/Socket.cpp index 87ec4113..88b0a747 100644 --- a/src/SFML/Network/Socket.cpp +++ b/src/SFML/Network/Socket.cpp @@ -35,7 +35,7 @@ namespace sf { //////////////////////////////////////////////////////////// -Socket::Socket(Type type) : m_type(type), m_socket(priv::SocketImpl::invalidSocket()), m_isBlocking(true) +Socket::Socket(Type type) : m_type(type), m_socket(priv::SocketImpl::invalidSocket()) { } diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index 608030bb..00f50d7b 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -425,10 +425,4 @@ Socket::Status TcpSocket::receive(Packet& packet) return Status::Done; } - -//////////////////////////////////////////////////////////// -TcpSocket::PendingPacket::PendingPacket() : Size(0), SizeReceived(0), Data() -{ -} - } // namespace sf diff --git a/src/SFML/Network/UdpSocket.cpp b/src/SFML/Network/UdpSocket.cpp index 0db6a92b..0e0df54c 100644 --- a/src/SFML/Network/UdpSocket.cpp +++ b/src/SFML/Network/UdpSocket.cpp @@ -38,7 +38,7 @@ namespace sf { //////////////////////////////////////////////////////////// -UdpSocket::UdpSocket() : Socket(Type::Udp), m_buffer(MaxDatagramSize) +UdpSocket::UdpSocket() : Socket(Type::Udp) { }