OverSim
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
I3SubIdentifier.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
25
#include "
I3SubIdentifier.h
"
26
27
28
I3SubIdentifier::I3SubIdentifier
() :
29
type(Invalid)
30
{
31
}
32
33
void
I3SubIdentifier::setIPAddress
(
const
I3IPAddress
&address)
34
{
35
type
=
IPAddress
;
36
ipAddress
= address;
37
identifier
.
clear
();
38
}
39
40
void
I3SubIdentifier::setIdentifier
(
const
I3Identifier
&
id
)
41
{
42
type
=
Identifier
;
43
44
I3IPAddress
zero;
// initialized to zero
45
ipAddress
= zero;
// set to clear
46
47
identifier
= id;
48
}
49
50
I3SubIdentifier::IdentifierType
I3SubIdentifier::getType
()
const
51
{
52
return
type
;
53
}
54
55
I3IPAddress
&
I3SubIdentifier::getIPAddress
()
56
{
57
if
(
type
!=
IPAddress
) {
58
// error!
59
}
60
return
ipAddress
;
61
}
62
63
I3Identifier
&
I3SubIdentifier::getIdentifier
()
64
{
65
if
(
type
!=
Identifier
) {
66
// error!
67
};
68
return
identifier
;
69
}
70
71
int
I3SubIdentifier::compareTo
(
const
I3SubIdentifier
&
id
)
const
72
{
73
if
(
type
!=
id
.
type
) {
74
return
type -
id
.type;
75
}
else
if
(type ==
Identifier
) {
76
return
identifier
.
compareTo
(
id
.
identifier
);
77
}
else
if
(type ==
IPAddress
) {
78
if
(
ipAddress
.
getIp
() <
id
.ipAddress.getIp())
return
-1;
79
else
if
(
ipAddress
.
getIp
() ==
id
.ipAddress.getIp())
return
ipAddress
.
getPort
() -
id
.ipAddress.getPort();
80
else
return
1;
81
}
82
return
0;
83
}
84
85
int
I3SubIdentifier::length
()
const
{
86
// return sizeof(type) + (type == IPAddress ? ipAddress.length() : identifier.length());
87
return
1 + (
type
==
IPAddress
?
ipAddress
.
length
() :
identifier
.
length
());
88
}
89
90
std::ostream&
operator<<
(std::ostream& os,
const
I3SubIdentifier
&s) {
91
if
(s.
type
==
I3SubIdentifier::Identifier
) {
92
os << s.
identifier
;
93
}
else
{
94
os << s.
ipAddress
;
95
}
96
return
os;
97
}
src
applications
i3
I3SubIdentifier.cc
Generated on Fri Dec 7 2012 13:37:52 for OverSim by
1.8.1.2