From 516eb71215aab3372ef8444c7abbf47c579acdef Mon Sep 17 00:00:00 2001
From: Florent Lamiraux <florent@laas.fr>
Date: Fri, 16 Mar 2012 17:22:28 +0100
Subject: [PATCH] Document entity class types with the output of C++
 getDocString method.

---
 src/dynamic-graph-py.cc     |  5 +++++
 src/dynamic_graph/entity.py |  1 +
 src/entity-py.cc            | 26 ++++++++++++++++++++++++++
 3 files changed, 32 insertions(+)

diff --git a/src/dynamic-graph-py.cc b/src/dynamic-graph-py.cc
index b69b26e..86485c7 100644
--- a/src/dynamic-graph-py.cc
+++ b/src/dynamic-graph-py.cc
@@ -50,6 +50,7 @@ namespace dynamicgraph {
       extern PyObject* executeCommand(PyObject* self, PyObject* args);
       extern PyObject* listCommands(PyObject* self, PyObject* args);
       extern PyObject* getCommandDocstring(PyObject* self, PyObject* args);
+      extern PyObject* getDocString(PyObject* self, PyObject* args);
     }
 
     namespace factory {
@@ -186,6 +187,10 @@ static PyMethodDef dynamicGraphMethods[] = {
    dynamicgraph::python::entity::getCommandDocstring,
    METH_VARARGS,
    "get the docstring of an entity command"},
+  {"entity_get_docstring",
+   dynamicgraph::python::entity::getDocString,
+   METH_VARARGS,
+   "get the doc string of an entity type"},
   {"factory_get_entity_class_list",
    dynamicgraph::python::factory::getEntityClassList,
    METH_VARARGS,
diff --git a/src/dynamic_graph/entity.py b/src/dynamic_graph/entity.py
index 648e963..3699349 100644
--- a/src/dynamic_graph/entity.py
+++ b/src/dynamic_graph/entity.py
@@ -85,6 +85,7 @@ class Entity (object) :
         Entity.__init__(self, self.className, name)
         if not self.__class__.commandCreated:
             self.boundClassCommands()
+            self.__class__.__doc__ = wrap.entity_get_docstring (self.obj)
             self.__class__.commandCreated = True
 
     @property
diff --git a/src/entity-py.cc b/src/entity-py.cc
index 558458b..d114e30 100644
--- a/src/entity-py.cc
+++ b/src/entity-py.cc
@@ -305,6 +305,32 @@ namespace dynamicgraph {
 	return Py_BuildValue("s", docstring.c_str());
       }
 
+      PyObject* getDocString(PyObject* /*self*/, PyObject* args)
+      {
+	PyObject* object = NULL;
+	if (!PyArg_ParseTuple(args, "O", &object)) {
+	  return NULL;
+	}
+
+	// Retrieve the entity instance
+	if (!PyCObject_Check(object)) {
+	  PyErr_SetString(dgpyError, "first argument is not an object");
+	  return NULL;
+	}
+	void* pointer = PyCObject_AsVoidPtr(object);
+	Entity* entity = (Entity*)pointer;
+	try {
+	  return Py_BuildValue ("s", entity->getDocString ().c_str ());
+	} catch (const std::exception& exc) {
+	    PyErr_SetString(dgpyError, exc.what ()) ;
+	    return NULL;
+	} catch (...) {
+	  PyErr_SetString(dgpyError, "Unknown exception");
+	  return NULL;
+	}
+	return NULL;
+      }
+
       PyObject* display(PyObject* /*self*/, PyObject* args)
       {
 	/* Retrieve the entity instance. */
-- 
GitLab