From fc48ae135faccaf8e5a4e4dd3679e907ba2f0a6c Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Wed, 10 May 2023 01:21:30 +0200 Subject: [PATCH] start cereal wrappers (move to separate submodule in the future...) --- cnorxz/base/base.pyx | 10 ++++++++++ cnorxz/base/cereal.pxd | 15 +++++++++++++++ setup.py | 1 + 3 files changed, 26 insertions(+) create mode 100644 cnorxz/base/cereal.pxd diff --git a/cnorxz/base/base.pyx b/cnorxz/base/base.pyx index ae58ddf..3b1f4ef 100644 --- a/cnorxz/base/base.pyx +++ b/cnorxz/base/base.pyx @@ -9,10 +9,12 @@ from libcpp.memory cimport shared_ptr, make_shared, dynamic_pointer_cast from libcpp.string cimport string from libcpp cimport bool +from cython.operator cimport dereference as deref from range cimport cpp_RangeBase from range_factory cimport cpp_RangeFactoryBase, cpp_CRangeFactory from array cimport cpp_CArrayBase, cpp_MArray from index cimport cpp_DIndex +from cereal cimport cpp_writeJSONFile ## ============ @@ -152,3 +154,11 @@ def getSubRange(_range): cdef Array_Range a = Array_Range() a.cpp_array = dynamic_pointer_cast[cpp_CArrayBase[shared_ptr[cpp_RangeBase]],cpp_MArray[shared_ptr[cpp_RangeBase]]] (make_shared[cpp_MArray[shared_ptr[cpp_RangeBase]]] (r.cpp_range.get().sub()) ) return a + + +def writeJSONFile(_fname,_array): + cdef Array_Double a = _array + cdef shared_ptr[cpp_MArray[double]] ap = dynamic_pointer_cast[cpp_MArray[double],cpp_CArrayBase[double]](a.cpp_array) + cpp_writeJSONFile[double](_fname, deref(ap.get())) + + diff --git a/cnorxz/base/cereal.pxd b/cnorxz/base/cereal.pxd new file mode 100644 index 0000000..f31d89f --- /dev/null +++ b/cnorxz/base/cereal.pxd @@ -0,0 +1,15 @@ + +from libcpp.string cimport string +from array cimport cpp_MArray + +cdef extern from "cereal/cnorxz_cereal.h" namespace "CNORXZ::cer": + cdef cppclass cpp_Format "CNORXZ::cer::Format": + pass + +cdef extern from "cereal/cnorxz_cereal.h" namespace "CNORXZ::cer::Format": + cdef cpp_Format BINARY + cdef cpp_Format JSON + cdef cpp_Format XML + +cdef extern from "cereal/cnorxz_cereal.h" namespace "CNORXZ::cer": + cdef void cpp_writeJSONFile "CNORXZ::cer::writeJSONFile" [T] (const string&, const cpp_MArray[T]&) diff --git a/setup.py b/setup.py index f77a2ff..0d485d0 100644 --- a/setup.py +++ b/setup.py @@ -60,6 +60,7 @@ if __name__ == "__main__": sources = [ "cnorxz/base/base.pyx", ], + define_macros=[('HAVE_CEREAL',None)], **default_extension_args ) )