Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
dqdumpfile.hh
Go to the documentation of this file.
1#ifndef DQDUMPFILE_HH
2#define DQDUMPFILE_HH
3
4#include <fstream>
5#include <vector>
6
8
9/**
10 * \author cpellegrino
11 */
12
13class Packet
14{
16
17 public:
18
19 Packet() {}
20
21 Packet& operator =(const Packet& packet)
22 {
23 m_data = packet.m_data;
24 return *this;
25 }
26
27 Packet(const Packet& packet)
28 :
29 m_data(packet.m_data)
30 {}
31
32 Packet(std::size_t size)
33 {
34 m_data.resize(size);
35 }
36
38 {
39 return static_cast<CLBCommonHeader const*>(
40 static_cast<void const*>(
41 &m_data.front()));
42 }
43
44 char const* payload() const
45 {
46 return &m_data.front() + sizeof(CLBCommonHeader);
47 }
48
49 std::size_t size() const
50 {
51 return m_data.size();
52 }
53
54 char* data()
55 {
56 return &m_data.front();
57 }
58
59 char const* data() const
60 {
61 return &m_data.front();
62 }
63};
64
66{
67 std::ifstream m_stream;
69
72
73 public:
74
76 {
78 std::size_t m_index;
79
80 public:
81
83 :
84 m_file(0),
85 m_index(0)
86 {}
87
88 iterator(DumpFile* x, std::size_t idx = 0)
89 :
90 m_file(x),
91 m_index(idx)
92 {}
93
94 iterator(const iterator& mit)
95 :
96 m_file(mit.m_file),
97 m_index(mit.m_index)
98 {}
99
101 {
102 ++m_index;
103 return *this;
104 }
105
107 {
108 iterator tmp(*this);
109 operator++();
110 return tmp;
111 }
112
114 {
115 --m_index;
116 return *this;
117 }
118
120 {
121 iterator tmp(*this);
122 operator--();
123 return tmp;
124 }
125
126 bool operator ==(const iterator& rhs)
127 {
128 return m_index == rhs.m_index && m_file == rhs.m_file;
129 }
130
131 bool operator !=(const iterator& rhs)
132 {
133 return !(*this == rhs);
134 }
135
137 {
138 return m_file->operator [](m_index);
139 }
140 };
141
142 DumpFile(std::string const& filename)
143 :
144 m_stream(filename.c_str())
145 {
146 while (m_stream) {
147 m_pos.push_back(m_stream.tellg());
148 uint32_t pack_size;
149 m_stream.read((char*) &pack_size, sizeof(pack_size));
150 m_stream.ignore(pack_size);
151 }
152 m_pos.pop_back();
153 }
154
156 {
157 return iterator(this, 0);
158 }
159
161 {
162 return iterator(this, m_pos.size());
163 }
164
165 Packet operator [](std::size_t n)
166 {
167 m_stream.clear();
168 m_stream.seekg(m_pos[n]);
169
170 uint32_t pack_size;
171 m_stream.read((char*) &pack_size, sizeof(pack_size));
172
173 Packet dg(pack_size);
174 m_stream.read(dg.data(), pack_size);
175 return dg;
176 }
177
178 std::size_t size() const
179 {
180 return m_pos.size();
181 }
182};
183
184#endif // DQDUMPFILE_HH
iterator & operator++()
bool operator!=(const iterator &rhs)
bool operator==(const iterator &rhs)
iterator operator++(int)
std::size_t m_index
Definition dqdumpfile.hh:78
iterator(const iterator &mit)
Definition dqdumpfile.hh:94
iterator operator--(int)
iterator(DumpFile *x, std::size_t idx=0)
Definition dqdumpfile.hh:88
DumpFile * m_file
Definition dqdumpfile.hh:77
iterator & operator--()
DumpFile & operator=(DumpFile const &)
Packet operator[](std::size_t n)
iterator begin()
std::vector< std::size_t > m_pos
Definition dqdumpfile.hh:68
DumpFile(DumpFile const &)
std::size_t size() const
iterator end()
DumpFile(std::string const &filename)
std::ifstream m_stream
Definition dqdumpfile.hh:67
Packet(std::size_t size)
Definition dqdumpfile.hh:32
std::size_t size() const
Definition dqdumpfile.hh:49
CLBCommonHeader const * CLBHeader() const
Definition dqdumpfile.hh:37
char * data()
Definition dqdumpfile.hh:54
std::vector< char > m_data
Definition dqdumpfile.hh:15
char const * data() const
Definition dqdumpfile.hh:59
Packet & operator=(const Packet &packet)
Definition dqdumpfile.hh:21
Packet(const Packet &packet)
Definition dqdumpfile.hh:27
char const * payload() const
Definition dqdumpfile.hh:44