From 72b49a3592788efb251bc75efc04e76c92ebd9de Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Thu, 11 Mar 2010 14:27:57 +0000 Subject: [PATCH] Made sf::IPAddress comparison operators non-member Minor fix in sf::Clock API documentation git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1447 4e206d99-4929-0410-ac5d-dfc041789085 --- include/SFML/Network/IPAddress.hpp | 134 +++++++++++++++-------------- include/SFML/System/Clock.hpp | 4 +- src/SFML/Network/IPAddress.cpp | 42 +++------ 3 files changed, 85 insertions(+), 95 deletions(-) diff --git a/include/SFML/Network/IPAddress.hpp b/include/SFML/Network/IPAddress.hpp index 072faa57..d29d4d89 100644 --- a/include/SFML/Network/IPAddress.hpp +++ b/include/SFML/Network/IPAddress.hpp @@ -130,66 +130,6 @@ public : //////////////////////////////////////////////////////////// static IPAddress GetPublicAddress(float timeout = 0.f); - //////////////////////////////////////////////////////////// - /// Comparison operator == - /// - /// \param other : Address to compare - /// - /// \return True if *this == other - /// - //////////////////////////////////////////////////////////// - bool operator ==(const IPAddress& other) const; - - //////////////////////////////////////////////////////////// - /// Comparison operator != - /// - /// \param other : Address to compare - /// - /// \return True if *this != other - /// - //////////////////////////////////////////////////////////// - bool operator !=(const IPAddress& other) const; - - //////////////////////////////////////////////////////////// - /// Comparison operator < - /// - /// \param other : Address to compare - /// - /// \return True if *this < other - /// - //////////////////////////////////////////////////////////// - bool operator <(const IPAddress& other) const; - - //////////////////////////////////////////////////////////// - /// Comparison operator > - /// - /// \param other : Address to compare - /// - /// \return True if *this > other - /// - //////////////////////////////////////////////////////////// - bool operator >(const IPAddress& other) const; - - //////////////////////////////////////////////////////////// - /// Comparison operator <= - /// - /// \param other : Address to compare - /// - /// \return True if *this <= other - /// - //////////////////////////////////////////////////////////// - bool operator <=(const IPAddress& other) const; - - //////////////////////////////////////////////////////////// - /// Comparison operator >= - /// - /// \param other : Address to compare - /// - /// \return True if *this >= other - /// - //////////////////////////////////////////////////////////// - bool operator >=(const IPAddress& other) const; - //////////////////////////////////////////////////////////// // Static member data //////////////////////////////////////////////////////////// @@ -204,10 +144,76 @@ private : }; //////////////////////////////////////////////////////////// -/// Operator >> overload to extract an address from an input stream +/// \brief Overload of == operator to compare two host addresses +/// +/// \param left Left operand (a host address) +/// \param right Right operand (a host address) +/// +/// \return True if both hosts are equal +/// +//////////////////////////////////////////////////////////// +SFML_API bool operator ==(const IPAddress& left, const IPAddress& right); + +//////////////////////////////////////////////////////////// +/// \brief Overload of != operator to compare two host addresses +/// +/// \param left Left operand (a host address) +/// \param right Right operand (a host address) +/// +/// \return True if both hosts are different +/// +//////////////////////////////////////////////////////////// +SFML_API bool operator !=(const IPAddress& left, const IPAddress& right); + +//////////////////////////////////////////////////////////// +/// \brief Overload of < operator to compare two host addresses +/// +/// \param left Left operand (a host address) +/// \param right Right operand (a host address) +/// +/// \return True if \a left is lesser than \a right +/// +//////////////////////////////////////////////////////////// +SFML_API bool operator <(const IPAddress& left, const IPAddress& right); + +//////////////////////////////////////////////////////////// +/// \brief Overload of > operator to compare two host addresses +/// +/// \param left Left operand (a host address) +/// \param right Right operand (a host address) +/// +/// \return True if \a left is greater than \a right +/// +//////////////////////////////////////////////////////////// +SFML_API bool operator >(const IPAddress& left, const IPAddress& right); + +//////////////////////////////////////////////////////////// +/// \brief Overload of <= operator to compare two host addresses +/// +/// \param left Left operand (a host address) +/// \param right Right operand (a host address) +/// +/// \return True if \a left is lesser or equal than \a right +/// +//////////////////////////////////////////////////////////// +SFML_API bool operator <=(const IPAddress& left, const IPAddress& right); + +//////////////////////////////////////////////////////////// +/// \brief Overload of >= operator to compare two host addresses +/// +/// \param left Left operand (a host address) +/// \param right Right operand (a host address) +/// +/// \return True if \a left is greater or equal than \a right +/// +//////////////////////////////////////////////////////////// +SFML_API bool operator >=(const IPAddress& left, const IPAddress& right); + +//////////////////////////////////////////////////////////// +/// Operator >> overload to extract an host address from an input stream /// /// \param Stream : Input stream -/// \param Address : Address to extract +/// \param Address : Host address to extract /// /// \return Reference to the input stream /// @@ -215,10 +221,10 @@ private : SFML_API std::istream& operator >>(std::istream& stream, IPAddress& address); //////////////////////////////////////////////////////////// -/// Operator << overload to print an address to an output stream +/// Operator << overload to print an host address to an output stream /// /// \param Stream : Output stream -/// \param Address : Address to print +/// \param Address : Host address to print /// /// \return Reference to the output stream /// diff --git a/include/SFML/System/Clock.hpp b/include/SFML/System/Clock.hpp index 6fb6b845..55be19c1 100644 --- a/include/SFML/System/Clock.hpp +++ b/include/SFML/System/Clock.hpp @@ -87,8 +87,8 @@ private : /// \class sf::Clock /// /// sf::Clock is a lightweight class for measuring time. -/// Its accuray depends on the underlying OS, but you can generally -/// expect a 1 ms precision. +/// Its resolution depends on the underlying OS, but you can generally +/// expect a 1 ms resolution. /// /// Usage example: /// \code diff --git a/src/SFML/Network/IPAddress.cpp b/src/SFML/Network/IPAddress.cpp index cc01b05f..accfbcc2 100644 --- a/src/SFML/Network/IPAddress.cpp +++ b/src/SFML/Network/IPAddress.cpp @@ -36,7 +36,7 @@ namespace sf //////////////////////////////////////////////////////////// /// Static member data //////////////////////////////////////////////////////////// -const IPAddress IPAddress::LocalHost("127.0.0.1"); +const IPAddress IPAddress::LocalHost(127, 0, 0, 1); //////////////////////////////////////////////////////////// @@ -221,61 +221,47 @@ IPAddress IPAddress::GetPublicAddress(float timeout) //////////////////////////////////////////////////////////// -/// Comparison operator == -//////////////////////////////////////////////////////////// -bool IPAddress::operator ==(const IPAddress& other) const +bool operator ==(const IPAddress& left, const IPAddress& right) { - return myAddress == other.myAddress; + return left.ToInteger() == right.ToInteger(); } //////////////////////////////////////////////////////////// -/// Comparison operator != -//////////////////////////////////////////////////////////// -bool IPAddress::operator !=(const IPAddress& other) const +bool operator !=(const IPAddress& left, const IPAddress& right) { - return myAddress != other.myAddress; + return !(left == right); } //////////////////////////////////////////////////////////// -/// Comparison operator < -//////////////////////////////////////////////////////////// -bool IPAddress::operator <(const IPAddress& other) const +bool operator <(const IPAddress& left, const IPAddress& right) { - return myAddress < other.myAddress; + return left.ToInteger() < right.ToInteger(); } //////////////////////////////////////////////////////////// -/// Comparison operator > -//////////////////////////////////////////////////////////// -bool IPAddress::operator >(const IPAddress& other) const +bool operator >(const IPAddress& left, const IPAddress& right) { - return myAddress > other.myAddress; + return right < left; } //////////////////////////////////////////////////////////// -/// Comparison operator <= -//////////////////////////////////////////////////////////// -bool IPAddress::operator <=(const IPAddress& other) const +bool operator <=(const IPAddress& left, const IPAddress& right) { - return myAddress <= other.myAddress; + return !(right < left); } //////////////////////////////////////////////////////////// -/// Comparison operator >= -//////////////////////////////////////////////////////////// -bool IPAddress::operator >=(const IPAddress& other) const +bool operator >=(const IPAddress& left, const IPAddress& right) { - return myAddress >= other.myAddress; + return !(left < right); } -//////////////////////////////////////////////////////////// -/// Operator >> overload to extract an address from an input stream //////////////////////////////////////////////////////////// std::istream& operator >>(std::istream& stream, IPAddress& address) { @@ -287,8 +273,6 @@ std::istream& operator >>(std::istream& stream, IPAddress& address) } -//////////////////////////////////////////////////////////// -/// Operator << overload to print an address to an output stream //////////////////////////////////////////////////////////// std::ostream& operator <<(std::ostream& stream, const IPAddress& address) {