CUGL 2.5
Cornell University Game Library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
cugl::net::InetAddress Class Reference

#include <CUInetAddress.h>

Inheritance diagram for cugl::net::InetAddress:
cugl::net::ICEAddress

Public Types

enum class  Type : int { INVALID = 0 , IPV4 = 1 , IPV6 = 2 , HOSTNAME = 3 }
 

Public Member Functions

 InetAddress ()
 
 InetAddress (uint16_t port)
 
 InetAddress (const std::string address, uint16_t port=0)
 
 InetAddress (const std::shared_ptr< JsonValue > &prefs)
 
 InetAddress (const InetAddress &src)=default
 
 InetAddress (InetAddress &&src)=default
 
 ~InetAddress ()
 
InetAddressoperator= (const InetAddress &src)=default
 
InetAddressoperator= (InetAddress &&src)=default
 
InetAddressset (const InetAddress &src)
 
InetAddressset (const std::shared_ptr< InetAddress > &src)
 
virtual InetAddressset (const std::shared_ptr< JsonValue > &pref)
 
virtual const std::string toString () const
 
Type getType () const
 
bool isValid () const
 

Public Attributes

std::string address
 
uint16_t port
 

Detailed Description

This class represents an internet address

This class is effectively a simple struct. All attributes are publicly available and we do not use the standard CUGL shared pointer architecture. Internet addresses are designed to be use on the stack, though you can combine them with share pointers if you wish.

This class does have methods for validating an address, as well as determining its type (IPV4, IPV6 or Hostname). The latter is important for converting the address to a string, as IPV6 addresses must be inclosed in brackets when combined with the port. Because the attributes are publicly accessible, none of this information is cached. Instead, it is computed on demand as necessary.

Member Enumeration Documentation

◆ Type

enum class cugl::net::InetAddress::Type : int
strong

This enum represents the interet address type.

This value allows us to have a single class that supports both IPV4 and IPV6 address values.

Enumerator
INVALID 

Indicates that the address is not one of the given types

IPV4 

Indicates that the IP address is formatted for IPV4.

IPV6 

Indicates that the IP address is formatted for IPV6.

HOSTNAME 

Indicates that the IP address refers to a host name.

Like IPV4 addresses, hostnames are separated by dots. A hostname is identifiable because the toplevel domain must be alphabetic.

Constructor & Destructor Documentation

◆ InetAddress() [1/6]

cugl::net::InetAddress::InetAddress ( )

Creates an internet address to refer to the localhost

The address will be the hostname "localhost". The port will be 0. The constructor does not perform any validation that the combined address port are reachable.

◆ InetAddress() [2/6]

cugl::net::InetAddress::InetAddress ( uint16_t  port)

Creates an internet address to refer to the localhost

The address will be the hostname "localhost". The constructor does not perform any validation that the combined address port are reachable.

Parameters
portThe address port

◆ InetAddress() [3/6]

cugl::net::InetAddress::InetAddress ( const std::string  address,
uint16_t  port = 0 
)

Creates an internet address for the given address.

The constructor does not perform any validation that the combined address and port are reachable.

Parameters
addressThe internet address
portThe address port

◆ InetAddress() [4/6]

cugl::net::InetAddress::InetAddress ( const std::shared_ptr< JsonValue > &  prefs)

Creates this internet address using a JSON entry.

The JSON value should be an object with at least two keys: "address" and "port". The "port" should be an integer.

Parameters
prefsThe address settings

◆ InetAddress() [5/6]

cugl::net::InetAddress::InetAddress ( const InetAddress src)
default

Creates a copy of the given internet address.

This copy constructor is provided so that internet addresses may be safely used on the stack, without the use of pointers.

Parameters
srcThe original internet address to copy

◆ InetAddress() [6/6]

cugl::net::InetAddress::InetAddress ( InetAddress &&  src)
default

Creates a new internet address with the resources of the given one.

This move constructor is provided so that internet addresses may be used efficiently on the stack, without the use of pointers.

Parameters
srcThe original address contributing resources

◆ ~InetAddress()

cugl::net::InetAddress::~InetAddress ( )
inline

Deletes this internet address, disposing all resources

Member Function Documentation

◆ getType()

Type cugl::net::InetAddress::getType ( ) const

Returns the type of this address.

The method only checks the syntax of the address, and not whether the address is actually reachable. As the address attributes are publicly accessible, this value is not cached, but is instead recomputed each time this method is called.

Returns
the type of this address.

◆ isValid()

bool cugl::net::InetAddress::isValid ( ) const
inline

Returns the true if this address is syntactically valid.

The method only checks the syntax of the address, and not whether the address is actually reachable. As the address attributes are publicly accessible, this value is not cached, but is instead recomputed each time this method is called.

Returns
the true if this address is syntactically valid.

◆ operator=() [1/2]

InetAddress & cugl::net::InetAddress::operator= ( const InetAddress src)
default

Assigns this address to be a copy of the given internet address.

Parameters
srcThe address to copy
Returns
a reference to this address for chaining purposes.

◆ operator=() [2/2]

InetAddress & cugl::net::InetAddress::operator= ( InetAddress &&  src)
default

Assigns this address to have the resources of the given internet address.

Parameters
srcThe address to take resources from
Returns
a reference to this address for chaining purposes.

◆ set() [1/3]

InetAddress & cugl::net::InetAddress::set ( const InetAddress src)

Assigns this address to be a copy of the given internet address.

Parameters
srcThe address to copy
Returns
a reference to this address for chaining purposes.

◆ set() [2/3]

InetAddress & cugl::net::InetAddress::set ( const std::shared_ptr< InetAddress > &  src)

Assigns this address to be a copy of the given internet address.

Parameters
srcThe address to copy
Returns
a reference to this address for chaining purposes.

◆ set() [3/3]

virtual InetAddress & cugl::net::InetAddress::set ( const std::shared_ptr< JsonValue > &  pref)
virtual

Assigns this address according to the given JSON object

The JSON value should be an object with at least two keys: "address" and "port". The "port" should be an integer.

Parameters
prefThe address settings
Returns
a reference to this address for chaining purposes.

Reimplemented in cugl::net::ICEAddress.

◆ toString()

virtual const std::string cugl::net::InetAddress::toString ( ) const
virtual

Returns a string representation of this address.

The string with combine the address string with the port, separated by a colon. No attempt is made to normalize IPV4 or IPV6 addresses.

Returns
a string representation of this address.

Reimplemented in cugl::net::ICEAddress.

Member Data Documentation

◆ address

std::string cugl::net::InetAddress::address

The internet address

◆ port

uint16_t cugl::net::InetAddress::port

The address port


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