BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
pyListHelper.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 // $Id: pyListHelper.h,v 1.1.2.2 2007/03/28 15:43:38 amoll Exp $
5 //
6 //
7 #ifndef BALL_PYTHON_PYLIST_HELPER
8 #define BALL_PYTHON_PYLIST_HELPER
9 
11 
12 namespace BALL
13 {
14 
15 typedef std::list<RegularData3D*> RegularData3DList;
16 
17 // Convert the list.
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 // Convert a Python list of TYPE instances to a TYPEList object on the heap.
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