From 67cbba713a1c5816a1019805c249a86999d71c74 Mon Sep 17 00:00:00 2001 From: Olivier Stasse <ostasse@laas.fr> Date: Fri, 5 May 2017 10:39:57 +0200 Subject: [PATCH] Implements correctly the list of entities inside the pool. --- src/dynamic-graph-py.cc | 6 +++++- src/pool-py.cc | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/dynamic-graph-py.cc b/src/dynamic-graph-py.cc index 0af45dc..ff987bf 100644 --- a/src/dynamic-graph-py.cc +++ b/src/dynamic-graph-py.cc @@ -59,13 +59,13 @@ namespace dynamicgraph { namespace factory { extern PyObject* getEntityClassList(PyObject* self, PyObject* args); - extern PyObject* getEntityMap(PyObject* self, PyObject* args); } namespace signalCaster { extern PyObject* getSignalTypeList(PyObject* self, PyObject* args); } namespace pool { extern PyObject* writeGraph (PyObject* self, PyObject* args); + extern PyObject* getEntityList(PyObject* self, PyObject* args); } PyObject* dgpyError; @@ -216,6 +216,10 @@ static PyMethodDef dynamicGraphMethods[] = { dynamicgraph::python::pool::writeGraph, METH_VARARGS, "Write the graph of entities in a filename."}, + {"get_entity_list", + dynamicgraph::python::pool::getEntityList, + METH_VARARGS, + "return the list of instanciated entities"}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/src/pool-py.cc b/src/pool-py.cc index 1858c96..c9085c2 100644 --- a/src/pool-py.cc +++ b/src/pool-py.cc @@ -15,7 +15,8 @@ #include <Python.h> #include <dynamic-graph/pool.h> - +#include <dynamic-graph/entity.h> +#include <vector> #include "exception.hh" namespace dynamicgraph { @@ -33,6 +34,43 @@ namespace dynamicgraph { } CATCH_ALL_EXCEPTIONS(); return Py_BuildValue (""); } + + /** + \brief Get list of entities + */ + PyObject* getEntityList(PyObject* /*self*/, PyObject* args) + { + if (!PyArg_ParseTuple(args, "")) + return NULL; + + std::vector <std::string> entityNames; + try { + const PoolStorage::Entities & listOfEntities= + dynamicgraph::PoolStorage::getInstance() + ->getEntityMap(); + + Py_ssize_t classNumber = listOfEntities.size(); + // Build a tuple object + PyObject* classTuple = PyTuple_New(classNumber); + + Py_ssize_t iEntity = 0; + for (PoolStorage::Entities::const_iterator entity_it = + listOfEntities.begin(); + entity_it != listOfEntities.end(); + ++entity_it) + { + const std::string & aname = entity_it->second->getName(); + + PyObject* className = + Py_BuildValue("s", aname.c_str()); + PyTuple_SetItem(classTuple, iEntity, className); + iEntity++; + } + return Py_BuildValue("O", classTuple); + } CATCH_ALL_EXCEPTIONS(); + return NULL; + } + } // python } // dynamicgraph } // namespace pool -- GitLab