tool::addr< ValueType, N, HexNotation, SepNotation > Struct Template Reference

Generic network address. More...

#include <wipal/tool/addr.hh>

List of all members.

Public Member Functions

 addr ()
 addr (const void *a)
 addr (const std::string &)
 addr (std::istream &)
std::istream & read (std::istream &)
void dump (void *) const
Comparison operators
bool operator< (const addr &) const
bool operator== (const addr &) const
bool operator!= (const addr &) const
Address' bytes access
ValueType & operator[] (unsigned)
const ValueType & operator[] (unsigned) const

Static Public Member Functions

static const addrnull ()
static const addrbroadcast ()


Detailed Description

template<class ValueType, unsigned N, bool HexNotation, char SepNotation>
struct tool::addr< ValueType, N, HexNotation, SepNotation >

Generic network address.

Protocol-agnostic network address, considered as a sequence of N values of type ValueType. For instance, IPv4 addresses are 4 uint8_t, MAC addresses are 6 uint8_t, and IPv6 addresses are 8 uint16_t. HexNotation indicates whether the address' string representation uses hexadecimal or decimal values. SepNotation is the character one should use to separate bytes in the string representation.


Constructor & Destructor Documentation

template<class VT , unsigned N, bool HN, char SN>
tool::addr< VT, N, HN, SN >::addr (  )  [inline]

Construct a null address.

template<class VT , unsigned N, bool HN, char SN>
tool::addr< VT, N, HN, SN >::addr ( const void *  a  )  [inline]

Construct an address from a memory location.

An alternative to using this constructor is to static_cast the memory location:

 typedef addr< // ...
               > addr_t;

 void* p = // To some memory containing an address.

 std::cout << *static_cast<addr_t*> (p) << std::endl;

template<class VT , unsigned N, bool HN, char SN>
tool::addr< VT, N, HN, SN >::addr ( const std::string &  str  )  [inline]

Construct an address from a string representation.

Example:

 addr<uint8_t, 6, true,  ':'> mac (std::string ("00:16:ec:92:84:b8"));
 addr<uint8_t, 4, false, '.'> ip4 (std::string ("192.168.1.1"));

template<class VT , unsigned N, bool HN, char SN>
tool::addr< VT, N, HN, SN >::addr ( std::istream &  is  )  [inline]

Construct an address from a stream (the address appears in the stream as a string representation).

 addr<uint8_t, 6, true, ':'> a (std::cin); // E.g. with 00:16:ec:92:84:b8
                                                 // on standard input.


Member Function Documentation

template<class VT , unsigned N, bool HN, char SN>
const addr< VT, N, HN, SN > & tool::addr< VT, N, HN, SN >::broadcast (  )  [inline, static]

Get a broadcast address (every byte is set to 255).

template<class VT , unsigned N, bool HN, char SN>
void tool::addr< VT, N, HN, SN >::dump ( void *  a  )  const [inline]

Copy to a memory location.

template<class VT , unsigned N, bool HN, char SN>
const addr< VT, N, HN, SN > & tool::addr< VT, N, HN, SN >::null (  )  [inline, static]

Get a null address (every byte is set to 0).

template<class VT , unsigned N, bool HN, char SN>
std::istream & tool::addr< VT, N, HN, SN >::read ( std::istream &  is  )  [inline]

Set the current address according to a string representation read from a stream.


The documentation for this struct was generated from the following files:

Generated on Wed Apr 22 22:52:43 2009 for wipal by  doxygen 1.5.8