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);
289 BagReader reader{bagfileName};
294 view.addBag(&reader);
296 auto it = view.begin();
299 CHECK(it->msg->connection->topicInBag ==
"/topicA");
301 ++it;
REQUIRE(it != view.end());
302 CHECK(it->msg->connection->topicInBag ==
"/topicB");
304 ++it;
REQUIRE(it != view.end());
305 CHECK(it->msg->connection->topicInBag ==
"/topicC");
307 ++it;
CHECK(it == view.end());
313 view.addBag(&reader, [&](
const BagReader::Connection& con){
314 return con.topicInBag ==
"/topicB";
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");
334 view.addBag(&reader, [&](
const BagReader::Connection& con){
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);