diff --git a/tools/rosbag_storage/include/rosbag/bag.h b/tools/rosbag_storage/include/rosbag/bag.h index 526c1dab03..83174d6fba 100644 --- a/tools/rosbag_storage/include/rosbag/bag.h +++ b/tools/rosbag_storage/include/rosbag/bag.h @@ -58,6 +58,7 @@ #include #include +#include #include #include "console_bridge/console.h" @@ -111,6 +112,12 @@ class ROSBAG_DECL Bag ~Bag(); +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + Bag(Bag&& other); + + Bag& operator=(Bag&& other); +#endif // BOOST_NO_CXX11_RVALUE_REFERENCES + //! Open a bag file. /*! * \param filename The bag file to open @@ -186,9 +193,12 @@ class ROSBAG_DECL Bag void swap(Bag&); private: + // disable copying Bag(const Bag&); Bag& operator=(const Bag&); + void init(); + // This helper function actually does the write with an arbitrary serializable message template void doWrite(std::string const& topic, ros::Time const& time, T const& msg, boost::shared_ptr const& connection_header); diff --git a/tools/rosbag_storage/src/bag.cpp b/tools/rosbag_storage/src/bag.cpp index b030852cfe..09bfd94cbc 100644 --- a/tools/rosbag_storage/src/bag.cpp +++ b/tools/rosbag_storage/src/bag.cpp @@ -57,45 +57,52 @@ using ros::Time; namespace rosbag { -Bag::Bag() : - mode_(bagmode::Write), - version_(0), - compression_(compression::Uncompressed), - chunk_threshold_(768 * 1024), // 768KB chunks - bag_revision_(0), - file_size_(0), - file_header_pos_(0), - index_data_pos_(0), - connection_count_(0), - chunk_count_(0), - chunk_open_(false), - curr_chunk_data_pos_(0), - current_buffer_(0), - decompressed_chunk_(0) +Bag::Bag() { + init(); } -Bag::Bag(string const& filename, uint32_t mode) : - compression_(compression::Uncompressed), - chunk_threshold_(768 * 1024), // 768KB chunks - bag_revision_(0), - file_size_(0), - file_header_pos_(0), - index_data_pos_(0), - connection_count_(0), - chunk_count_(0), - chunk_open_(false), - curr_chunk_data_pos_(0), - current_buffer_(0), - decompressed_chunk_(0) +Bag::Bag(string const& filename, uint32_t mode) { + init(); open(filename, mode); } +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + +Bag::Bag(Bag&& other) { + init(); + swap(other); +} + +Bag& Bag::operator=(Bag&& other) { + swap(other); + return *this; +} + +#endif // BOOST_NO_CXX11_RVALUE_REFERENCES + Bag::~Bag() { close(); } +void Bag::init() { + mode_ = bagmode::Write; + version_ = 0; + compression_ = compression::Uncompressed; + chunk_threshold_ = 768 * 1024; // 768KB chunks + bag_revision_ = 0; + file_size_ = 0; + file_header_pos_ = 0; + index_data_pos_ = 0; + connection_count_ = 0; + chunk_count_ = 0; + chunk_open_ = false; + curr_chunk_data_pos_ = 0; + current_buffer_ = 0; + decompressed_chunk_ = 0; +} + void Bag::open(string const& filename, uint32_t mode) { mode_ = (BagMode) mode;