32 lines
920 B
Cython
32 lines
920 B
Cython
|
|
from libcpp.memory cimport shared_ptr, make_shared, dynamic_pointer_cast
|
|
from range cimport cpp_RangeBase
|
|
from range_factory cimport cpp_RangeFactoryBase, cpp_CRangeFactory
|
|
|
|
cdef class Range:
|
|
cdef shared_ptr[cpp_RangeBase] cpp_range
|
|
|
|
def size(self):
|
|
return self.cpp_range.get().size()
|
|
|
|
def dim(self):
|
|
return self.cpp_range.get().dim()
|
|
|
|
|
|
cdef class RangeFactory:
|
|
cdef shared_ptr[cpp_RangeFactoryBase] cpp_rfactory
|
|
|
|
def __cinit__(self,rangetype,**kvargs):
|
|
cdef size_t size = 0
|
|
if rangetype == 'C':
|
|
size = kvargs['size']
|
|
self.cpp_rfactory = dynamic_pointer_cast[cpp_RangeFactoryBase,cpp_CRangeFactory](
|
|
make_shared[cpp_CRangeFactory](size))
|
|
else:
|
|
raise Exception('unknown range type:'+ rangetype)
|
|
|
|
def create(self):
|
|
r = Range()
|
|
r.cpp_range = self.cpp_rfactory.get().create()
|
|
return r
|
|
|