#include <I3SubIdentifier.h>
A wrapper around either an I3IPAddress or an I3Identifier. The I3 paper proposes an identifier stack that is "a list of identifiers that takes the form (id[1], id[2], ..., id[k]) where where id[i] is either an identifier or an address." To avoid confusion, the former identifier id[i] is called an I3SubIdentifier and the latter is the normal I3Identifier.
Public Types | |
enum | IdentifierType { Invalid, Identifier, IPAddress } |
Identifier type. More... | |
Public Member Functions | |
I3SubIdentifier () | |
Constructor. | |
void | setIPAddress (const I3IPAddress &address) |
Sets this identifier as an I3IPAddress. | |
void | setIdentifier (const I3Identifier &id) |
Sets this identifier as an I3Identifier. | |
IdentifierType | getType () const |
Returns the subidentifier type. | |
I3IPAddress & | getIPAddress () |
Returns the IP address. | |
I3Identifier & | getIdentifier () |
Returns the identifier. | |
int | compareTo (const I3SubIdentifier &) const |
Comparison function. | |
int | length () const |
Protected Attributes | |
IdentifierType | type |
Type of subidentifier. | |
I3IPAddress | ipAddress |
IP address referred to. | |
I3Identifier | identifier |
Identifier referred to. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const I3SubIdentifier &s) |
Identifier type.
Invalid | |
Identifier | Type has not been set yet. |
IPAddress |
Subidentifier refers to an I3Identifier.
Subidentifier refers to an I3IPAddress |
00040 { 00041 Invalid, 00042 Identifier, 00043 IPAddress 00044 };
void I3SubIdentifier::setIPAddress | ( | const I3IPAddress & | address | ) |
Sets this identifier as an I3IPAddress.
address | IP address to set to |
00028 { 00029 type = IPAddress; 00030 ipAddress = address; 00031 identifier.clear(); 00032 }
void I3SubIdentifier::setIdentifier | ( | const I3Identifier & | id | ) |
Sets this identifier as an I3Identifier.
id | Identifer to set to |
00035 { 00036 type = Identifier; 00037 00038 I3IPAddress zero; // initialized to zero 00039 ipAddress = zero; // set to clear 00040 00041 identifier = id; 00042 }
I3SubIdentifier::IdentifierType I3SubIdentifier::getType | ( | ) | const |
I3IPAddress & I3SubIdentifier::getIPAddress | ( | ) |
I3Identifier & I3SubIdentifier::getIdentifier | ( | ) |
Returns the identifier.
00058 { 00059 if (type != Identifier) { 00060 // error! 00061 }; 00062 return identifier; 00063 }
int I3SubIdentifier::compareTo | ( | const I3SubIdentifier & | id | ) | const |
Comparison function.
00066 { 00067 if (type != id.type) { 00068 return type - id.type; 00069 } else if (type == Identifier) { 00070 return identifier.compareTo(id.identifier); 00071 } else if (type == IPAddress) { 00072 if (ipAddress.ip < id.ipAddress.ip) return -1; 00073 else if (ipAddress.ip == id.ipAddress.ip) return ipAddress.port - id.ipAddress.port; 00074 else return 1; 00075 } 00076 return 0; 00077 }
int I3SubIdentifier::length | ( | ) | const |
std::ostream& operator<< | ( | std::ostream & | os, | |
const I3SubIdentifier & | s | |||
) | [friend] |
00084 { 00085 if (s.type == I3SubIdentifier::Identifier) { 00086 os << s.identifier; 00087 } else { 00088 os << s.ipAddress; 00089 } 00090 return os; 00091 }
IdentifierType I3SubIdentifier::type [protected] |
Type of subidentifier.
I3IPAddress I3SubIdentifier::ipAddress [protected] |
IP address referred to.
I3Identifier I3SubIdentifier::identifier [protected] |
Identifier referred to.