Skip to content
Snippets Groups Projects
Commit 9a3f57de authored by florent's avatar florent
Browse files

Bind method Entity::listEntities.

     * src/CMakeLists.txt,
     * src/dynamic-graph-py.cc,
     * src/factory-py.cc: new.
parent 5cb2284d
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ ADD_LIBRARY(${PYTHON_MODULE}
dynamic-graph-py.cc
signal-base-py.cc
entity-py.cc
factory-py.cc
)
# Remove prefix lib
......
......@@ -30,6 +30,9 @@ namespace dynamicgraph {
}
namespace factory {
PyObject* getEntityClassList(PyObject* self, PyObject* args);
}
PyObject* error;
static dynamicgraph::InterpreterHelper interpreter;
......@@ -114,6 +117,10 @@ static PyMethodDef dynamicGraphMethods[] = {
{"entity_display_signals", dynamicgraph::python::entity::displaySignals,
METH_VARARGS,
"Display the list of signals of an entity in standard output"},
{"factory_get_entity_class_list",
dynamicgraph::python::factory::getEntityClassList,
METH_VARARGS,
"return the list of entity classes"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
......
/*
* Copyright 2010 (C) CNRS
* Author: Florent Lamiraux
*/
#include <Python.h>
#include <iostream>
#include <dynamic-graph/factory.h>
using dynamicgraph::Entity;
using dynamicgraph::ExceptionAbstract;
namespace dynamicgraph {
namespace python {
extern PyObject* error;
namespace factory {
/**
\brief Get name of entity
*/
PyObject* getEntityClassList(PyObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
std::vector <std::string> classNames;
dynamicgraph::g_factory.listEntities(classNames);
unsigned int classNumber = classNames.size();
// Build a tuple object
PyObject* classTuple = PyTuple_New(classNumber);
for (unsigned int iEntity = 0; iEntity < classNames.size(); iEntity++) {
PyObject* className = Py_BuildValue("s", classNames[iEntity].c_str());
PyTuple_SetItem(classTuple, iEntity, className);
}
return Py_BuildValue("O", classTuple);
}
} // namespace factory
} // namespace python
} // namespace dynamicgraph
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