IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
IBR-DTNSuite
Namespaces
Classes
Files
File List
daemon
ibrcommon
ibrdtn
ibrdtn
api
data
AdministrativeBlock.cpp
AdministrativeBlock.h
AgeBlock.cpp
AgeBlock.h
Block.cpp
Block.h
Bundle.cpp
Bundle.h
BundleBuilder.cpp
BundleBuilder.h
BundleFragment.cpp
BundleFragment.h
BundleID.cpp
BundleID.h
BundleList.cpp
BundleList.h
BundleMerger.cpp
BundleMerger.h
BundleSet.cpp
BundleSet.h
BundleSetImpl.cpp
BundleSetImpl.h
BundleString.cpp
BundleString.h
CompressedPayloadBlock.cpp
CompressedPayloadBlock.h
CustodySignalBlock.cpp
CustodySignalBlock.h
Dictionary.cpp
Dictionary.h
DTNTime.cpp
DTNTime.h
EID.cpp
EID.h
Endianess.cpp
Endianess.h
Exceptions.h
ExtensionBlock.cpp
ExtensionBlock.h
MemoryBundleSet.cpp
MemoryBundleSet.h
MetaBundle.cpp
MetaBundle.h
Number.h
PayloadBlock.cpp
PayloadBlock.h
PrimaryBlock.cpp
PrimaryBlock.h
SchedulingBlock.cpp
SchedulingBlock.h
ScopeControlHopLimitBlock.cpp
ScopeControlHopLimitBlock.h
SDNV.cpp
SDNV.h
Serializer.cpp
Serializer.h
StatusReportBlock.cpp
StatusReportBlock.h
StreamBlock.cpp
StreamBlock.h
TrackingBlock.cpp
TrackingBlock.h
security
streams
utils
config.h
dummy.cpp
ibrdtn.h
tools
File Members
BundleBuilder.h
Go to the documentation of this file.
1
/*
2
* BundleBuilder.h
3
*
4
* Created on: 10.01.2013
5
* Author: morgenro
6
*/
7
8
#ifndef BUNDLEBUILDER_H_
9
#define BUNDLEBUILDER_H_
10
11
#include <
ibrdtn/data/Number.h
>
12
#include <
ibrdtn/data/Bundle.h
>
13
#include <
ibrdtn/data/Block.h
>
14
#include <iterator>
15
#include <stdlib.h>
16
17
namespace
dtn
18
{
19
namespace
data
20
{
21
class
BundleBuilder
{
22
public
:
23
class
DiscardBlockException
:
public
dtn::SerializationFailedException
24
{
25
public
:
26
DiscardBlockException
(
string
what
=
"Block has been discarded."
) throw() : dtn::
SerializationFailedException
(
what
)
27
{
28
};
29
};
30
31
enum
POSITION
32
{
33
FRONT
,
34
MIDDLE
,
35
END
36
};
37
38
BundleBuilder
(
Bundle
&target,
POSITION
alignment =
END
,
int
pos = 0);
39
virtual
~BundleBuilder
();
40
44
void
clear
();
45
46
template
<
class
T>
47
T&
insert
(
const
Bitset<Block::ProcFlags>
&procflags);
48
49
POSITION
getAlignment
()
const
;
50
51
dtn::data::Block
&
insert
(
dtn::data::ExtensionBlock::Factory
&f,
const
Bitset<Block::ProcFlags>
&procflags);
52
56
dtn::data::Block
&
insert
(
dtn::data::block_t
block_type,
const
Bitset<Block::ProcFlags>
&procflags)
throw
(
dtn::InvalidDataException
);
57
58
private
:
59
Bundle
*_target;
60
61
POSITION
_alignment;
62
int
_pos;
63
};
64
65
template
<
class
T>
66
T&
BundleBuilder::insert
(
const
Bitset<Block::ProcFlags>
&procflags)
67
{
68
switch
(_alignment)
69
{
70
case
FRONT
:
71
{
72
T &block = _target->
push_front
<T>();
73
bool
last_block = block.get(
dtn::data::Block::LAST_BLOCK
);
74
block._procflags = procflags;
75
block.set(
dtn::data::Block::LAST_BLOCK
, last_block);
76
return
block;
77
}
78
79
case
END
:
80
{
81
T &block = _target->
push_back
<T>();
82
bool
last_block = block.get(
dtn::data::Block::LAST_BLOCK
);
83
block._procflags = procflags;
84
block.set(
dtn::data::Block::LAST_BLOCK
, last_block);
85
return
block;
86
}
87
88
default
:
89
if
(_pos <= 0) {
90
T &block = _target->
push_front
<T>();
91
bool
last_block = block.get(
dtn::data::Block::LAST_BLOCK
);
92
block._procflags = procflags;
93
block.set(
dtn::data::Block::LAST_BLOCK
, last_block);
94
return
block;
95
}
96
97
dtn::data::Bundle::iterator
it = _target->
begin
();
98
std::advance(it, _pos-1);
99
100
T &block = (it == _target->
end
()) ? _target->
push_back
<T>() : _target->
insert
<T>(it);
101
102
bool
last_block = block.get(
dtn::data::Block::LAST_BLOCK
);
103
block._procflags = procflags;
104
block.set(
dtn::data::Block::LAST_BLOCK
, last_block);
105
return
block;
106
}
107
}
108
}
/* namespace data */
109
}
/* namespace dtn */
110
#endif
/* BUNDLEBUILDER_H_ */
ibrdtn
ibrdtn
data
BundleBuilder.h
Generated on Thu Mar 27 2014 09:26:21 for IBR-DTNSuite by
1.8.4