Add _repr_latex_ methods for IPython prettyprint
[linpy.git] / pypol / _islhelper.c
1 #include <Python.h>
2
3 #include <isl/constraint.h>
4 #include <isl/set.h>
5 #include <isl/vertices.h>
6
7
8 static inline int _append_pointer_to_list(void *pointer, void *user) {
9 PyObject *list, *item;
10 list = (PyObject *) user;
11 item = PyLong_FromVoidPtr(pointer);
12 if (item == NULL) {
13 return -1;
14 }
15 return PyList_Append(list, item);
16 }
17
18 static int _append_constraint_to_list(isl_constraint *constraint, void *user) {
19 return _append_pointer_to_list((void *) constraint, user);
20 }
21
22 static PyObject * isl_basic_set_constraints(PyObject *self, PyObject *args) {
23 long pointer;
24 isl_basic_set *bset;
25 PyObject *list;
26 if (!PyArg_ParseTuple(args, "l", &pointer)) {
27 return NULL;
28 }
29 bset = (isl_basic_set *) pointer;
30 list = PyList_New(0);
31 if (list == NULL) {
32 return NULL;
33 }
34 if (isl_basic_set_foreach_constraint(bset, _append_constraint_to_list, list) == -1) {
35 PyErr_SetString(PyExc_RuntimeError,
36 "an error occurred in isl_basic_set_foreach_constraint");
37 Py_DECREF(list);
38 return NULL;
39 }
40 return list;
41 }
42
43 static int _append_basic_set_to_list(isl_basic_set *bset, void *user) {
44 return _append_pointer_to_list((void *) bset, user);
45 }
46
47 static PyObject * isl_set_basic_sets(PyObject *self, PyObject *args) {
48 long pointer;
49 isl_set *set;
50 PyObject *list;
51 if (!PyArg_ParseTuple(args, "l", &pointer)) {
52 return NULL;
53 }
54 set = (isl_set *) pointer;
55 list = PyList_New(0);
56 if (list == NULL) {
57 return NULL;
58 }
59 if (isl_set_foreach_basic_set(set, _append_basic_set_to_list, list) == -1) {
60 PyErr_SetString(PyExc_RuntimeError,
61 "an error occurred in isl_set_foreach_basic_set");
62 Py_DECREF(list);
63 return NULL;
64 }
65 return list;
66 }
67
68 static int _append_point_to_list(isl_point *point, void* user) {
69 return _append_pointer_to_list((void *) point, user);
70 }
71
72 static PyObject * isl_set_points(PyObject *self, PyObject *args) {
73 long pointer;
74 isl_set *set;
75 PyObject *list;
76 if (!PyArg_ParseTuple(args, "l", &pointer)) {
77 return NULL;
78 }
79 set = (isl_set *) pointer;
80 list = PyList_New(0);
81 if (list == NULL) {
82 return NULL;
83 }
84 if (isl_set_foreach_point(set, _append_point_to_list, list) == -1) {
85 PyErr_SetString(PyExc_RuntimeError,
86 "an error occurred in isl_set_foreach_point");
87 Py_DECREF(list);
88 return NULL;
89 }
90 return list;
91 }
92
93 static int _append_vertex_to_list(isl_vertex *vertex, void* user) {
94 return _append_pointer_to_list((void *) vertex, user);
95 }
96
97 static PyObject * isl_vertices_vertices(PyObject *self, PyObject *args) {
98 long pointer;
99 isl_vertices *vertices;
100 PyObject *list;
101 if (!PyArg_ParseTuple(args, "l", &pointer)) {
102 return NULL;
103 }
104 vertices = (isl_vertices *) pointer;
105 list = PyList_New(0);
106 if (list == NULL) {
107 return NULL;
108 }
109 if (isl_vertices_foreach_vertex(vertices, _append_vertex_to_list, list) == -1) {
110 PyErr_SetString(PyExc_RuntimeError,
111 "an error occurred in isl_vertices_foreach_vertex");
112 Py_DECREF(list);
113 return NULL;
114 }
115 return list;
116 }
117
118
119 static PyMethodDef _islhelper_methods[] = {
120 {"isl_basic_set_constraints", isl_basic_set_constraints, METH_VARARGS, NULL},
121 {"isl_set_basic_sets", isl_set_basic_sets, METH_VARARGS, NULL},
122 {"isl_set_points", isl_set_points, METH_VARARGS, NULL},
123 {"isl_vertices_vertices", isl_vertices_vertices, METH_VARARGS, NULL},
124 {NULL, NULL, 0, NULL}
125 };
126
127 static struct PyModuleDef _islhelpermodule = {
128 PyModuleDef_HEAD_INIT,
129 "_islhelper",
130 NULL,
131 0,
132 _islhelper_methods
133 };
134
135 PyMODINIT_FUNC PyInit__islhelper(void) {
136 PyObject *m;
137 m = PyModule_Create(&_islhelpermodule);
138 if (m == NULL) {
139 return NULL;
140 }
141 if (PyModule_AddObject(m, "dim_set", PyLong_FromLong(isl_dim_set)) == -1) {
142 return NULL;
143 }
144 return m;
145 }