47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
|
|
#include "cnorxz/core/include/array_wrapper.h"
|
|
|
|
using namespace CNORXZ
|
|
|
|
static int PyCArrayB_init(CArrayWrapperBase* self, PyObject* args, PyObject* kwds)
|
|
{
|
|
static char* kwlist[] = { "type", "extension" , NULL };
|
|
SizeT ext = 0;
|
|
const char* type;
|
|
|
|
if(not PyArg_ParseTupleAndKeywords(args, kwds, "s|k", kwlist, &type, &ext)){
|
|
return NULL;
|
|
}
|
|
|
|
if(ext != 0){
|
|
RangePtr r = CRangeFactory(ext).create();
|
|
self->ptrObj = new CArrayBase<T>(r);
|
|
}
|
|
else {
|
|
self->ptrObj = new CArrayBase<T>();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void PyCArrayB_dealloc(CArrayWrapperBase* self)
|
|
{
|
|
delete self->ptrObject;
|
|
Py_TYPE(self)->tp_free(self);
|
|
}
|
|
|
|
static PyObject* PyCArrayB_size(CArrayWrapperBase* self)
|
|
{
|
|
if(not self->ptrObj->range()){
|
|
PyErr_SetString(PyExc_RuntimeError, "array not initialized");
|
|
return NULL;
|
|
}
|
|
const SizeT retval = self->ptrObj->size();
|
|
return Py_BuildValue("k",retval);
|
|
}
|
|
|
|
static PyMethodDef PyCArrayB_methods[] = {
|
|
{ "size", (PyCFunction)PyCArrayB_size, METH_VARARGS, "return size of the array" },
|
|
{ NULL }
|
|
};
|
|
|