python-cnorxz/cnorxz/base/base.pyx

51 lines
1.2 KiB
Cython
Raw Normal View History

2023-02-22 01:04:45 +01:00
from libcpp.memory cimport shared_ptr, make_shared, dynamic_pointer_cast
from range cimport cpp_RangeBase
from range_factory cimport cpp_RangeFactoryBase, cpp_CRangeFactory
from array cimport cpp_CArrayBase
## ============
## Range
## ============
2023-02-22 01:04:45 +01:00
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
## ===========
## Array
## ===========
cdef class Array:
cdef shared_ptr[cpp_CArrayBase[double]] cpp_array
def size(self):
return self.cpp_array.get().size()
2023-02-22 01:04:45 +01:00