diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 1a4f46539..70c3d6363 100755 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -99,6 +99,10 @@ namespace libtorrent const boost::filesystem::path& save_path() const; + // fills the vector with a map of pieces to + // slots, including not-yet-finished piece + void export_piece_map(std::vector >& pieces) const; + private: struct impl; opaque_value_ptr m_pimpl; diff --git a/src/storage.cpp b/src/storage.cpp index c90196410..144ff0f16 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -370,6 +370,8 @@ namespace libtorrent { const boost::filesystem::path& save_path() const { return m_save_path; } + void export_piece_map(std::vector >& p) const; + private: // returns the slot currently associated with the given // piece or assigns the given piece_index to a free slot @@ -427,6 +429,26 @@ namespace libtorrent { { } + void piece_manager::impl::export_piece_map( + std::vector >& p) const + { + p.clear(); + for (std::vector::const_iterator i = m_piece_to_slot.begin(); + i != m_piece_to_slot.end(); + ++i) + { + if (*i == -1) continue; + p.push_back(std::make_pair(i - m_piece_to_slot.begin(), *i)); + } + } + + void piece_manager::export_piece_map( + std::vector >& p) const + { + m_pimpl->export_piece_map(p); + } + + piece_manager::size_type piece_manager::impl::read( char* buf , int piece_index