00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_PYTHON_PYLIST_HELPER
00008 #define BALL_PYTHON_PYLIST_HELPER
00009
00010 #include <BALL/DATATYPE/regularData3D.h>
00011
00012 namespace BALL
00013 {
00014
00015 typedef std::list<RegularData3D*> RegularData3DList;
00016
00017
00018 #define BALL_CONVERT_LIST_FROM(TYPE)\
00019 PyObject *pl;\
00020 \
00021 if ((pl = PyList_New(0)) == NULL) return NULL;\
00022 \
00023 for (TYPE##List::const_iterator it = sipCpp->begin(); it != sipCpp->end(); ++it)\
00024 {\
00025 PyObject *inst = BALL_CONVERT_FROM_INSTANCE(*it, TYPE, 0);\
00026 \
00027 if (inst == NULL || PyList_Append(pl,inst) < 0)\
00028 {\
00029 Py_DECREF(pl);\
00030 return NULL;\
00031 }\
00032 }\
00033 \
00034 return pl;
00035
00036
00037
00038 #define BALL_CONVERT_LIST_TO(TYPE)\
00039 if (sipIsErr == NULL) return PyList_Check(sipPy);\
00040 \
00041 TYPE##List* alist = new TYPE##List;\
00042 \
00043 for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)\
00044 {\
00045 TYPE* a = reinterpret_cast<TYPE*>(BALL_FORCE_CONVERT_TO_TYPE(PyList_GET_ITEM(sipPy,i), TYPE));\
00046 \
00047 if (*sipIsErr)\
00048 {\
00049 delete alist;\
00050 return 0;\
00051 }\
00052 \
00053 alist->push_back(a);\
00054 }\
00055 \
00056 *sipCppPtr = alist;\
00057 \
00058 return 1;
00059
00060 }
00061
00062 #endif