Implement IslObjects, delete Value
[linpy.git] / pypol / isl.py
1 """
2 note: for islpy
3 isl format: basic set: ("{[x, y] : x >= 0 and x < 5 and y >= 0 and y < x+4 }")
4 """
5
6 import ctypes, ctypes.util
7 import functools
8 import math
9 import numbers
10 import operator
11 import re
12
13
14 libisl = ctypes.CDLL(ctypes.util.find_library('isl'))
15
16 libisl.isl_printer_get_str.restype = ctypes.c_char_p
17
18
19 class IslObject:
20
21 __slots__ = ('_ptr')
22
23 def __init__(self, ptr):
24 self._ptr = ptr
25
26 @property
27 def _as_parameter_(self):
28 return self._ptr
29
30
31 class Context(IslObject):
32
33 def __init__(self):
34 self._ptr = libisl.isl_ctx_alloc()
35
36 #comment out so does not delete itself after being created
37 #def __del__(self):
38 # libisl.isl_ctx_free(self)
39
40 def __eq__(self, other):
41 if not isinstance(other, Context):
42 return False
43 return self._ptr == other._ptr
44
45
46 class BasicSet(IslObject):
47
48 def __str__(self):
49 ls = libisl.isl_basic_set_get_local_space(self)
50 ctx = libisl.isl_local_space_get_ctx(ls)
51 p = libisl.isl_printer_to_str(ctx)
52 p = libisl.isl_printer_print_basic_set(p, self)
53 string = libisl.isl_printer_get_str(p)
54 string = str(string.decode())
55 return string