Files
Tower-Defense/include/td/network/IPAddress.h
Persson-dev 7a1db0305d
All checks were successful
Linux arm64 / Build (push) Successful in 1m27s
fix build
2025-03-19 19:04:38 +01:00

58 lines
1.3 KiB
C++

#ifndef NETWORK_IPADDRESS_H_
#define NETWORK_IPADDRESS_H_
#include <string>
#include <iosfwd>
#include <vector>
#include <cstdint>
namespace td {
namespace network {
/* IPv4 address */
class IPAddress {
private:
std::uint32_t m_Address;
bool m_Valid;
public:
/* Create an invalid address */
IPAddress() noexcept;
/* Initialize by string IP */
IPAddress(const std::string& str);
/* Initialize by string IP */
IPAddress(const std::wstring& str);
/* Initialize by octets */
IPAddress(std::uint8_t octet1, std::uint8_t octet2, std::uint8_t octet3, std::uint8_t octet4) noexcept;
/* Get the specific octet. 1-4 */
std::uint8_t GetOctet(std::uint8_t num) const;
/* Set the specific octet. 1-4 */
void SetOctet(std::uint8_t num, std::uint8_t value);
/* Make sure the IP is valid. It will be invalid if the host wasn't found. */
bool IsValid() const noexcept { return m_Valid; }
std::string ToString() const;
static IPAddress LocalAddress();
bool operator==(const IPAddress& right);
bool operator!=(const IPAddress& right);
bool operator==(bool b);
};
typedef std::vector<IPAddress> IPAddresses;
std::ostream& operator<<(std::ostream& os, const IPAddress& addr);
std::wostream& operator<<(std::wostream& os, const IPAddress& addr);
} // ns network
} // ns td
#endif