OverSim
I3IdentifierStack.cc
Go to the documentation of this file.
1 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 
24 #include "I3IdentifierStack.h"
25 
26 using namespace std;
27 
28 void I3IdentifierStack::push(const I3Identifier &identifier)
29 {
30  I3SubIdentifier id;
31 
32  id.setIdentifier(identifier);
33  stack.push_back(id);
34 }
35 
36 void I3IdentifierStack::push(const IPvXAddress &ip, int port)
37 {
38  I3IPAddress ipAddress;
39 
40  ipAddress.setIp(ip);
41  ipAddress.setPort(port);
42  push(ipAddress);
43 }
44 
46 {
47  I3SubIdentifier id;
48 
49  id.setIPAddress(ip);
50  stack.push_back(id);
51 }
52 
54 {
55  list<I3SubIdentifier>::const_iterator it;
56 
57  for (it = s.stack.begin(); it != s.stack.end(); it++) {
58  stack.push_back(*it);
59  }
60 }
61 
63 {
64  return stack.back();
65 }
66 
68 {
69  return stack.back();
70 }
71 
73 {
74  stack.pop_back();
75 }
76 
77 
79 {
80  int cmp;
81 
82  if (stack.size() != s.size()) {
83  return stack.size() - s.size();
84  }
85 
86  list<I3SubIdentifier>::const_iterator it0 = stack.begin();
87  list<I3SubIdentifier>::const_iterator it1 = s.stack.begin();
88 
89  for (; it0 != stack.end(); it0++, it1++) {
90  //for (uint i = 0; i < stack.size(); i++) {
91  cmp = it0->compareTo(*it1);
92  //cmp = stack[i].compareTo(s.stack[i]);
93  if (cmp != 0) return cmp;
94  }
95  return 0;
96 }
97 
98 
100 {
101  stack.clear();
102 }
103 
104 uint32_t I3IdentifierStack::size() const
105 {
106  return stack.size();
107 }
108 
110  int len = 0;
111  list<I3SubIdentifier>::const_iterator it;
112 
113  for (it = stack.begin(); it != stack.end(); it++) {
114  len += it->length();
115  }
116  return len + 16; /* the size variable */
117 }
118 
120  list<I3SubIdentifier>::iterator it;
121 
122  for (it = stack.begin(); it != stack.end(); it++) {
123  if (it->getType() == I3SubIdentifier::IPAddress && it->getIPAddress() == source) {
124  it->setIPAddress(dest);
125  }
126  }
127 
128 }
129 
130 std::ostream& operator<<(std::ostream& os, const I3IdentifierStack &s) {
131  list<I3SubIdentifier>::const_iterator it;
132 
133  for (it = s.stack.begin(); it != s.stack.end(); it++) {
134  os << *it << ", ";
135  }
136  return os;
137 }
138