@@ -155,7 +155,7 @@ struct PyArrayElementComparator
155155template <template <class , class , int > class Class , class ... Types>
156156void registerArray (pybind11::module_& m)
157157{
158- using namespace yup ;
158+ // clang-format off
159159
160160 namespace py = pybind11;
161161 using namespace py ::literals;
@@ -181,38 +181,40 @@ void registerArray (pybind11::module_& m)
181181 .def (py::init<const ValueType&>())
182182 .def (py::init<const T&>())
183183 .def (py::init ([] (py::list list)
184- {
185- auto result = T ();
186- result.ensureStorageAllocated (static_cast <int > (list.size ()));
187-
188- for (auto item : list)
189184 {
190- py::detail::make_caster<ValueType> conv;
185+ auto result = T ();
186+ result.ensureStorageAllocated (static_cast <int > (list.size ()));
191187
192- if (! conv.load (item, true ))
193- py::pybind11_fail (" Invalid value type used to feed \" Array\" constructor" );
188+ for (auto item : list)
189+ {
190+ py::detail::make_caster<ValueType> conv;
194191
195- result. add (py::detail::cast_op<ValueType&&> ( std::move ( conv)));
196- }
192+ if (! conv. load (item, true ))
193+ py::pybind11_fail ( " Invalid value type used to feed \" Array \" constructor " );
197194
198- return result;
199- })).def (py::init ([] (py::args args)
200- {
201- auto result = T ();
202- result.ensureStorageAllocated (static_cast <int > (args.size ()));
195+ result.add (py::detail::cast_op<ValueType&&> (std::move (conv)));
196+ }
203197
204- for (auto item : args)
198+ return result;
199+ }))
200+ .def (py::init ([] (py::args args)
205201 {
206- py::detail::make_caster<ValueType> conv;
202+ auto result = T ();
203+ result.ensureStorageAllocated (static_cast <int > (args.size ()));
204+
205+ for (auto item : args)
206+ {
207+ py::detail::make_caster<ValueType> conv;
207208
208- if (! conv.load (item, true ))
209- py::pybind11_fail (" Invalid value type used to feed \" Array\" constructor" );
209+ if (! conv.load (item, true ))
210+ py::pybind11_fail (" Invalid value type used to feed \" Array\" constructor" );
210211
211- result.add (py::detail::cast_op<ValueType&&> (std::move (conv)));
212- }
212+ result.add (py::detail::cast_op<ValueType&&> (std::move (conv)));
213+ }
213214
214- return result;
215- })).def (" clear" , &T::clear)
215+ return result;
216+ }))
217+ .def (" clear" , &T::clear)
216218 .def (" clearQuick" , &T::clearQuick)
217219 .def (" fill" , &T::fill)
218220 .def (" size" , &T::size)
@@ -225,69 +227,73 @@ void registerArray (pybind11::module_& m)
225227 .def (" getLast" , &T::getLast)
226228 // .def ("getRawDataPointer", &T::getRawDataPointer)
227229 .def (" __iter__" , [] (T& self)
228- {
229- return py::make_iterator (self.begin (), self.end ());
230- },
231- py::keep_alive<0 , 1 >())
230+ {
231+ return py::make_iterator (self.begin (), self.end ());
232+ }, py::keep_alive<0 , 1 >())
232233 .def (" add" , [] (T& self, const ValueType& arg)
233- {
234- self.add (arg);
235- }).def (" add" , [] (T& self, py::list list)
236- {
237- self.ensureStorageAllocated (self.size () + static_cast <int > (list.size ()));
238-
239- for (auto item : list)
240234 {
241- py::detail::make_caster<ValueType> conv;
235+ self.add (arg);
236+ })
237+ .def (" add" , [] (T& self, py::list list)
238+ {
239+ self.ensureStorageAllocated (self.size () + static_cast <int > (list.size ()));
242240
243- if (! conv.load (item, true ))
244- py::pybind11_fail (" Invalid value type used to feed \" Array.add\" " );
241+ for (auto item : list)
242+ {
243+ py::detail::make_caster<ValueType> conv;
245244
246- self.add (py::detail::cast_op<ValueType&&> (std::move (conv)));
247- }
248- }).def (" add" , [] (T& self, py::args args)
249- {
250- self.ensureStorageAllocated (self.size () + static_cast <int > (args.size ()));
245+ if (! conv.load (item, true ))
246+ py::pybind11_fail (" Invalid value type used to feed \" Array.add\" " );
251247
252- for (auto item : args)
248+ self.add (py::detail::cast_op<ValueType&&> (std::move (conv)));
249+ }
250+ })
251+ .def (" add" , [] (T& self, py::args args)
253252 {
254- py::detail::make_caster<ValueType> conv;
253+ self.ensureStorageAllocated (self.size () + static_cast <int > (args.size ()));
254+
255+ for (auto item : args)
256+ {
257+ py::detail::make_caster<ValueType> conv;
255258
256- if (! conv.load (item, true ))
257- py::pybind11_fail (" Invalid value type used to feed \" Array.add\" " );
259+ if (! conv.load (item, true ))
260+ py::pybind11_fail (" Invalid value type used to feed \" Array.add\" " );
258261
259- self.add (py::detail::cast_op<ValueType&&> (std::move (conv)));
260- }
261- }).def (" insert" , &T::insert)
262+ self.add (py::detail::cast_op<ValueType&&> (std::move (conv)));
263+ }
264+ })
265+ .def (" insert" , &T::insert)
262266 .def (" insertMultiple" , &T::insertMultiple)
263267 // .def ("insertArray", &T::insertArray)
264268 .def (" set" , &T::set)
265269 .def (" setUnchecked" , &T::setUnchecked)
266270 // .def ("addArray", &T::addArray)
267271 .def (" addArray" , [] (T& self, py::list list)
268- {
269- for (auto item : list)
270272 {
271- py::detail::make_caster<ValueType> conv;
273+ for (auto item : list)
274+ {
275+ py::detail::make_caster<ValueType> conv;
272276
273- if (! conv.load (item, true ))
274- py::pybind11_fail (" Invalid value type used to feed \" Array.addArray\" " );
277+ if (! conv.load (item, true ))
278+ py::pybind11_fail (" Invalid value type used to feed \" Array.addArray\" " );
275279
276- self.add (py::detail::cast_op<ValueType&&> (std::move (conv)));
277- }
278- }).def (" swapWith" , &T::template swapWith<T>)
280+ self.add (py::detail::cast_op<ValueType&&> (std::move (conv)));
281+ }
282+ })
283+ .def (" swapWith" , &T::template swapWith<T>)
279284 .def (" addArray" , py::overload_cast<const T&> (&T::template addArray<T>))
280285 .def (" resize" , &T::resize)
281286 .def (" remove" , py::overload_cast<int > (&T::remove))
282287 .def (" removeAndReturn" , &T::removeAndReturn)
283288 .def (" remove" , py::overload_cast<const ValueType*> (&T::remove))
284289 .def (" removeIf" , [] (T& self, py::function predicate)
285- {
286- return self.removeIf ([&predicate] (const ValueType& value)
287290 {
288- return predicate (py::cast (value)).template cast <bool >();
289- });
290- }).def (" removeRange" , &T::removeRange)
291+ return self.removeIf ([&predicate] (const ValueType& value)
292+ {
293+ return predicate (py::cast (value)).template cast <bool >();
294+ });
295+ })
296+ .def (" removeRange" , &T::removeRange)
291297 .def (" removeLast" , &T::removeLast)
292298 .def (" swap" , &T::swap)
293299 .def (" move" , &T::move, " currentIndex" _a, " newIndex" _a)
@@ -296,19 +302,21 @@ void registerArray (pybind11::module_& m)
296302 .def (" getLock" , &T::getLock)
297303 .def (" __len__" , &T::size)
298304 .def (" __repr__" , [className] (T& self)
299- {
300- String result;
301- result
302- << " <" << Helpers::pythonizeModuleClassName (PythonModuleName, typeid (T).name (), 1 )
303- << " object at " << String::formatted (" %p" , std::addressof (self)) << " >" ;
304- return result;
305- });
305+ {
306+ String result;
307+ result
308+ << " <" << Helpers::pythonizeModuleClassName (PythonModuleName, typeid (T).name (), 1 )
309+ << " object at " << String::formatted (" %p" , std::addressof (self)) << " >" ;
310+ return result;
311+ });
306312
307313 if constexpr (! std::is_same_v<ValueType, Types>)
314+ {
308315 class_.def (py::init ([] (Types value)
309316 {
310317 return T (static_cast <ValueType> (value));
311318 }));
319+ }
312320
313321 if constexpr (isEqualityComparable<ValueType>::value)
314322 {
@@ -320,24 +328,25 @@ void registerArray (pybind11::module_& m)
320328 .def (" addIfNotAlreadyThere" , &T::addIfNotAlreadyThere)
321329 .def (" addUsingDefaultSort" , &T::addUsingDefaultSort)
322330 .def (" addSorted" , [] (T& self, PyArrayElementComparator<ValueType>& comparator, ValueType value)
323- {
324- self.addSorted (comparator, value);
325- }).def (" indexOfSorted" , [] (const T& self, PyArrayElementComparator<ValueType>& comparator, ValueType value)
326- {
327- return self.indexOfSorted (comparator, value);
328- }).def (" removeValuesIn" , &T::template removeValuesIn<T>)
331+ {
332+ self.addSorted (comparator, value);
333+ })
334+ .def (" indexOfSorted" , [] (const T& self, PyArrayElementComparator<ValueType>& comparator, ValueType value)
335+ {
336+ return self.indexOfSorted (comparator, value);
337+ })
338+ .def (" removeValuesIn" , &T::template removeValuesIn<T>)
329339 .def (" removeValuesNotIn" , &T::template removeValuesNotIn<T>)
330340 .def (" removeFirstMatchingValue" , &T::removeFirstMatchingValue)
331341 .def (" removeAllInstancesOf" , &T::removeAllInstancesOf)
332342 .def (" sort" , [] (T& self)
333- {
334- self.sort ();
335- }).def (" sort" , [] (T& self, PyArrayElementComparator<ValueType>& comparator, int retainOrderOfEquivalentItems)
336- {
337- self.sort (comparator, retainOrderOfEquivalentItems);
338- },
339- " comparator" _a,
340- " retainOrderOfEquivalentItems" _a = false );
343+ {
344+ self.sort ();
345+ })
346+ .def (" sort" , [] (T& self, PyArrayElementComparator<ValueType>& comparator, int retainOrderOfEquivalentItems)
347+ {
348+ self.sort (comparator, retainOrderOfEquivalentItems);
349+ }, " comparator" _a, " retainOrderOfEquivalentItems" _a = false );
341350 }
342351
343352 type[py::type::of (py::cast (Types {}))] = class_;
@@ -346,11 +355,13 @@ void registerArray (pybind11::module_& m)
346355 }() && ...);
347356
348357 m.attr (" Array" ) = type;
358+
359+ // clang-format on
349360}
350361
351362// ==============================================================================
352363
353- struct PyThreadID
364+ struct YUP_API PyThreadID
354365{
355366 explicit PyThreadID (Thread::ThreadID value) noexcept
356367 : value (value)
@@ -538,7 +549,7 @@ template <class Base = OutputStream>
538549struct PyOutputStream : Base
539550{
540551private:
541- #if JUCE_WINDOWS && ! JUCE_MINGW
552+ #if YUP_WINDOWS
542553 using ssize_t = pointer_sized_int;
543554#endif
544555
0 commit comments