An IPv4 address used as a URL's host, e.g. "192.0.2.1". More...
#include <urlparser.h>
Collaboration diagram for urlparser::ipv4:Public Member Functions | |
| ipv4 () noexcept=default | |
| Default-constructs 0.0.0.0. | |
| ipv4 (std::string_view text) | |
| Parse an IPv4 address from text. | |
| std::array< uint8_t, 4 > | bytes () const noexcept |
| The address as 4 bytes, most significant first. | |
| ipv4 & | operator++ () noexcept |
| ipv4 | operator++ (int) noexcept |
| ipv4 & | operator+= (int64_t delta) noexcept |
Steps the address by delta, wrapping around mod 2^32. | |
| ipv4 & | operator-- () noexcept |
| ipv4 | operator-- (int) noexcept |
| ipv4 & | operator-= (int64_t delta) noexcept |
| std::string | str () const |
| Canonical dotted-decimal text form, e.g. "192.0.2.1". | |
| uint32_t | to_uint32 () const noexcept |
| The address as a 32-bit integer (host byte order). Always valid - never throws. | |
Static Public Member Functions | |
| static ipv4 | from_uint32 (uint32_t address) noexcept |
| Constructs from a 32-bit representation (host byte order), e.g. 0xC0A80101 = 192.168.1.1. | |
| static ipv4 | from_url (std::string_view url) |
| Extract the host from a URL and parse it as an IPv4 address. | |
| static bool | is_valid (std::string_view text) noexcept |
| Checks validity without throwing or constructing. | |
Friends | |
| bool | operator!= (const ipv4 &a, const ipv4 &b) noexcept |
| ipv4 | operator+ (ipv4 lhs, int64_t delta) noexcept |
| int64_t | operator- (const ipv4 &a, const ipv4 &b) noexcept |
| Distance between two addresses (always fits in int64_t: the range is only 2^32). | |
| ipv4 | operator- (ipv4 lhs, int64_t delta) noexcept |
| bool | operator< (const ipv4 &a, const ipv4 &b) noexcept |
| bool | operator<= (const ipv4 &a, const ipv4 &b) noexcept |
| bool | operator== (const ipv4 &a, const ipv4 &b) noexcept |
| bool | operator> (const ipv4 &a, const ipv4 &b) noexcept |
| bool | operator>= (const ipv4 &a, const ipv4 &b) noexcept |
An IPv4 address used as a URL's host, e.g. "192.0.2.1".
A plain 32-bit value type (internally just a uint32_t), so every operation - comparisons, ++/–/+=/-=, to_uint32() - is a single native integer instruction; there's no PSL, no subdomain/domain/suffix, and no family tag to branch on the way a combined IPv4-or-IPv6 type would need.
Parsing/formatting use the platform's own inet_pton/inet_ntop (POSIX) or InetPtonA/InetNtopA (Windows) rather than hand-written: even IPv4's text format has edge cases (leading zeros, legacy octal/hex octets) better left to a battle-tested implementation than re-derived here.
|
defaultnoexcept |
Default-constructs 0.0.0.0.
| urlparser::ipv4::ipv4 | ( | std::string_view | text | ) |
Parse an IPv4 address from text.
| std::invalid_argument | if text isn't a valid IPv4 address. |
|
noexcept |
The address as 4 bytes, most significant first.
|
staticnoexcept |
Constructs from a 32-bit representation (host byte order), e.g. 0xC0A80101 = 192.168.1.1.
|
static |
Extract the host from a URL and parse it as an IPv4 address.
| std::invalid_argument | if the URL's host isn't a valid IPv4 address. |
|
staticnoexcept |
Checks validity without throwing or constructing.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Steps the address by delta, wrapping around mod 2^32.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
| std::string urlparser::ipv4::str | ( | ) | const |
Canonical dotted-decimal text form, e.g. "192.0.2.1".
|
inlinenoexcept |
The address as a 32-bit integer (host byte order). Always valid - never throws.
Distance between two addresses (always fits in int64_t: the range is only 2^32).