11
11
#include " libtorrent/units.hpp"
12
12
#include " libtorrent/sha1_hash.hpp"
13
13
#include " libtorrent/disk_interface.hpp" // for open_file_state
14
+ #include " libtorrent/aux_/noexcept_movable.hpp"
14
15
#include < vector>
15
16
16
17
using namespace boost ::python;
@@ -70,9 +71,10 @@ struct pair_to_tuple
70
71
}
71
72
};
72
73
74
+ template <typename Addr>
73
75
struct address_to_tuple
74
76
{
75
- static PyObject* convert (lt::address const & addr)
77
+ static PyObject* convert (Addr const & addr)
76
78
{
77
79
lt::error_code ec;
78
80
return incref (bp::object (addr.to_string (ec)).ptr ());
@@ -145,7 +147,7 @@ struct dict_to_map
145
147
template <class T >
146
148
struct vector_to_list
147
149
{
148
- static PyObject* convert (const std::vector<T> & v)
150
+ static PyObject* convert (T const & v)
149
151
{
150
152
list l;
151
153
for (int i = 0 ; i < int (v.size ()); ++i)
@@ -162,7 +164,7 @@ struct list_to_vector
162
164
list_to_vector ()
163
165
{
164
166
converter::registry::push_back (
165
- &convertible, &construct, type_id<std::vector<T> >()
167
+ &convertible, &construct, type_id<T >()
166
168
);
167
169
}
168
170
@@ -174,17 +176,17 @@ struct list_to_vector
174
176
static void construct (PyObject* x, converter::rvalue_from_python_stage1_data* data)
175
177
{
176
178
void * storage = ((converter::rvalue_from_python_storage<
177
- std::vector<T> >*)data)->storage .bytes ;
179
+ T >*)data)->storage .bytes ;
178
180
179
- std::vector<T> p;
181
+ T p;
180
182
int const size = int (PyList_Size (x));
181
183
p.reserve (size);
182
184
for (int i = 0 ; i < size; ++i)
183
185
{
184
186
object o (borrowed (PyList_GetItem (x, i)));
185
- p.push_back (extract<T >(o));
187
+ p.push_back (extract<typename T::value_type >(o));
186
188
}
187
- std::vector<T> * ptr = new (storage) std::vector<T> ();
189
+ T * ptr = new (storage) T ();
188
190
ptr->swap (p);
189
191
data->convertible = storage;
190
192
}
@@ -234,35 +236,60 @@ void bind_converters()
234
236
to_python_converter<std::pair<lt::piece_index_t , int >, pair_to_tuple<lt::piece_index_t , int >>();
235
237
to_python_converter<lt::tcp::endpoint, endpoint_to_tuple<lt::tcp::endpoint>>();
236
238
to_python_converter<lt::udp::endpoint, endpoint_to_tuple<lt::udp::endpoint>>();
237
- to_python_converter<lt::address, address_to_tuple>();
239
+ to_python_converter<lt::address, address_to_tuple<lt::address> >();
238
240
to_python_converter<std::pair<std::string, int >, pair_to_tuple<std::string, int >>();
239
241
240
- to_python_converter<std::vector<lt::stats_metric>, vector_to_list<lt::stats_metric>>();
241
- to_python_converter<std::vector<lt::open_file_state>, vector_to_list<lt::open_file_state>>();
242
- to_python_converter<std::vector<lt::sha1_hash>, vector_to_list<lt::sha1_hash>>();
243
- to_python_converter<std::vector<std::string>, vector_to_list<std::string>>();
244
- to_python_converter<std::vector<int >, vector_to_list<int >>();
245
- to_python_converter<std::vector<std::uint8_t >, vector_to_list<std::uint8_t >>();
246
- to_python_converter<std::vector<lt::tcp::endpoint>, vector_to_list<lt::tcp::endpoint>>();
247
- to_python_converter<std::vector<lt::udp::endpoint>, vector_to_list<lt::udp::endpoint>>();
248
- to_python_converter<std::vector<std::pair<std::string, int >>, vector_to_list<std::pair<std::string, int >>>();
242
+ to_python_converter<std::vector<lt::stats_metric>, vector_to_list<std::vector< lt::stats_metric> >>();
243
+ to_python_converter<std::vector<lt::open_file_state>, vector_to_list<std::vector< lt::open_file_state> >>();
244
+ to_python_converter<std::vector<lt::sha1_hash>, vector_to_list<std::vector< lt::sha1_hash> >>();
245
+ to_python_converter<std::vector<std::string>, vector_to_list<std::vector<std:: string> >>();
246
+ to_python_converter<std::vector<int >, vector_to_list<std::vector< int > >>();
247
+ to_python_converter<std::vector<std::uint8_t >, vector_to_list<std::vector<std:: uint8_t > >>();
248
+ to_python_converter<std::vector<lt::tcp::endpoint>, vector_to_list<std::vector< lt::tcp::endpoint> >>();
249
+ to_python_converter<std::vector<lt::udp::endpoint>, vector_to_list<std::vector< lt::udp::endpoint> >>();
250
+ to_python_converter<std::vector<std::pair<std::string, int >>, vector_to_list<std::vector<std:: pair<std::string, int > >>>();
249
251
250
252
to_python_converter<lt::piece_index_t , from_strong_typedef<lt::piece_index_t >>();
251
253
to_python_converter<lt::file_index_t , from_strong_typedef<lt::file_index_t >>();
252
254
255
+ // work-around types
256
+ to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple<
257
+ lt::aux::noexcept_movable<lt::address>>>();
258
+ to_python_converter<lt::aux::noexcept_movable<lt::tcp::endpoint>, endpoint_to_tuple<
259
+ lt::aux::noexcept_movable<lt::tcp::endpoint>>>();
260
+ to_python_converter<lt::aux::noexcept_movable<lt::udp::endpoint>, endpoint_to_tuple<
261
+ lt::aux::noexcept_movable<lt::udp::endpoint>>>();
262
+ to_python_converter<lt::aux::noexcept_movable<std::vector<lt::stats_metric>>, vector_to_list<lt::aux::noexcept_movable<std::vector<lt::stats_metric>>>>();
263
+ to_python_converter<lt::aux::noexcept_movable<std::vector<lt::open_file_state>>, vector_to_list<lt::aux::noexcept_movable<std::vector<lt::open_file_state>>>>();
264
+ to_python_converter<lt::aux::noexcept_movable<std::vector<lt::sha1_hash>>, vector_to_list<lt::aux::noexcept_movable<std::vector<lt::sha1_hash>>>>();
265
+ to_python_converter<lt::aux::noexcept_movable<std::vector<std::string>>, vector_to_list<lt::aux::noexcept_movable<std::vector<std::string>>>>();
266
+ to_python_converter<lt::aux::noexcept_movable<std::vector<int >>, vector_to_list<lt::aux::noexcept_movable<std::vector<int >>>>();
267
+ to_python_converter<lt::aux::noexcept_movable<std::vector<std::uint8_t >>, vector_to_list<lt::aux::noexcept_movable<std::vector<std::uint8_t >>>>();
268
+ to_python_converter<lt::aux::noexcept_movable<std::vector<lt::tcp::endpoint>>, vector_to_list<lt::aux::noexcept_movable<std::vector<lt::tcp::endpoint>>>>();
269
+ to_python_converter<lt::aux::noexcept_movable<std::vector<lt::udp::endpoint>>, vector_to_list<lt::aux::noexcept_movable<std::vector<lt::udp::endpoint>>>>();
270
+ to_python_converter<lt::aux::noexcept_movable<std::vector<std::pair<std::string, int >>>, vector_to_list<lt::aux::noexcept_movable<std::vector<std::pair<std::string, int >>>>>();
271
+
253
272
// python -> C++ conversions
254
273
tuple_to_pair<int , int >();
255
274
tuple_to_pair<std::string, int >();
256
275
tuple_to_endpoint<lt::tcp::endpoint>();
257
276
tuple_to_endpoint<lt::udp::endpoint>();
258
277
tuple_to_pair<lt::piece_index_t , int >();
259
278
dict_to_map<lt::file_index_t , std::string>();
260
- list_to_vector<int >();
261
- list_to_vector<std::uint8_t >();
262
- list_to_vector<std::string>();
263
- list_to_vector<lt::tcp::endpoint>();
264
- list_to_vector<lt::udp::endpoint>();
265
- list_to_vector<std::pair<std::string, int >>();
279
+ list_to_vector<std::vector<int >>();
280
+ list_to_vector<std::vector<std::uint8_t >>();
281
+ list_to_vector<std::vector<std::string>>();
282
+ list_to_vector<std::vector<lt::tcp::endpoint>>();
283
+ list_to_vector<std::vector<lt::udp::endpoint>>();
284
+ list_to_vector<std::vector<std::pair<std::string, int >>>();
285
+
286
+ // work-around types
287
+ list_to_vector<lt::aux::noexcept_movable<std::vector<int >>>();
288
+ list_to_vector<lt::aux::noexcept_movable<std::vector<std::uint8_t >>>();
289
+ list_to_vector<lt::aux::noexcept_movable<std::vector<std::string>>>();
290
+ list_to_vector<lt::aux::noexcept_movable<std::vector<lt::tcp::endpoint>>>();
291
+ list_to_vector<lt::aux::noexcept_movable<std::vector<lt::udp::endpoint>>>();
292
+ list_to_vector<lt::aux::noexcept_movable<std::vector<std::pair<std::string, int >>>>();
266
293
267
294
to_strong_typedef<lt::piece_index_t >();
268
295
to_strong_typedef<lt::file_index_t >();
0 commit comments