From 07a1213ad84c47482502b6ae3ec5ba6f5696a14a Mon Sep 17 00:00:00 2001 From: The Coriolis Project Date: Fri, 17 Oct 2008 17:51:31 +0000 Subject: [PATCH] collections still in progress --- hurricane/src/isobar/PyNetCollection.cpp | 29 ++--------------- .../src/isobar/hurricane/isobar/PyHurricane.h | 32 ++++++++++++++++++- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/hurricane/src/isobar/PyNetCollection.cpp b/hurricane/src/isobar/PyNetCollection.cpp index 2fed22bd..5e273904 100644 --- a/hurricane/src/isobar/PyNetCollection.cpp +++ b/hurricane/src/isobar/PyNetCollection.cpp @@ -23,36 +23,11 @@ extern "C" { DirectDeleteMethod(PyNetCollection_DeAlloc, PyNetCollection) - static void PyNetCollectionLocator_DeAlloc(PyNetCollectionLocator* pyLocator) { - Py_XDECREF(pyLocator->_collection); - if (pyLocator->_object) { - delete pyLocator->_object; - } - PyObject_Del(pyLocator); - } - GetLocatorMethod(Net) + LocatorNextMethod(Net) + CollectionMethods(Net) - static PyObject* NetLocatorNext(PyNetCollectionLocator* pyLocator) { - Locator* locator = pyLocator->_object; - if (locator->isValid()) { - Net* net = locator->getElement(); - locator->progress(); - return PyNet_Link(net); - } - return NULL; - } - - extern void PyNetCollection_LinkPyType () { - trace << "PyNetCollection_LinkType()" << endl; - PyTypeNetCollection.tp_iter = (getiterfunc)GetLocator; /* tp_iter */ - PyTypeNetCollection.tp_dealloc = (destructor)PyNetCollection_DeAlloc; - PyTypeNetCollectionLocator.tp_dealloc = (destructor)PyNetCollectionLocator_DeAlloc; - PyTypeNetCollectionLocator.tp_iter = PyObject_SelfIter; - PyTypeNetCollectionLocator.tp_iternext = (iternextfunc)NetLocatorNext; - PyTypeNetCollection.tp_dealloc = (destructor)PyNetCollection_DeAlloc; - } #else // End of Python Module Code Part. diff --git a/hurricane/src/isobar/hurricane/isobar/PyHurricane.h b/hurricane/src/isobar/hurricane/isobar/PyHurricane.h index 8b5c7bbe..f168b95f 100644 --- a/hurricane/src/isobar/hurricane/isobar/PyHurricane.h +++ b/hurricane/src/isobar/hurricane/isobar/PyHurricane.h @@ -382,7 +382,7 @@ extern "C" { // Collection and Locator macros -#define GetLocatorMethod(TYPE) \ +#define CollectionMethods(TYPE) \ static PyObject* GetLocator(Py##TYPE##Collection* collection) { \ Py##TYPE##CollectionLocator* cl = \ PyObject_New(Py##TYPE##CollectionLocator, &PyType##TYPE##CollectionLocator); \ @@ -393,8 +393,38 @@ extern "C" { cl->_object = collection->_object->getLocator(); \ Py_INCREF(collection); \ return (PyObject *)cl; \ + } \ + \ + static void Py##TYPE##CollectionLocatorDeAlloc(Py##TYPE##CollectionLocator* locator) { \ + Py_XDECREF(locator->_collection); \ + if (locator->_object) { \ + delete locator->_object; \ + } \ + PyObject_Del(locator); \ + } \ + \ + extern void Py##TYPE##Collection_LinkPyType () { \ + trace << "Py"#TYPE"Collection_LinkType()" << endl; \ + PyType##TYPE##Collection.tp_iter = (getiterfunc)GetLocator; /* tp_iter */ \ + PyType##TYPE##Collection.tp_dealloc = (destructor)Py##TYPE##Collection_DeAlloc; \ + PyType##TYPE##CollectionLocator.tp_dealloc = (destructor)Py##TYPE##CollectionLocatorDeAlloc; \ + PyType##TYPE##CollectionLocator.tp_iter = PyObject_SelfIter; \ + PyType##TYPE##CollectionLocator.tp_iternext = (iternextfunc)Py##TYPE##LocatorNext; \ } +#define LocatorNextMethod(TYPE) \ + static PyObject* Py##TYPE##LocatorNext(Py##TYPE##CollectionLocator* pyLocator) { \ + Locator* locator = pyLocator->_object; \ + \ + if (locator->isValid()) { \ + TYPE* object = locator->getElement(); \ + locator->progress(); \ + return Py##TYPE##_Link(object); \ + } \ + return NULL; \ + } + + // ------------------------------------------------------------------- // Attribute Method For Repr.