Apollo  6.0
Open source self driving car software
record_viewer.h
Go to the documentation of this file.
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 
31 namespace apollo {
32 namespace cyber {
33 namespace record {
34 
38 class RecordViewer {
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 
112  Iterator() {}
113 
117  virtual ~Iterator() {}
118 
126  bool operator==(Iterator const& other) const;
127 
135  bool operator!=(const Iterator& rhs) const;
136 
142  Iterator& operator++();
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 
179  private:
180  friend class Iterator;
181 
182  void Init();
183  void Reset();
184  void UpdateTime();
185  bool FillBuffer();
186  bool Update(RecordMessage* message);
187 
188  uint64_t begin_time_ = 0;
189  uint64_t end_time_ = std::numeric_limits<uint64_t>::max();
190  // User defined channels
191  std::set<std::string> channels_;
192  // All channel in user defined readers
193  std::set<std::string> channel_list_;
194  std::vector<RecordReaderPtr> readers_;
195  std::vector<bool> readers_finished_;
196 
197  uint64_t curr_begin_time_ = 0;
198  std::multimap<uint64_t, std::shared_ptr<RecordMessage>> msg_buffer_;
199 
200  const uint64_t kStepTimeNanoSec = 1000000000UL; // 1 second
201  const std::size_t kBufferMinSize = 128;
202 };
203 
204 } // namespace record
205 } // namespace cyber
206 } // namespace apollo
207 
208 #endif // CYBER_RECORD_RECORD_VIEWER_H_
Basic data struct of record message.
Definition: record_message.h:34
RecordViewer(const RecordReaderPtr &reader, uint64_t begin_time=0, uint64_t end_time=std::numeric_limits< uint64_t >::max(), const std::set< std::string > &channels={})
The constructor with single reader.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
pointer operator->()
Overloading operator ->.
bool operator!=(const Iterator &rhs) const
Overloading operator !=.
bool IsValid() const
Is this record reader is valid.
uint64_t end_time() const
Get end time.
Definition: record_viewer.h:86
Iterator()
The default constructor of iterator.
Definition: record_viewer.h:112
std::shared_ptr< RecordReader > RecordReaderPtr
Definition: record_viewer.h:40
uint64_t begin_time() const
Get begin time.
Definition: record_viewer.h:79
The iterator.
Definition: record_viewer.h:98
Iterator end()
Get the end iterator.
virtual ~Iterator()
The default destructor of iterator.
Definition: record_viewer.h:117
The record viewer.
Definition: record_viewer.h:38
Iterator begin()
Get the begin iterator.
bool Init(const char *binary_name)
Iterator & operator++()
Overloading operator ++.
bool operator==(Iterator const &other) const
Overloading operator ==.
reference operator*()
Overloading operator *.
std::set< std::string > GetChannelList() const
Get channel list.
Definition: record_viewer.h:93