IBR-DTNSuite
0.10
Main Page
Namespaces
Classes
Files
File List
File Members
BundleID.cpp
Go to the documentation of this file.
1
/*
2
* BundleID.cpp
3
*
4
* Copyright (C) 2011 IBR, TU Braunschweig
5
*
6
* Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7
*
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
11
*
12
* http://www.apache.org/licenses/LICENSE-2.0
13
*
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
19
*
20
*/
21
22
#include "
ibrdtn/config.h
"
23
#include "
ibrdtn/data/BundleID.h
"
24
#include "
ibrdtn/data/Number.h
"
25
#include "
ibrdtn/data/BundleString.h
"
26
27
namespace
dtn
28
{
29
namespace
data
30
{
31
BundleID::BundleID
(
const
dtn::data::EID
s,
const
dtn::data::Timestamp
&t,
const
dtn::data::Number
&sq,
const
bool
f,
const
dtn::data::Number
&o)
32
: source(s), timestamp(t), sequencenumber(sq), fragment(f), offset(o)
33
{
34
}
35
36
BundleID::BundleID
(
const
dtn::data::PrimaryBlock
&b)
37
: source(b.source), timestamp(b.timestamp), sequencenumber(b.sequencenumber),
38
fragment(b.get(dtn::data::
Bundle
::FRAGMENT)), offset(b.fragmentoffset)
39
{
40
}
41
42
BundleID::~BundleID
()
43
{
44
}
45
46
bool
BundleID::operator<
(
const
BundleID
& other)
const
47
{
48
if
(
source
< other.
source
)
return
true
;
49
if
(
source
!= other.
source
)
return
false
;
50
51
if
(
timestamp
< other.
timestamp
)
return
true
;
52
if
(
timestamp
!= other.
timestamp
)
return
false
;
53
54
if
(
sequencenumber
< other.
sequencenumber
)
return
true
;
55
if
(
sequencenumber
!= other.
sequencenumber
)
return
false
;
56
57
if
(other.
fragment
)
58
{
59
if
(!
fragment
)
return
true
;
60
return
(
offset
< other.
offset
);
61
}
62
63
return
false
;
64
}
65
66
bool
BundleID::operator>
(
const
BundleID
& other)
const
67
{
68
return
!(((*this) < other) || ((*
this
) == other));
69
}
70
71
bool
BundleID::operator!=
(
const
BundleID
& other)
const
72
{
73
return
!((*this) == other);
74
}
75
76
bool
BundleID::operator==
(
const
BundleID
& other)
const
77
{
78
if
(other.
timestamp
!=
timestamp
)
return
false
;
79
if
(other.
sequencenumber
!=
sequencenumber
)
return
false
;
80
if
(other.
source
!=
source
)
return
false
;
81
if
(other.
fragment
!=
fragment
)
return
false
;
82
83
if
(
fragment
)
84
{
85
if
(other.
offset
!=
offset
)
return
false
;
86
}
87
88
return
true
;
89
}
90
91
std::string
BundleID::toString
()
const
92
{
93
stringstream ss;
94
ss <<
"["
<<
timestamp
.
toString
() <<
"."
<<
sequencenumber
.
toString
();
95
96
if
(
fragment
)
97
{
98
ss <<
"."
<<
offset
.
toString
();
99
}
100
101
ss <<
"] "
<<
source
.
getString
();
102
103
return
ss.str();
104
}
105
106
std::ostream &
operator<<
(std::ostream &stream,
const
BundleID
&obj)
107
{
108
dtn::data::BundleString
source(obj.
source
.
getString
());
109
110
stream << obj.
timestamp
<< obj.
sequencenumber
<< obj.
offset
<< source;
111
112
return
stream;
113
}
114
115
std::istream &
operator>>
(std::istream &stream,
BundleID
&obj)
116
{
117
dtn::data::BundleString
source;
118
119
stream >> obj.
timestamp
>> obj.
sequencenumber
>> obj.
offset
>> source;
120
121
obj.
source
=
dtn::data::EID
(source);
122
123
return
stream;
124
}
125
}
126
}
ibrdtn
ibrdtn
data
BundleID.cpp
Generated on Mon Jul 22 2013 15:16:00 for IBR-DTNSuite by
1.8.3.1