00001 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH) 00002 // 00003 // This program is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU General Public License 00005 // as published by the Free Software Foundation; either version 2 00006 // of the License, or (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00016 // 00017 00024 #include "I3IdentifierStack.h" 00025 00026 using namespace std; 00027 00028 void I3IdentifierStack::push(const I3Identifier &identifier) 00029 { 00030 I3SubIdentifier id; 00031 00032 id.setIdentifier(identifier); 00033 stack.push_back(id); 00034 } 00035 00036 void I3IdentifierStack::push(const IPvXAddress &ip, int port) 00037 { 00038 I3IPAddress ipAddress; 00039 00040 ipAddress.setAddress(ip); 00041 ipAddress.setPort(port); 00042 push(ipAddress); 00043 } 00044 00045 void I3IdentifierStack::push(const I3IPAddress &ip) 00046 { 00047 I3SubIdentifier id; 00048 00049 id.setIPAddress(ip); 00050 stack.push_back(id); 00051 } 00052 00053 void I3IdentifierStack::push(const I3IdentifierStack &s) 00054 { 00055 list<I3SubIdentifier>::const_iterator it; 00056 00057 for (it = s.stack.begin(); it != s.stack.end(); it++) { 00058 stack.push_back(*it); 00059 } 00060 } 00061 00062 I3SubIdentifier &I3IdentifierStack::peek() 00063 { 00064 return stack.back(); 00065 } 00066 00067 const I3SubIdentifier &I3IdentifierStack::peek() const 00068 { 00069 return stack.back(); 00070 } 00071 00072 void I3IdentifierStack::pop() 00073 { 00074 stack.pop_back(); 00075 } 00076 00077 00078 int I3IdentifierStack::compareTo(const I3IdentifierStack &s) const 00079 { 00080 int cmp; 00081 00082 if (stack.size() != s.size()) { 00083 return stack.size() - s.size(); 00084 } 00085 00086 list<I3SubIdentifier>::const_iterator it0 = stack.begin(); 00087 list<I3SubIdentifier>::const_iterator it1 = s.stack.begin(); 00088 00089 for (; it0 != stack.end(); it0++, it1++) { 00090 //for (uint i = 0; i < stack.size(); i++) { 00091 cmp = it0->compareTo(*it1); 00092 //cmp = stack[i].compareTo(s.stack[i]); 00093 if (cmp != 0) return cmp; 00094 } 00095 return 0; 00096 } 00097 00098 00099 void I3IdentifierStack::clear() 00100 { 00101 stack.clear(); 00102 } 00103 00104 uint32_t I3IdentifierStack::size() const 00105 { 00106 return stack.size(); 00107 } 00108 00109 int I3IdentifierStack::length() const { 00110 int len = 0; 00111 list<I3SubIdentifier>::const_iterator it; 00112 00113 for (it = stack.begin(); it != stack.end(); it++) { 00114 len += it->length(); 00115 } 00116 return len + 16; /* the size variable */ 00117 } 00118 00119 void I3IdentifierStack::replaceAddress(const I3IPAddress &source, const I3IPAddress &dest) { 00120 list<I3SubIdentifier>::iterator it; 00121 00122 for (it = stack.begin(); it != stack.end(); it++) { 00123 if (it->getType() == I3SubIdentifier::IPAddress && it->getIPAddress() == source) { 00124 it->setIPAddress(dest); 00125 } 00126 } 00127 00128 } 00129 00130 std::ostream& operator<<(std::ostream& os, const I3IdentifierStack &s) { 00131 list<I3SubIdentifier>::const_iterator it; 00132 00133 for (it = s.stack.begin(); it != s.stack.end(); it++) { 00134 os << *it << ", "; 00135 } 00136 return os; 00137 } 00138