wrap more functions in Range wrapper
This commit is contained in:
parent
034a9bcc8e
commit
6a6e1c823c
5 changed files with 49 additions and 5 deletions
|
@ -5,12 +5,17 @@
|
|||
|
||||
using namespace CNORXZ;
|
||||
|
||||
static PyMethodDef cnorxz_core_methods[] = {
|
||||
{ "readFile", (PyCFunction) PyCxReadFile, METH_VARARGS| METH_KEYWORDS, "Read cnorxz-formatted file." },
|
||||
{ NULL, NULL, 0, NULL }
|
||||
};
|
||||
|
||||
static PyModuleDef cnorxz_core_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"cnorxz",
|
||||
"cnorxz core module",
|
||||
-1,
|
||||
NULL, NULL, NULL, NULL, NULL
|
||||
cnorxz_core_methods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_cnorxz()
|
||||
|
|
|
@ -113,6 +113,8 @@ PyObject* PyCxArrayB_writeFile(PyCxArrayB* self, PyObject* args, PyObject* kwds)
|
|||
PyObject* PyCxArrayB_readFile(PyCxArrayB* self, PyObject* args, PyObject* kwds);
|
||||
PyTypeObject* PyCxArrayBType_init();
|
||||
|
||||
PyObject* PyCxReadFile(PyObject* self, PyObject* args, PyObject* kwds);
|
||||
|
||||
extern PyMethodDef PyCxArrayB_methods[];
|
||||
extern PyTypeObject PyCxArrayBType;
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace CNORXZ
|
|||
inline bool _init() const { return mR != nullptr; }
|
||||
inline SizeT size() const { return mR->size(); }
|
||||
inline SizeT dim() const { return mR->dim(); }
|
||||
inline RangePtr sub(SizeT pos) { return mR->sub(pos); }
|
||||
inline String stringMeta(SizeT pos) const { return mR->stringMeta(pos); }
|
||||
|
||||
private:
|
||||
|
@ -32,6 +33,7 @@ int PyCxRange_init(PyCxRange* self, PyObject* args, PyObject* kwds);
|
|||
void PyCxRange_dealloc(PyCxRange* self);
|
||||
PyObject* PyCxRange_size(PyCxRange* self);
|
||||
PyObject* PyCxRange_dim(PyCxRange* self);
|
||||
PyObject* PyCxRange_sub(PyCxRange* self, PyObject* args, PyObject* kwds);
|
||||
PyObject* PyCxRange_stringMeta(PyCxRange* self, PyObject* args, PyObject* kwds);
|
||||
PyTypeObject* PyCxRangeType_init();
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ PyObject* PyCxArrayB_range(PyCxArrayB* self)
|
|||
PyCxRange* o;
|
||||
o = PyObject_New(PyCxRange, &PyCxRangeType);
|
||||
o->ptrObj = new RangeWrapper(r);
|
||||
//return Py_BuildValue("k", retval);
|
||||
return Py_BuildValue("O", o);
|
||||
}
|
||||
|
||||
|
@ -88,7 +87,7 @@ PyObject* PyCxArrayB_writeFile(PyCxArrayB* self, PyObject* args, PyObject* kwds)
|
|||
char* fname = NULL;
|
||||
char* format = NULL;
|
||||
|
||||
if(not PyArg_ParseTupleAndKeywords(args, kwds, "s|s", kwlist, &fname, &format)){
|
||||
if(not PyArg_ParseTupleAndKeywords(args, kwds, "ss|", kwlist, &fname, &format)){
|
||||
return NULL;
|
||||
}
|
||||
const String fn(fname);
|
||||
|
@ -103,7 +102,7 @@ PyObject* PyCxArrayB_readFile(PyCxArrayB* self, PyObject* args, PyObject* kwds)
|
|||
char* fname = NULL;
|
||||
char* format = NULL;
|
||||
|
||||
if(not PyArg_ParseTupleAndKeywords(args, kwds, "s|s", kwlist, &fname, &format)){
|
||||
if(not PyArg_ParseTupleAndKeywords(args, kwds, "ss|", kwlist, &fname, &format)){
|
||||
return NULL;
|
||||
}
|
||||
const String fn(fname);
|
||||
|
@ -176,3 +175,11 @@ PyTypeObject* PyCxArrayBType_init()
|
|||
return &PyCxArrayBType;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* PyCxReadFile(PyObject* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
PyCxArrayB* out = (PyCxArrayB*) PyObject_NEW(PyCxArrayB, &PyCxArrayBType);
|
||||
out->ptrObj = new ArrayWrapper<Double>();
|
||||
PyCxArrayB_readFile(out,args,kwds);
|
||||
return Py_BuildValue("O", out);;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ using namespace CNORXZ;
|
|||
|
||||
int PyCxRange_init(PyCxRange* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
|
||||
//!!!
|
||||
}
|
||||
|
||||
|
@ -34,14 +35,41 @@ PyObject* PyCxRange_dim(PyCxRange* self)
|
|||
return Py_BuildValue("k", retval);
|
||||
}
|
||||
|
||||
PyObject* PyCxRange_sub(PyCxRange* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
static char* kwlist[] = { "pos", NULL };
|
||||
SizeT pos = 0;
|
||||
|
||||
if(not PyArg_ParseTupleAndKeywords(args, kwds, "k|", kwlist, &pos)){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SizeT dim = self->ptrObj->dim();
|
||||
if(pos >= dim){
|
||||
return PyErr_Format(PyExc_RuntimeError, "requested sub-range position (%d) exceeds range dimension (%d)", pos, dim);
|
||||
}
|
||||
|
||||
const RangePtr r = self->ptrObj->sub(pos);
|
||||
PyCxRange* o = PyObject_New(PyCxRange, &PyCxRangeType);
|
||||
o->ptrObj = new RangeWrapper(r);
|
||||
return Py_BuildValue("O", o);
|
||||
}
|
||||
|
||||
PyObject* PyCxRange_stringMeta(PyCxRange* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
//!!!
|
||||
const SizeT size = self->ptrObj->size();
|
||||
PyObject* out = PyList_New(size);
|
||||
for(SizeT i = 0; i != size; ++i){
|
||||
PyObject* s = Py_BuildValue("s", self->ptrObj->stringMeta(i).c_str() );
|
||||
PyList_SetItem(out, i, s);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
PyMethodDef PyCxRange_methods[] = {
|
||||
{ "size", (PyCFunction) PyCxRange_size, METH_VARARGS, "return range size" },
|
||||
{ "dim", (PyCFunction) PyCxRange_dim, METH_VARARGS, "return range dimension" },
|
||||
{ "sub", (PyCFunction) PyCxRange_sub, METH_VARARGS|METH_KEYWORDS, "return sub-range for given dimension" },
|
||||
{ "stringMeta", (PyCFunction) PyCxRange_stringMeta, METH_VARARGS,
|
||||
"return string meta data for given range position" },
|
||||
{ NULL }
|
||||
|
|
Loading…
Reference in a new issue