fix python binding issue with string_view (#1560)

fix python binding issue with string_view
This commit is contained in:
Arvid Norberg 2017-01-15 14:42:22 -05:00 committed by GitHub
parent 77d6a24f10
commit d4672f41ba
1 changed files with 26 additions and 17 deletions

View File

@ -57,7 +57,7 @@ namespace
}
#ifndef TORRENT_NO_DEPRECATE
void add_file(file_storage& ct, file_entry const& fe)
void add_file_deprecated(file_storage& ct, file_entry const& fe)
{
ct.add_file(fe);
}
@ -99,7 +99,15 @@ namespace
FileIter end_files(file_storage const& self)
{ return FileIter(self, self.end_file()); }
#endif
#if TORRENT_USE_WSTRING
void add_file_wstring(file_storage& fs, std::wstring const& file, std::int64_t size
, int flags, std::time_t md, std::string link)
{
fs.add_file(file, size, flags, md, link);
}
#endif // TORRENT_USE_WSTRING
#endif // TORRENT_NO_DEPRECATE
void add_files_callback(file_storage& fs, std::string const& file
, boost::python::object cb, std::uint32_t flags)
@ -107,19 +115,20 @@ namespace
add_files(fs, file, [&](std::string const& i) { return cb(i); }, flags);
}
void add_file(file_storage& fs, std::string const& file, std::int64_t size
, int flags, std::time_t md, std::string link)
{
fs.add_file(file, size, flags, md, link);
}
void add_tracker(create_torrent& ct, std::string url, int tier)
{
ct.add_tracker(url, tier);
}
}
void bind_create_torrent()
{
void (file_storage::*add_file0)(std::string const&, std::int64_t
, int, std::time_t, string_view) = &file_storage::add_file;
#ifndef TORRENT_NO_DEPRECATE
#if TORRENT_USE_WSTRING
void (file_storage::*add_file1)(std::wstring const&, std::int64_t
, int, std::time_t, string_view) = &file_storage::add_file;
#endif // TORRENT_USE_WSTRING
#endif // TORRENT_NO_DEPRECATE
void (file_storage::*set_name0)(std::string const&) = &file_storage::set_name;
void (file_storage::*rename_file0)(file_index_t, std::string const&) = &file_storage::rename_file;
#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE
@ -146,17 +155,17 @@ void bind_create_torrent()
// TODO: 3 move this to its own file
class_<file_storage>("file_storage")
.def("is_valid", &file_storage::is_valid)
.def("add_file", add_file0, (arg("path"), arg("size"), arg("flags") = 0, arg("mtime") = 0, arg("linkpath") = ""))
#if TORRENT_USE_WSTRING && !defined TORRENT_NO_DEPRECATE
.def("add_file", add_file1, (arg("path"), arg("size"), arg("flags") = 0, arg("mtime") = 0, arg("linkpath") = ""))
#endif
.def("add_file", add_file, (arg("path"), arg("size"), arg("flags") = 0, arg("mtime") = 0, arg("linkpath") = ""))
.def("num_files", &file_storage::num_files)
#ifndef TORRENT_NO_DEPRECATE
.def("at", at)
.def("add_file", add_file, arg("entry"))
.def("add_file", add_file_deprecated, arg("entry"))
.def("__iter__", boost::python::range(&begin_files, &end_files))
.def("__len__", &file_storage::num_files)
#if TORRENT_USE_WSTRING
.def("add_file", add_file_wstring, (arg("path"), arg("size"), arg("flags") = 0, arg("mtime") = 0, arg("linkpath") = ""))
#endif
#endif // TORRENT_NO_DEPRECATE
.def("hash", file_storage_hash)
.def("symlink", file_storage_symlink, return_value_policy<copy_const_reference>())
.def("file_path", file_storage_file_path, (arg("idx"), arg("save_path") = ""))
@ -202,7 +211,7 @@ void bind_create_torrent()
.def("add_url_seed", &create_torrent::add_url_seed)
.def("add_http_seed", &create_torrent::add_http_seed)
.def("add_node", &add_node)
.def("add_tracker", &create_torrent::add_tracker, (arg("announce_url"), arg("tier") = 0))
.def("add_tracker", add_tracker, (arg("announce_url"), arg("tier") = 0))
.def("set_priv", &create_torrent::set_priv)
.def("num_pieces", &create_torrent::num_pieces)
.def("piece_length", &create_torrent::piece_length)