7 #include <std_msgs/Header.h> 8 #include <std_msgs/UInt8.h> 19 auto& handle =
m_bags.emplace_back();
20 handle.reader = reader;
21 handle.filtering =
true;
25 if(handle.connectionIDs.size() <= conn.first)
26 handle.connectionIDs.resize(conn.first+1,
false);
28 if(connectionPredicate(conn.second))
29 handle.connectionIDs[conn.first] =
true;
35 auto& handle =
m_bags.emplace_back();
36 handle.reader = reader;
37 handle.filtering =
false;
47 start = std::min(start, bag.reader->startTime());
56 end = std::max(end, bag.reader->endTime());
78 for(
auto& handle : view->
m_bags)
80 auto& state = m_state.emplace_back();
81 state.handle = &handle;
82 state.it = handle.reader->begin();
85 state.skipToNext(
false);
91 for(
auto& handle : view->
m_bags)
93 auto& state = m_state.emplace_back();
94 state.handle = &handle;
95 state.it = handle.reader->findTime(time);
98 state.skipToNext(
false);
131 :
m_d{std::make_shared<Private>(view->
m_d.get())}
137 :
m_d{std::make_shared<Private>(view->
m_d.get(), time)}
148 throw std::logic_error{
"Attempt to dereference invalid BagView::Iterator"};
160 auto* bag =
m_d->m_nextBag;
163 if(bag->handle->filtering)
164 bag->skipToNext(
true);
171 m_d->m_nextBag =
nullptr;
176 auto& state =
m_d->m_state[i];
178 if(state.it == state.handle->reader->end())
181 if(!
m_d->m_nextBag || state.it->stamp < earliestStamp)
183 m_d->m_nextBag = &state;
184 earliestStamp = state.it->stamp;
197 m_d->m_msg.msg = &*
m_d->m_nextBag->it;
198 m_d->m_msg.bagIndex = bagIndex;
216 :
m_d{std::make_unique<Private>()}
224 m_d->addBag(reader, connectionPredicate);
234 return m_d->startTime();
239 return m_d->endTime();
261 char bagfileName[] =
"/tmp/rosbag_fancy_test_XXXXXX";
263 int fd = mkstemp(bagfileName);
267 rosbag::Bag bag{bagfileName, rosbag::BagMode::Write};
270 std_msgs::Header msg;
275 std_msgs::Header msg;
277 bag.write(
"/topicB",
ros::Time(1001, 0), msg);
282 bag.write(
"/topicC",
ros::Time(1002, 0), msg);
296 auto it = view.
begin();
299 CHECK(it->msg->connection->topicInBag ==
"/topicA");
302 CHECK(it->msg->connection->topicInBag ==
"/topicB");
305 CHECK(it->msg->connection->topicInBag ==
"/topicC");
318 for(
auto& pmsg : view)
320 CHECK(pmsg.msg->connection->topicInBag ==
"/topicB");
322 auto msg = pmsg.msg->instantiate<std_msgs::Header>();
324 CHECK(msg->frame_id ==
"b");
335 return con.
type ==
"std_msgs/UInt8";
339 for(
auto& pmsg : view)
341 CHECK(pmsg.msg->connection->topicInBag ==
"/topicC");
343 auto msg = pmsg.msg->instantiate<std_msgs::UInt8>();
345 CHECK(msg->data == 123);
std::unique_ptr< Private > m_d
decltype(sizeof(void *)) typede size_t)
const ConnectionMap & connections() const
void addBag(BagReader *reader)
std::vector< BagHandle > m_bags
friend bool operator!=(const Iterator &a, const Iterator &b)
ros::Time startTime() const
ros::Time endTime() const
Private(const BagView::Private *view, const ros::Time &time)
const BagView::Private::BagHandle * handle
std::vector< BagState > m_state
void advanceWithPredicates(const std::function< bool(const ConnectionInfo &)> &connPredicate, const std::function< bool(const Message &)> &messagePredicate)
friend bool operator==(const Iterator &a, const Iterator &b)
ros::Time endTime() const
void findNextWithPredicates(const std::function< bool(const ConnectionInfo &)> &connPredicate, const std::function< bool(const Message &)> &messagePredicate)
void addBag(BagReader *reader, const std::function< bool(const BagReader::Connection &)> &connectionPredicate)
std::shared_ptr< Private > m_d
void addBag(BagReader *reader)
void skipToNext(bool advance)
ros::Time startTime() const
TEST_CASE("BagView: One file")
std::vector< bool > connectionIDs
Iterator findTime(const ros::Time &time) const
void write(std::string const &topic, ros::MessageEvent< T > const &event)
Private(const BagView::Private *view)