| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#ifndef BALL_PYTHON_PYLIST_HELPER |
| 8 |
#define BALL_PYTHON_PYLIST_HELPER |
| 9 |
|
| 10 |
#include <BALL/DATATYPE/regularData3D.h> |
| 11 |
|
| 12 |
namespace BALL |
| 13 |
{ |
| 14 |
|
| 15 |
typedef std::list<RegularData3D*> RegularData3DList; |
| 16 |
|
| 17 |
|
| 18 |
#define BALL_CONVERT_LIST_FROM(TYPE)\ |
| 19 |
PyObject *pl;\ |
| 20 |
\ |
| 21 |
if ((pl = PyList_New(0)) == NULL) return NULL;\ |
| 22 |
\ |
| 23 |
for (TYPE##List::const_iterator it = sipCpp->begin(); it != sipCpp->end(); ++it)\ |
| 24 |
{\ |
| 25 |
PyObject *inst = BALL_CONVERT_FROM_INSTANCE(*it, TYPE, 0);\ |
| 26 |
\ |
| 27 |
if (inst == NULL || PyList_Append(pl,inst) < 0)\ |
| 28 |
{\ |
| 29 |
Py_DECREF(pl);\ |
| 30 |
return NULL;\ |
| 31 |
}\ |
| 32 |
}\ |
| 33 |
\ |
| 34 |
return pl; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#define BALL_CONVERT_LIST_TO(TYPE)\ |
| 39 |
if (sipIsErr == NULL) return PyList_Check(sipPy);\ |
| 40 |
\ |
| 41 |
TYPE##List* alist = new TYPE##List;\ |
| 42 |
\ |
| 43 |
for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)\ |
| 44 |
{\ |
| 45 |
TYPE* a = reinterpret_cast<TYPE*>(BALL_FORCE_CONVERT_TO_TYPE(PyList_GET_ITEM(sipPy,i), TYPE));\ |
| 46 |
\ |
| 47 |
if (*sipIsErr)\ |
| 48 |
{\ |
| 49 |
delete alist;\ |
| 50 |
return 0;\ |
| 51 |
}\ |
| 52 |
\ |
| 53 |
alist->push_back(a);\ |
| 54 |
}\ |
| 55 |
\ |
| 56 |
*sipCppPtr = alist;\ |
| 57 |
\ |
| 58 |
return 1; |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
#endif |