Removed IpAddress::IsValid(), added IpAddress::None

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1456 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-03-13 09:50:24 +00:00
parent 81fd4c5d1d
commit 691eea4c69
6 changed files with 10 additions and 37 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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
{