Skip to content
Snippets Groups Projects
Commit 25d016aa authored by Nicolas Mansard's avatar Nicolas Mansard Committed by Nicolas Mansard
Browse files

Added the display method, py-bound in __str__.

parent 482a81c4
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,7 @@ namespace dynamicgraph { ...@@ -38,6 +38,7 @@ namespace dynamicgraph {
} }
namespace entity { namespace entity {
extern PyObject* create(PyObject* self, PyObject* args); extern PyObject* create(PyObject* self, PyObject* args);
extern PyObject* display(PyObject* self, PyObject* args);
extern PyObject* getName(PyObject* self, PyObject* args); extern PyObject* getName(PyObject* self, PyObject* args);
extern PyObject* getSignal(PyObject* self, PyObject* args); extern PyObject* getSignal(PyObject* self, PyObject* args);
extern PyObject* listSignals(PyObject* self, PyObject* args); extern PyObject* listSignals(PyObject* self, PyObject* args);
...@@ -161,6 +162,8 @@ static PyMethodDef dynamicGraphMethods[] = { ...@@ -161,6 +162,8 @@ static PyMethodDef dynamicGraphMethods[] = {
// Entity // Entity
{"create_entity", dynamicgraph::python::entity::create, METH_VARARGS, {"create_entity", dynamicgraph::python::entity::create, METH_VARARGS,
"create an Entity C++ object"}, "create an Entity C++ object"},
{"display_entity", dynamicgraph::python::entity::display, METH_VARARGS,
"print an Entity C++ object"},
{"entity_get_name", dynamicgraph::python::entity::getName, METH_VARARGS, {"entity_get_name", dynamicgraph::python::entity::getName, METH_VARARGS,
"get the name of an Entity"}, "get the name of an Entity"},
{"entity_get_signal", dynamicgraph::python::entity::getSignal, METH_VARARGS, {"entity_get_signal", dynamicgraph::python::entity::getSignal, METH_VARARGS,
......
...@@ -72,6 +72,9 @@ class Entity (object) : ...@@ -72,6 +72,9 @@ class Entity (object) :
def name(self) : def name(self) :
return wrap.entity_get_name(self.obj) return wrap.entity_get_name(self.obj)
def __str__(self) :
return wrap.display_entity(self.obj)
def signal (self, name) : def signal (self, name) :
""" """
Get a signal of the entity from signal name Get a signal of the entity from signal name
......
...@@ -505,6 +505,27 @@ namespace dynamicgraph { ...@@ -505,6 +505,27 @@ namespace dynamicgraph {
std::string docstring = command->getDocstring(); std::string docstring = command->getDocstring();
return Py_BuildValue("s", docstring.c_str()); return Py_BuildValue("s", docstring.c_str());
} }
PyObject* display(PyObject* /*self*/, PyObject* args)
{
/* Retrieve the entity instance. */
PyObject* object = NULL;
if (!PyArg_ParseTuple(args, "O", &object)
|| (!PyCObject_Check(object)) )
{
PyErr_SetString(error, "first argument is not an object");
return NULL;
}
void* pointer = PyCObject_AsVoidPtr(object);
Entity* entity = (Entity*)pointer;
/* Run the display function. */
std::ostringstream oss;
entity->display(oss);
/* Return the resulting string. */
return Py_BuildValue("s", oss.str().c_str());
}
} }
} }
} }
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