Fix Symbol.__slots__
[linpy.git] / pypol / isl.py
1 import ctypes, ctypes.util
2
3 from . import _isl
4
5
6 libisl = ctypes.CDLL(ctypes.util.find_library('isl'))
7
8 libisl.isl_printer_get_str.restype = ctypes.c_char_p
9 libisl.isl_dim_set = _isl.isl_dim_set
10
11
12 class IslObject:
13
14 __slots__ = (
15 '_ptr',
16 )
17
18 def __init__(self, ptr):
19 self._ptr = ptr
20
21 @property
22 def _as_parameter_(self):
23 return self._ptr
24
25
26 class Context(IslObject):
27
28 def __init__(self):
29 ptr = libisl.isl_ctx_alloc()
30 super().__init__(ptr)
31
32 #comment out so does not delete itself after being created
33 #def __del__(self):
34 # libisl.isl_ctx_free(self)
35
36 def __eq__(self, other):
37 if not isinstance(other, Context):
38 return False
39 return self._ptr == other._ptr
40
41
42 class BasicSet(IslObject):
43
44 def __str__(self):
45 ls = libisl.isl_basic_set_get_local_space(self)
46 ctx = libisl.isl_local_space_get_ctx(ls)
47 p = libisl.isl_printer_to_str(ctx)
48 p = libisl.isl_printer_print_basic_set(p, self)
49 string = libisl.isl_printer_get_str(p).decode()
50 return string
51
52 def __del__(self):
53 libisl.isl_basic_set_free(self)