Go to the documentation of this file.00001 #include <generic_control_toolbox/bag_manager.hpp>
00002
00003 namespace generic_control_toolbox
00004 {
00005 BagManager::BagManager(const std::string &path,
00006 const std::string &default_topic)
00007 : default_topic_(default_topic)
00008 {
00009 boost::filesystem::create_directory(path);
00010 int num = numOfFiles(path);
00011 std::string name = path + "log_" + std::to_string(num) + ".bag";
00012 ROS_DEBUG_STREAM("Opening a new bag: " << name);
00013 bag_.open(name, rosbag::bagmode::Write);
00014 }
00015
00016 BagManager::~BagManager() { bag_.close(); }
00017
00018 int BagManager::numOfFiles(const std::string &path) const
00019 {
00020
00021 boost::filesystem::path p(path);
00022 boost::filesystem::directory_iterator end_iter;
00023 int num = 1;
00024
00025 for (boost::filesystem::directory_iterator iter(p); iter != end_iter; iter++)
00026 {
00027 if (iter->path().extension() == ".bag")
00028 {
00029 num++;
00030 }
00031 }
00032
00033 return num;
00034 }
00035 }