Skip to content
Snippets Groups Projects
Commit ed39db7c authored by Olivier Stasse's avatar Olivier Stasse
Browse files

Implements correctly the list of entities inside the pool.

parent e2fc6170
No related branches found
No related tags found
No related merge requests found
Pipeline #7535 failed
......@@ -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 */
};
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment