diff --git a/docs/manual.html b/docs/manual.html index 7168b2994..e0ea9b782 100755 --- a/docs/manual.html +++ b/docs/manual.html @@ -501,7 +501,7 @@ public: torrent_info(const entry& torrent_file) torrent_info(int piece_size, const char* name); - entry create_torrent(const char* created_by = 0) const; + entry create_torrent() const; void set_comment(char const* str); void set_creator(char const* str); void set_hash(int index, const sha1_hash& h); diff --git a/docs/manual.rst b/docs/manual.rst index da5186e62..e9caf21a8 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -482,7 +482,7 @@ The ``torrent_info`` has the following synopsis:: torrent_info(const entry& torrent_file) torrent_info(int piece_size, const char* name); - entry create_torrent(const char* created_by = 0) const; + entry create_torrent() const; void set_comment(char const* str); void set_creator(char const* str); void set_hash(int index, const sha1_hash& h); diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index 4e9419192..b5094a6d1 100755 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -102,6 +102,7 @@ namespace libtorrent }; } + class entry; class entry { @@ -171,13 +172,14 @@ namespace libtorrent data_type m_type; -#if defined(_MSC_VER) - +#if defined(_MSC_VER) && _MSC_VER < 1300 // workaround for msvc-bug. // assumes sizeof(map) == sizeof(map) + // and sizeof(list) == sizeof(list) union { - char data[detail::max4) , sizeof(std::map) , sizeof(string_type) , sizeof(integer_type)>::value]; diff --git a/src/allocate_resources.cpp b/src/allocate_resources.cpp index c4fcefebc..561c5e9be 100644 --- a/src/allocate_resources.cpp +++ b/src/allocate_resources.cpp @@ -38,10 +38,11 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #if defined(_MSC_VER) && _MSC_VER < 1300 #define for if (false) {} else for +#else +#include #endif namespace libtorrent @@ -252,6 +253,68 @@ namespace libtorrent , res); } */ +#if defined(_MSC_VER) && _MSC_VER < 1300 + + namespace detail + { + struct iterator_wrapper + { + typedef std::map >::iterator orig_iter; + + orig_iter iter; + + iterator_wrapper(orig_iter i): iter(i) {} + void operator++() { ++iter; } + torrent& operator*() { return *(iter->second); } + bool operator==(const iterator_wrapper& i) const + { return iter == i.iter; } + bool operator!=(const iterator_wrapper& i) const + { return iter != i.iter; } + }; + + struct iterator_wrapper2 + { + typedef std::map::iterator orig_iter; + + orig_iter iter; + + iterator_wrapper2(orig_iter i): iter(i) {} + void operator++() { ++iter; } + peer_connection& operator*() { return *(iter->second); } + bool operator==(const iterator_wrapper2& i) const + { return iter == i.iter; } + bool operator!=(const iterator_wrapper2& i) const + { return iter != i.iter; } + }; + + } + + void allocate_resources( + int resources + , std::map >& c + , resource_request torrent::* res) + { + allocate_resources_impl( + resources + , detail::iterator_wrapper(c.begin()) + , detail::iterator_wrapper(c.end()) + , res); + } + + void allocate_resources( + int resources + , std::map& c + , resource_request peer_connection::* res) + { + allocate_resources_impl( + resources + , detail::iterator_wrapper2(c.begin()) + , detail::iterator_wrapper2(c.end()) + , res); + } + +#else + void allocate_resources( int resources , std::map >& c @@ -283,5 +346,6 @@ namespace libtorrent , new_iter(c.end(), &pick_peer2) , res); } +#endif } // namespace libtorrent diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 1e3d2e4c5..d1a073778 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -44,8 +44,13 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/invariant_check.hpp" #include "libtorrent/io.hpp" -#if defined(_MSC_VER) +#if defined(_MSC_VER) && _MSC_VER < 1300 #define for if (false) {} else for +namespace std +{ + using ::isprint; +} + #endif #define VERBOSE diff --git a/src/session.cpp b/src/session.cpp index a3a2f1a7f..a7a4c4ee5 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -872,6 +872,8 @@ namespace libtorrent , const boost::filesystem::path& save_path , const entry& resume_data) { + if (ti.begin_files() == ti.end_files()) + throw std::runtime_error("no files in torrent"); { // lock the session diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index e665ea0db..67bfc654b 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -75,6 +75,64 @@ namespace libtorrent namespace { +#if defined(_MSC_VER) && _MSC_VER < 1300 + + template + struct transform_void{ typedef T type; }; + + template<> + struct transform_void { typedef int type; }; + + template + struct void_call_wrapper + { + template + static Ret call(F f, torrent& t) + { + return f(t); + } + }; + + template<> + struct void_call_wrapper + { + template + static int call(F f, torrent& t) + { + f(t); + return 0; + } + }; + + template + transform_void::type call_member( + detail::session_impl* ses + , detail::checker_impl* chk + , sha1_hash const& hash + , F f) + { + typedef typename transform_void::type ret; + if (ses == 0) throw invalid_handle(); + + { + boost::mutex::scoped_lock l(ses->m_mutex); + torrent* t = ses->find_torrent(hash); + if (t != 0) return void_call_wrapper::call(f, *t); + } + + + if (chk) + { + boost::mutex::scoped_lock l(chk->m_mutex); + + detail::piece_checker_data* d = chk->find_torrent(hash); + if (d != 0) return void_call_wrapper::call(f, *d->torrent_ptr); + } + throw invalid_handle(); + } + +#else + template Ret call_member( detail::session_impl* ses @@ -100,6 +158,8 @@ namespace libtorrent } throw invalid_handle(); } +#endif + } #ifndef NDEBUG