static PyObject *PyView_relocrows(PyView *o, PyObject *_args) { try { PWOSequence args(_args); if (!PyView_Check((PyObject *)args[2])) Fail(PyExc_TypeError, "Third arg must be a view object"); PyView& dest = *(PyView *)(PyObject *)args[2]; int from = PWONumber(args[0]); if (from < 0) from += o->GetSize(); int count = PWONumber(args[1]); if (from < 0 || count < 0 || from + count > o->GetSize()) Fail(PyExc_IndexError, "Source index out of range"); int pos = PWONumber(args[3]); if (pos < 0) pos += dest.GetSize(); if (pos < 0 || pos > dest.GetSize()) Fail(PyExc_IndexError, "Destination index out of range"); if (!o->IsCompatibleWith(dest)) Fail(PyExc_TypeError, "Views are not compatible"); o->RelocateRows(from, count, dest, pos); Py_INCREF(Py_None); return Py_None; } catch (...) { return 0; } }
static PyObject *PyStorage_new(PyObject *o, PyObject *_args) { try { PWOSequence args(_args); PyStorage *ps = 0; switch (args.len()) { case 0: ps = new PyStorage; break; case 1: if (!PyFile_Check((PyObject*)args[0])) { if (PyString_Check((PyObject*)args[0])) Fail(PyExc_TypeError, "rw parameter missing"); else Fail(PyExc_TypeError, "argument not an open file"); break; } ps = new PyStorage(*new c4_FileStrategy(PyFile_AsFile(args[0])), true); break; case 4: { // Rrrrrr... if (!PyStorage_Check((PyObject*)args[0])) Fail(PyExc_TypeError, "First arg must be a storage object"); c4_Storage &storage = *(PyStorage*)(PyObject*)args[0]; if (!PyView_Check((PyObject*)args[1])) Fail(PyExc_TypeError, "Second arg must be a view object"); c4_View &view = *(PyView*)(PyObject*)args[1]; if (!PyProperty_Check((PyObject*)args[2])) Fail(PyExc_TypeError, "Third arg must be a property object"); c4_BytesProp &prop = *(c4_BytesProp*)(c4_Property*)(PyProperty*) (PyObject*)args[2]; int row = PWONumber(args[3]); ps = new PyStorage(*new SiasStrategy(storage, view, prop, row), true); break; } case 2: { char *fnm; int mode; if (!PyArg_ParseTuple(args, "esi", "utf_8", &fnm, &mode)) Fail(PyExc_TypeError, "bad argument type"); ps = new PyStorage(fnm, mode); PyMem_Free(fnm); if (!ps->Strategy().IsValid()) { delete ps; ps = 0; Fail(PyExc_IOError, "can't open storage file"); } break; } default: Fail(PyExc_ValueError, "storage() takes at most 4 arguments"); } return ps; } catch (...) { return 0; } }
static PyObject *PyView_map(PyView *o, PyObject *_args) { try { PWOSequence args(_args); PWOCallable func(args[0]); if (args.len() > 1) { if (!PyView_Check((PyObject *)args[1])) Fail(PyExc_TypeError, "Second arg must be a view object"); PyView& subset = *(PyView *)(PyObject *)args[1]; o->map(func, subset); } else o->map(func); Py_INCREF(Py_None); return Py_None; } catch (...) { return 0; } }