Loading...
Searching...
No Matches
urlparser::ipv6 Class Reference

An IPv6 address used as a URL's host, e.g. "2001:db8::1". More...

#include <urlparser.h>

+ Collaboration diagram for urlparser::ipv6:

Public Member Functions

 ipv6 () noexcept=default
 Default-constructs "::" (all zero).
 
 ipv6 (std::string_view text)
 Parse an IPv6 address from text. Accepts a bracketed literal ("[::1]", as it appears in a URL's host component) or a bare one ("::1").
 
std::array< uint8_t, 16 > bytes () const noexcept
 The address as 16 bytes, most significant first.
 
uint64_t high64 () const noexcept
 The high 64 bits (first 8 bytes).
 
uint64_t low64 () const noexcept
 The low 64 bits (last 8 bytes).
 
ipv6 & operator++ () noexcept
 
ipv6 operator++ (int) noexcept
 
ipv6 & operator+= (int64_t delta) noexcept
 Steps the address by delta, wrapping around mod 2^128.
 
ipv6 & operator-- () noexcept
 
ipv6 operator-- (int) noexcept
 
ipv6 & operator-= (int64_t delta) noexcept
 
std::string str () const
 Canonical (RFC 5952) text form, no brackets: "2001:db8::1", not "[2001:db8::1]".
 

Static Public Member Functions

static ipv6 from_uint64_pair (uint64_t high, uint64_t low) noexcept
 Constructs from the two 64-bit halves (high64, then low64), in host byte order.
 
static ipv6 from_url (std::string_view url)
 Extract the host from a URL and parse it as an IPv6 address.
 
static bool is_valid (std::string_view text) noexcept
 Checks validity (bracketed or bare) without throwing or constructing.
 

Friends

bool operator!= (const ipv6 &a, const ipv6 &b) noexcept
 
ipv6 operator+ (ipv6 lhs, int64_t delta) noexcept
 
ipv6 operator- (ipv6 lhs, int64_t delta) noexcept
 
bool operator< (const ipv6 &a, const ipv6 &b) noexcept
 
bool operator<= (const ipv6 &a, const ipv6 &b) noexcept
 
bool operator== (const ipv6 &a, const ipv6 &b) noexcept
 
bool operator> (const ipv6 &a, const ipv6 &b) noexcept
 
bool operator>= (const ipv6 &a, const ipv6 &b) noexcept
 

Detailed Description

An IPv6 address used as a URL's host, e.g. "2001:db8::1".

A plain 128-bit value type, stored as two 64-bit halves (high64()/ low64()) since C++ has no portable 128-bit integer - arithmetic is two native 64-bit add-with-carry operations, not a byte-array loop.

Parsing/formatting use the platform's own inet_pton/inet_ntop (POSIX) or InetPtonA/InetNtopA (Windows): IPv6's text format (:: compression, embedded IPv4 tails, zone IDs on some platforms) has enough edge cases that a hand-written parser is far more likely to introduce bugs than to avoid them.

Constructor & Destructor Documentation

◆ ipv6() [1/2]

urlparser::ipv6::ipv6 ( )
defaultnoexcept

Default-constructs "::" (all zero).

◆ ipv6() [2/2]

urlparser::ipv6::ipv6 ( std::string_view  text)

Parse an IPv6 address from text. Accepts a bracketed literal ("[::1]", as it appears in a URL's host component) or a bare one ("::1").

Exceptions
std::invalid_argumentif text isn't a valid IPv6 address.

Member Function Documentation

◆ bytes()

std::array< uint8_t, 16 > urlparser::ipv6::bytes ( ) const
noexcept

The address as 16 bytes, most significant first.

◆ from_uint64_pair()

static ipv6 urlparser::ipv6::from_uint64_pair ( uint64_t  high,
uint64_t  low 
)
staticnoexcept

Constructs from the two 64-bit halves (high64, then low64), in host byte order.

◆ from_url()

static ipv6 urlparser::ipv6::from_url ( std::string_view  url)
static

Extract the host from a URL and parse it as an IPv6 address.

Exceptions
std::invalid_argumentif the URL's host isn't a valid IPv6 address.

◆ high64()

uint64_t urlparser::ipv6::high64 ( ) const
inlinenoexcept

The high 64 bits (first 8 bytes).

◆ is_valid()

static bool urlparser::ipv6::is_valid ( std::string_view  text)
staticnoexcept

Checks validity (bracketed or bare) without throwing or constructing.

◆ low64()

uint64_t urlparser::ipv6::low64 ( ) const
inlinenoexcept

The low 64 bits (last 8 bytes).

◆ operator++() [1/2]

ipv6 & urlparser::ipv6::operator++ ( )
inlinenoexcept

◆ operator++() [2/2]

ipv6 urlparser::ipv6::operator++ ( int  )
inlinenoexcept

◆ operator+=()

ipv6 & urlparser::ipv6::operator+= ( int64_t  delta)
inlinenoexcept

Steps the address by delta, wrapping around mod 2^128.

◆ operator--() [1/2]

ipv6 & urlparser::ipv6::operator-- ( )
inlinenoexcept

◆ operator--() [2/2]

ipv6 urlparser::ipv6::operator-- ( int  )
inlinenoexcept

◆ operator-=()

ipv6 & urlparser::ipv6::operator-= ( int64_t  delta)
inlinenoexcept

◆ str()

std::string urlparser::ipv6::str ( ) const

Canonical (RFC 5952) text form, no brackets: "2001:db8::1", not "[2001:db8::1]".

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const ipv6 &  a,
const ipv6 &  b 
)
friend

◆ operator+

ipv6 operator+ ( ipv6  lhs,
int64_t  delta 
)
friend

◆ operator-

ipv6 operator- ( ipv6  lhs,
int64_t  delta 
)
friend

◆ operator<

bool operator< ( const ipv6 &  a,
const ipv6 &  b 
)
friend

◆ operator<=

bool operator<= ( const ipv6 &  a,
const ipv6 &  b 
)
friend

◆ operator==

bool operator== ( const ipv6 &  a,
const ipv6 &  b 
)
friend

◆ operator>

bool operator> ( const ipv6 &  a,
const ipv6 &  b 
)
friend

◆ operator>=

bool operator>= ( const ipv6 &  a,
const ipv6 &  b 
)
friend

The documentation for this class was generated from the following file: