diff --git a/include/SFML/Network/Packet.hpp b/include/SFML/Network/Packet.hpp index a4a2cb73..61baa244 100644 --- a/include/SFML/Network/Packet.hpp +++ b/include/SFML/Network/Packet.hpp @@ -46,6 +46,9 @@ class UdpSocket; //////////////////////////////////////////////////////////// class SFML_API Packet { + // A bool-like type that cannot be converted to integer or pointer types + typedef bool (Packet::*BoolType)(std::size_t); + public : //////////////////////////////////////////////////////////// @@ -125,6 +128,8 @@ public : //////////////////////////////////////////////////////////// bool EndOfPacket() const; +public: + //////////////////////////////////////////////////////////// /// \brief Test the validity of the packet, for reading /// @@ -154,12 +159,16 @@ public : /// } /// \endcode /// + /// Don't focus on the return type, it's equivalent to bool but + /// it disallows unwanted implicit conversions to integer or + /// pointer types. + /// /// \return True if last data extraction from packet was successful /// /// \see EndOfPacket /// //////////////////////////////////////////////////////////// - operator void*() const; + operator BoolType() const; //////////////////////////////////////////////////////////// /// Overloads of operator >> to read data from the packet @@ -204,6 +213,13 @@ private : friend class TcpSocket; friend class UdpSocket; + //////////////////////////////////////////////////////////// + /// Disallow comparisons between packets + /// + //////////////////////////////////////////////////////////// + bool operator ==(const Packet& right) const; + bool operator !=(const Packet& right) const; + //////////////////////////////////////////////////////////// /// \brief Check if the packet can extract a given number of bytes /// diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index 740ca39f..0a747360 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -92,9 +92,9 @@ bool Packet::EndOfPacket() const //////////////////////////////////////////////////////////// -Packet::operator void*() const +Packet::operator BoolType() const { - return myIsValid ? const_cast(this) : NULL; + return myIsValid ? &Packet::CheckSize : NULL; }