MCPcopy Create free account
hub / github.com/bab2min/tomotopy / foreachWithPy

Function foreachWithPy

src/python/handler/PyUtils.h:1510–1531  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1508
1509 template<typename T, typename Fn, typename Msg>
1510 inline void foreachWithPy(PyObject* iterable, Fn&& fn, Msg&& failMsg)
1511 {
1512 if (!iterable) throw ConversionFail{ std::forward<Msg>(failMsg) };
1513 UniqueObj iter{ PyObject_GetIter(iterable) }, item;
1514 if (!iter) throw ConversionFail{ std::forward<Msg>(failMsg) };
1515 try
1516 {
1517 while ((item = UniqueObj{ PyIter_Next(iter.get()) }))
1518 {
1519 fn(toCpp<T>(item.get()), item.get());
1520 }
1521 }
1522 catch (const ForeachFailed&)
1523 {
1524 throw ConversionFail{ std::forward<Msg>(failMsg) };
1525 }
1526
1527 if (PyErr_Occurred())
1528 {
1529 throw ConversionFail{ std::forward<Msg>(failMsg) };
1530 }
1531 }
1532
1533#ifdef USE_NUMPY
1534 template<typename _Ty>

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected