I3SubIdentifier Class Reference

A wrapper around either an I3IPAddress or an I3Identifier. More...

#include <I3SubIdentifier.h>

List of all members.

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.
I3IPAddressgetIPAddress ()
 Returns the IP address.
I3IdentifiergetIdentifier ()
 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)

Detailed Description

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.

Definition at line 37 of file I3SubIdentifier.h.


Member Enumeration Documentation

Identifier type.

Enumerator:
Invalid 
Identifier 

Type has not been set yet.

IPAddress 

Subidentifier refers to an I3Identifier.

Subidentifier refers to an I3IPAddress

Definition at line 40 of file I3SubIdentifier.h.

00040                         {
00041         Invalid,       
00042         Identifier,    
00043         IPAddress      
00044     };


Constructor & Destructor Documentation

I3SubIdentifier::I3SubIdentifier (  ) 

Constructor.

Definition at line 28 of file I3SubIdentifier.cc.

00029                                  :
00030         type(Invalid)
00031 {
}


Member Function Documentation

int I3SubIdentifier::compareTo ( const I3SubIdentifier id  )  const

Comparison function.

Definition at line 71 of file I3SubIdentifier.cc.

00072 {
00073     if (type != id.type) {
00074         return type - id.type;
00075     } else if (type == Identifier) {
00076         return identifier.compareTo(id.identifier);
00077     } else if (type == IPAddress) {
00078         if (ipAddress.getAddress() < id.ipAddress.getAddress()) return -1;
00079         else if (ipAddress.getAddress() == id.ipAddress.getAddress()) return ipAddress.getPort() - id.ipAddress.getPort();
00080         else return 1;
00081     }
00082     return 0;
00083 }

I3Identifier & I3SubIdentifier::getIdentifier (  ) 

Returns the identifier.

Returns:
Identifier referred to

Definition at line 63 of file I3SubIdentifier.cc.

Referenced by I3::handleUDPMessage(), I3BaseApp::sendPacket(), and I3::sendPacket().

00064 {
00065     if (type != Identifier) {
00066         // error!
00067     };
00068     return identifier;
00069 }

I3IPAddress & I3SubIdentifier::getIPAddress (  ) 

Returns the IP address.

Returns:
IP address referred to

Definition at line 55 of file I3SubIdentifier.cc.

Referenced by I3BaseApp::sendPacket().

00056 {
00057     if (type != IPAddress) {
00058         // error!
00059     }
00060     return ipAddress;
00061 }

I3SubIdentifier::IdentifierType I3SubIdentifier::getType (  )  const

Returns the subidentifier type.

Returns:
Subidentifier type

Definition at line 50 of file I3SubIdentifier.cc.

Referenced by I3::handleUDPMessage(), I3BaseApp::sendPacket(), and I3::sendPacket().

00051 {
00052     return type;
00053 }

int I3SubIdentifier::length (  )  const

Definition at line 85 of file I3SubIdentifier.cc.

00085                                   {
00086 //      return sizeof(type) + (type == IPAddress ? ipAddress.length() : identifier.length());
00087     return 1 + (type == IPAddress ? ipAddress.length() : identifier.length());
00088 }

void I3SubIdentifier::setIdentifier ( const I3Identifier id  ) 

Sets this identifier as an I3Identifier.

Parameters:
id Identifer to set to

Definition at line 40 of file I3SubIdentifier.cc.

00041 {
00042     type = Identifier;
00043 
00044     I3IPAddress zero; // initialized to zero
00045     ipAddress = zero; // set to clear
00046 
00047     identifier = id;
00048 }

void I3SubIdentifier::setIPAddress ( const I3IPAddress address  ) 

Sets this identifier as an I3IPAddress.

Parameters:
address IP address to set to

Definition at line 33 of file I3SubIdentifier.cc.

00034 {
00035     type = IPAddress;
00036     ipAddress = address;
00037     identifier.clear();
00038 }


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const I3SubIdentifier s 
) [friend]

Definition at line 90 of file I3SubIdentifier.cc.

00090                                                                  {
00091     if (s.type == I3SubIdentifier::Identifier) {
00092         os << s.identifier;
00093     } else {
00094         os << s.ipAddress;
00095     }
00096     return os;
00097 }


Member Data Documentation

Identifier referred to.

Definition at line 90 of file I3SubIdentifier.h.

Referenced by compareTo(), getIdentifier(), length(), operator<<(), setIdentifier(), and setIPAddress().

IP address referred to.

Definition at line 87 of file I3SubIdentifier.h.

Referenced by compareTo(), getIPAddress(), length(), operator<<(), setIdentifier(), and setIPAddress().

Type of subidentifier.

Definition at line 84 of file I3SubIdentifier.h.

Referenced by compareTo(), getIdentifier(), getIPAddress(), getType(), length(), operator<<(), setIdentifier(), and setIPAddress().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:17 2010 for OverSim by  doxygen 1.6.3