From 691eea4c6936f203e904c655ae373627a40a1004 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Sat, 13 Mar 2010 09:50:24 +0000 Subject: [PATCH] Removed IpAddress::IsValid(), added IpAddress::None git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1456 4e206d99-4929-0410-ac5d-dfc041789085 --- include/SFML/Network/IpAddress.hpp | 27 +++------------------------ samples/ftp/Ftp.cpp | 2 +- samples/sockets/TCP.cpp | 2 +- samples/sockets/UDP.cpp | 2 +- samples/voip/Client.cpp | 2 +- src/SFML/Network/IpAddress.cpp | 12 +++--------- 6 files changed, 10 insertions(+), 37 deletions(-) diff --git a/include/SFML/Network/IpAddress.hpp b/include/SFML/Network/IpAddress.hpp index 52179f790..d71d0633a 100644 --- a/include/SFML/Network/IpAddress.hpp +++ b/include/SFML/Network/IpAddress.hpp @@ -107,29 +107,6 @@ public : //////////////////////////////////////////////////////////// IpAddress(Uint32 address); - //////////////////////////////////////////////////////////// - /// \brief Check if the address is a valid one - /// - /// If the address was constructed from a decimal representation - /// (like "192.168.1.56") this function will always return true - /// unless the address is the special one 255.255.255.255. - /// If the address was constructed from a host name, it is - /// reported as beeing valid only if the host exists and could - /// be converted to a decimal IP address. - /// - /// Examples: - /// \begincode - /// bool b1 = sf::IpAddress("127.0.0.1").IsValid(); // true - /// bool b2 = sf::IpAddress("1.2.3.4").IsValid(); // true - /// bool b3 = sf::IpAddress("www.google.com").IsValid(); // true - /// bool b4 = sf::IpAddress("www.dfgfghqsd.com").IsValid(); // false - /// \endcode - /// - /// \return True if address has a valid syntax - /// - //////////////////////////////////////////////////////////// - bool IsValid() const; - //////////////////////////////////////////////////////////// /// \brief Get a string representation of the address /// @@ -203,6 +180,7 @@ public : //////////////////////////////////////////////////////////// // Static member data //////////////////////////////////////////////////////////// + static const IpAddress None; ///< Value representing an empty/invalid address static const IpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally) private : @@ -317,7 +295,8 @@ SFML_API std::ostream& operator <<(std::ostream& stream, const IpAddress& addres /// /// Usage example: /// \code -/// sf::IpAddress a1; // an invalid address +/// sf::IpAddress a0; // an invalid address +/// sf::IpAddress a1 = sf::IpAddress::None; // an invalid address (same as a0) /// sf::IpAddress a2("127.0.0.1"); // the local host address /// sf::IpAddress a3 = sf::IpAddress::LocalHost; // the local host address (same as a2) /// sf::IpAddress a4(192, 168, 1, 56); // a local address diff --git a/samples/ftp/Ftp.cpp b/samples/ftp/Ftp.cpp index 238adae0d..b7882aa5e 100644 --- a/samples/ftp/Ftp.cpp +++ b/samples/ftp/Ftp.cpp @@ -32,7 +32,7 @@ int main() std::cout << "Enter the FTP server address : "; std::cin >> address; } - while (!address.IsValid()); + while (address == sf::IpAddress::None); // Connect to the server sf::Ftp server; diff --git a/samples/sockets/TCP.cpp b/samples/sockets/TCP.cpp index 1800d64ce..124ffe065 100644 --- a/samples/sockets/TCP.cpp +++ b/samples/sockets/TCP.cpp @@ -19,7 +19,7 @@ void DoClientTCP(unsigned short port) std::cout << "Type address or name of the server to connect to : "; std::cin >> serverAddress; } - while (!serverAddress.IsValid()); + while (serverAddress == sf::IpAddress::None); // Create a TCP socket for communicating with server sf::SocketTCP client; diff --git a/samples/sockets/UDP.cpp b/samples/sockets/UDP.cpp index 7e6100190..fa520cb09 100644 --- a/samples/sockets/UDP.cpp +++ b/samples/sockets/UDP.cpp @@ -19,7 +19,7 @@ void DoClientUDP(unsigned short port) std::cout << "Type address or name of the server to send the message to : "; std::cin >> serverAddress; } - while (!serverAddress.IsValid()); + while (serverAddress == sf::IpAddress::None); // Create a UDP socket for communicating with server sf::SocketUDP client; diff --git a/samples/voip/Client.cpp b/samples/voip/Client.cpp index 12b0d217b..e397eece3 100644 --- a/samples/voip/Client.cpp +++ b/samples/voip/Client.cpp @@ -76,7 +76,7 @@ void DoClient(unsigned short port) std::cout << "Type address or name of the server to connect to : "; std::cin >> serverAddress; } - while (!serverAddress.IsValid()); + while (serverAddress == sf::IpAddress::None); // Create a TCP socket for communicating with server sf::SocketTCP socket; diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index 0fd96b406..846fc02a6 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -34,6 +34,7 @@ namespace sf { //////////////////////////////////////////////////////////// +const IpAddress IpAddress::None; const IpAddress IpAddress::LocalHost(127, 0, 0, 1); @@ -52,7 +53,7 @@ IpAddress::IpAddress(const std::string& address) myAddress = inet_addr(address.c_str()); // If not successful, try to convert it as a host name - if (!IsValid()) + if (myAddress == INADDR_NONE) { hostent* host = gethostbyname(address.c_str()); if (host) @@ -76,7 +77,7 @@ IpAddress::IpAddress(const char* address) myAddress = inet_addr(address); // If not successful, try to convert it as a host name - if (!IsValid()) + if (myAddress == INADDR_NONE) { hostent* host = gethostbyname(address); if (host) @@ -107,13 +108,6 @@ IpAddress::IpAddress(Uint32 address) } -//////////////////////////////////////////////////////////// -bool IpAddress::IsValid() const -{ - return myAddress != INADDR_NONE; -} - - //////////////////////////////////////////////////////////// std::string IpAddress::ToString() const {