Bitstream Interpretation Library (BIL)  0.1
Type2Packet.cpp
Go to the documentation of this file.
1 
9 
10 using namespace bil;
11 
12 
14  m_data(),
15  m_wordCount(0),
16  m_opcode(PacketOpcode::NO_OP)
17 {
18 
19 }
20 
21 
23 {
24  return new Type2Packet(*this);
25 }
26 
27 
28 void Type2Packet::accept(PacketVisitor& visitor) const
29 {
30  visitor.visit(*this);
31 }
32 
33 
35 {
36  // set word count and data according to opcode
37  switch (opcode)
38  {
40  // word count has to be zero, no data allowed
41  m_wordCount = 0;
42  m_data.resize(0);
43  break;
44 
46  // no data allowed
47  m_data.resize(0);
48  break;
49 
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 
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 
107 {
108  m_opcode = PacketOpcode::NO_OP;
109  m_wordCount = 0;
110  m_data.resize(0);
111 }