- tp_name: "location.Database",
- tp_basicsize: sizeof(DatabaseObject),
- tp_flags: Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
- tp_new: Database_new,
- tp_dealloc: (destructor)Database_dealloc,
- tp_init: (initproc)Database_init,
- tp_doc: "Database object",
- tp_methods: Database_methods,
- tp_getset: Database_getsetters,
- tp_repr: (reprfunc)Database_repr,
+ .tp_name = "location.Database",
+ .tp_basicsize = sizeof(DatabaseObject),
+ .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+ .tp_new = Database_new,
+ .tp_dealloc = (destructor)Database_dealloc,
+ .tp_init = (initproc)Database_init,
+ .tp_doc = "Database object",
+ .tp_methods = Database_methods,
+ .tp_getset = Database_getsetters,
+ .tp_repr = (reprfunc)Database_repr,
+};
+
+static PyObject* DatabaseEnumerator_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
+ DatabaseEnumeratorObject* self = (DatabaseEnumeratorObject*)type->tp_alloc(type, 0);
+
+ return (PyObject*)self;
+}
+
+static void DatabaseEnumerator_dealloc(DatabaseEnumeratorObject* self) {
+ loc_database_enumerator_unref(self->enumerator);
+
+ Py_TYPE(self)->tp_free((PyObject* )self);
+}
+
+static PyObject* DatabaseEnumerator_next(DatabaseEnumeratorObject* self) {
+ struct loc_as* as = loc_database_enumerator_next_as(self->enumerator);
+ if (as) {
+ PyObject* obj = new_as(&ASType, as);
+ loc_as_unref(as);
+
+ return obj;
+ }
+
+ // Nothing found, that means the end
+ PyErr_SetNone(PyExc_StopIteration);
+ return NULL;
+}
+
+PyTypeObject DatabaseEnumeratorType = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = "location.DatabaseEnumerator",
+ .tp_basicsize = sizeof(DatabaseEnumeratorObject),
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_alloc = PyType_GenericAlloc,
+ .tp_new = DatabaseEnumerator_new,
+ .tp_dealloc = (destructor)DatabaseEnumerator_dealloc,
+ .tp_iter = PyObject_SelfIter,
+ .tp_iternext = (iternextfunc)DatabaseEnumerator_next,