Apollo 10.0
自动驾驶开放平台
record_viewer.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#ifndef CYBER_RECORD_RECORD_VIEWER_H_
18#define CYBER_RECORD_RECORD_VIEWER_H_
19
20#include <cstddef>
21#include <limits>
22#include <map>
23#include <memory>
24#include <set>
25#include <string>
26#include <vector>
27
30
31namespace apollo {
32namespace cyber {
33namespace record {
34
39 public:
40 using RecordReaderPtr = std::shared_ptr<RecordReader>;
41
50 RecordViewer(const RecordReaderPtr& reader, uint64_t begin_time = 0,
51 uint64_t end_time = std::numeric_limits<uint64_t>::max(),
52 const std::set<std::string>& channels = {});
53
62 RecordViewer(const std::vector<RecordReaderPtr>& readers,
63 uint64_t begin_time = 0,
64 uint64_t end_time = std::numeric_limits<uint64_t>::max(),
65 const std::set<std::string>& channels = std::set<std::string>());
66
72 bool IsValid() const;
73
79 uint64_t begin_time() const { return begin_time_; }
80
86 uint64_t end_time() const { return end_time_; }
87
93 std::set<std::string> GetChannelList() const { return channel_list_; }
94
98 class Iterator : public std::iterator<std::input_iterator_tag, RecordMessage,
99 int, RecordMessage*, RecordMessage&> {
100 public:
107 explicit Iterator(RecordViewer* viewer, bool end = false);
108
113
117 virtual ~Iterator() {}
118
126 bool operator==(Iterator const& other) const;
127
135 bool operator!=(const Iterator& rhs) const;
136
143
149 pointer operator->();
150
156 reference operator*();
157
158 private:
159 bool end_ = false;
160 uint64_t index_ = 0;
161 RecordViewer* viewer_ = nullptr;
162 value_type message_instance_;
163 };
164
170 Iterator begin();
171
177 Iterator end();
178
184 Iterator curr_itr();
185
186 void set_curr_itr(const Iterator& curr_itr);
187
188 private:
189 friend class Iterator;
190
191 void Init();
192 void Reset();
193 void UpdateTime();
194 bool FillBuffer();
195 bool Update(RecordMessage* message);
196
197 uint64_t begin_time_ = 0;
198 uint64_t end_time_ = std::numeric_limits<uint64_t>::max();
199 // User defined channels
200 std::set<std::string> channels_;
201 // All channel in user defined readers
202 std::set<std::string> channel_list_;
203 std::vector<RecordReaderPtr> readers_;
204 std::vector<bool> readers_finished_;
205
206 uint64_t curr_begin_time_ = 0;
207 std::multimap<uint64_t, std::shared_ptr<RecordMessage>> msg_buffer_;
208
209 const uint64_t kStepTimeNanoSec = 1000000000UL; // 1 second
210 const std::size_t kBufferMinSize = 128;
211
212 Iterator itr_;
213};
214
215} // namespace record
216} // namespace cyber
217} // namespace apollo
218
219#endif // CYBER_RECORD_RECORD_VIEWER_H_
bool operator==(Iterator const &other) const
Overloading operator ==.
Iterator & operator++()
Overloading operator ++.
bool operator!=(const Iterator &rhs) const
Overloading operator !=.
virtual ~Iterator()
The default destructor of iterator.
Iterator()
The default constructor of iterator.
pointer operator->()
Overloading operator ->.
reference operator*()
Overloading operator *.
void set_curr_itr(const Iterator &curr_itr)
uint64_t begin_time() const
Get begin time.
Iterator begin()
Get the begin iterator.
bool IsValid() const
Is this record reader is valid.
std::set< std::string > GetChannelList() const
Get channel list.
std::shared_ptr< RecordReader > RecordReaderPtr
Iterator curr_itr()
Get current iterator.
Iterator end()
Get the end iterator.
uint64_t end_time() const
Get end time.
class register implement
Definition arena_queue.h:37
Basic data struct of record message.