From 3a1432212f10f7272dddb3c5bac9e75c1651908e Mon Sep 17 00:00:00 2001 From: John McCardle Date: Sat, 9 Sep 2023 10:14:11 -0400 Subject: [PATCH] UICollection.remove --- src/UI.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/UI.h b/src/UI.h index 13c97a8..5c26e8a 100644 --- a/src/UI.h +++ b/src/UI.h @@ -1062,11 +1062,27 @@ switch (target->derived_type()) \ static PyObject* PyUICollection_remove(PyUICollectionObject* self, PyObject* o) { - // if (!PyLong_Check(o)) { //exception text; return -1; } - // long index = PyLong_AsLong(o); - // if (index >= self->data->size()) { //exception text; return -1; } + if (!PyLong_Check(o)) + { + PyErr_SetString(PyExc_TypeError, "UICollection.remove requires an integer index to remove"); + return NULL; + } + long index = PyLong_AsLong(o); + if (index >= self->data->size()) + { + PyErr_SetString(PyExc_ValueError, "Index out of range"); + return NULL; + } + else if (index < 0) + { + PyErr_SetString(PyExc_NotImplementedError, "reverse indexing is not implemented."); + return NULL; + } + // release the shared pointer at self->data[index]; - return NULL; // TODO + self->data->erase(self->data->begin() + index); + Py_INCREF(Py_None); + return Py_None; } static PyMethodDef PyUICollection_methods[] = {