Public Types |
| enum | MaxSize_e { MAX_SIZE = 20
} |
Public Member Functions |
| | Address () |
| | Address (uint8_t type, const uint8_t *buffer, uint8_t len) |
|
| Address (const Address &address) |
|
Address & | operator= (const Address &address) |
| bool | IsInvalid (void) const |
| uint8_t | GetLength (void) const |
| uint32_t | CopyTo (uint8_t buffer[MAX_SIZE]) const |
| uint32_t | CopyAllTo (uint8_t *buffer, uint8_t len) const |
| uint32_t | CopyFrom (const uint8_t *buffer, uint8_t len) |
| uint32_t | CopyAllFrom (const uint8_t *buffer, uint8_t len) |
| bool | CheckCompatible (uint8_t type, uint8_t len) const |
| bool | IsMatchingType (uint8_t type) const |
| uint32_t | GetSerializedSize (void) const |
| void | Serialize (TagBuffer buffer) const |
| void | Deserialize (TagBuffer buffer) |
Static Public Member Functions |
| static uint8_t | Register (void) |
Friends |
|
bool | operator== (const Address &a, const Address &b) |
|
bool | operator< (const Address &a, const Address &b) |
|
std::ostream & | operator<< (std::ostream &os, const Address &address) |
|
std::istream & | operator>> (std::istream &is, Address &address) |
a polymophic address class
This class is very similar in design and spirit to the BSD sockaddr structure: they are both used to hold multiple types of addresses together with the type of the address.
A new address class defined by a user needs to:
- allocate a type id with Address::Register
- provide a method to convert his new address to an Address instance. This method is typically a member method named ConvertTo: Address MyAddress::ConvertTo (void) const;
- provide a method to convert an Address instance back to an instance of his new address type. This method is typically a static member method of his address class named ConvertFrom: static MyAddress MyAddress::ConvertFrom (const Address &address);
- the ConvertFrom method is expected to check that the type of the input Address instance is compatible with its own type.
Typical code to create a new class type looks like:
class MyAddress
{
public:
Address ConvertTo (void) const;
static MyAddress ConvertFrom (void);
private:
static uint8_t GetType (void);
};
Address MyAddress::ConvertTo (void) const
{
return Address (GetType (), m_buffer, 2);
}
MyAddress MyAddress::ConvertFrom (const Address &address)
{
MyAddress ad;
NS_ASSERT (address.CheckCompatible (GetType (), 2));
address.CopyTo (ad.m_buffer, 2);
return ad;
}
uint8_t MyAddress::GetType (void)
{
static uint8_t type = Address::Register ();
return type;
}