Bitstream Interpretation Library (BIL)
0.1
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
bitstream
Type2Packet.cpp
Go to the documentation of this file.
1
6
#include <
bitstream/PacketVisitor.hpp
>
7
#include <
bitstream/Type2Packet.hpp
>
8
#include <
exception/Exception.hpp
>
9
10
using namespace
bil;
11
12
13
Type2Packet::Type2Packet
():
14
m_data(),
15
m_wordCount(0),
16
m_opcode(PacketOpcode::
NO_OP
)
17
{
18
19
}
20
21
22
Type2Packet
*
Type2Packet::clone
()
const
23
{
24
return
new
Type2Packet
(*
this
);
25
}
26
27
28
void
Type2Packet::accept
(
PacketVisitor
& visitor)
const
29
{
30
visitor.
visit
(*
this
);
31
}
32
33
34
void
Type2Packet::opcode
(
PacketOpcode::opcode_t
opcode)
35
{
36
// set word count and data according to opcode
37
switch
(opcode)
38
{
39
case
PacketOpcode::NO_OP
:
40
// word count has to be zero, no data allowed
41
m_wordCount = 0;
42
m_data.resize(0);
43
break
;
44
45
case
PacketOpcode::REGISTER_READ
:
46
// no data allowed
47
m_data.resize(0);
48
break
;
49
50
case
PacketOpcode::REGISTER_WRITE
:
51
// set data size to word count words
52
m_data.resize(m_wordCount);
53
break
;
54
55
default
:
throw
Exception
();
56
}
57
58
// set new opcode
59
m_opcode =
opcode
;
60
}
61
62
63
PacketOpcode::opcode_t
Type2Packet::opcode
()
const
64
{
65
return
m_opcode;
66
}
67
68
69
void
Type2Packet::wordCount
(
size_t
count)
70
{
71
// in no op mode, count must be zero
72
if
((
PacketOpcode::NO_OP
== m_opcode) && (0 < count))
73
throw
Exception
();
74
75
// set new count
76
m_wordCount = count;
77
78
// in write mode resize data to new size
79
if
(
PacketOpcode::REGISTER_WRITE
== m_opcode)
80
m_data.resize(count);
81
}
82
83
84
size_t
Type2Packet::wordCount
()
const
85
{
86
return
m_wordCount;
87
}
88
89
90
boost::uint32_t*
Type2Packet::dataWords
()
91
{
92
// if there is data, return pointer to it, else return 0.
93
if
(0 < m_data.size())
return
&(m_data[0]);
94
else
return
0;
95
}
96
97
98
const
boost::uint32_t*
Type2Packet::dataWords
()
const
99
{
100
// if there is data, return pointer to it, else return 0.
101
if
(0 < m_data.size())
return
&(m_data[0]);
102
else
return
0;
103
}
104
105
106
void
Type2Packet::clear
()
107
{
108
m_opcode =
PacketOpcode::NO_OP
;
109
m_wordCount = 0;
110
m_data.resize(0);
111
}
Generated on Wed Aug 8 2012 21:57:40 for Bitstream Interpretation Library (BIL) by
1.8.1.1