From 4faf7044842eb93a86fb168ce3da6e7051a2fc59 Mon Sep 17 00:00:00 2001
From: Florent Lamiraux <florent@florent-laptop.(none)>
Date: Wed, 19 Jan 2011 12:05:45 +0100
Subject: [PATCH] Add a method getName in python class SignalBase

    * src/dynamic-graph-py.cc,
    * src/dynamic_graph/signal_base.py,
    * src/signal-base-py.cc.
---
 src/dynamic-graph-py.cc          |  3 +++
 src/dynamic_graph/signal_base.py |  6 ++++++
 src/signal-base-py.cc            | 27 +++++++++++++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/src/dynamic-graph-py.cc b/src/dynamic-graph-py.cc
index 3887420..e524b28 100644
--- a/src/dynamic-graph-py.cc
+++ b/src/dynamic-graph-py.cc
@@ -19,6 +19,7 @@ namespace dynamicgraph {
     namespace signalBase {
       extern PyObject* create(PyObject* self, PyObject* args);
       extern PyObject* getTime(PyObject* self, PyObject* args);
+      extern PyObject* getName(PyObject* self, PyObject* args);
       extern PyObject* getValue(PyObject* self, PyObject* args);
       extern PyObject* setValue(PyObject* self, PyObject* args);
       extern PyObject* recompute(PyObject* self, PyObject* args);
@@ -133,6 +134,8 @@ static PyMethodDef dynamicGraphMethods[] = {
    "create a SignalBase C++ object"},
   {"signal_base_get_time", dynamicgraph::python::signalBase::getTime,
    METH_VARARGS, "Get time of  a SignalBase"},
+  {"signal_base_get_name", dynamicgraph::python::signalBase::getName,
+   METH_VARARGS, "Get the name of a signal"},
   {"signal_base_get_value", dynamicgraph::python::signalBase::getValue,
    METH_VARARGS, "Read the value of a signal"},
   {"signal_base_set_value", dynamicgraph::python::signalBase::setValue,
diff --git a/src/dynamic_graph/signal_base.py b/src/dynamic_graph/signal_base.py
index bbd6969..142c287 100644
--- a/src/dynamic_graph/signal_base.py
+++ b/src/dynamic_graph/signal_base.py
@@ -200,6 +200,12 @@ class SignalBase (object) :
         string = objectToString(val)
         return wrap.signal_base_set_value(self.obj, string)
 
+    def getName(self):
+        """
+        Get name of signal
+        """
+        return wrap.signal_base_get_name(self.obj)
+
     def recompute(self, time):
         """
         Force signal to recompute the value at given time.
diff --git a/src/signal-base-py.cc b/src/signal-base-py.cc
index 0381a91..133c5cd 100644
--- a/src/signal-base-py.cc
+++ b/src/signal-base-py.cc
@@ -91,6 +91,33 @@ namespace dynamicgraph {
 	return Py_BuildValue("s", valueString.c_str());
       }
 
+      PyObject* getName(PyObject* self, PyObject* args)
+      {
+	void* pointer = NULL;
+	PyObject* object = NULL;
+	if (!PyArg_ParseTuple(args,"O", &object))
+	  return NULL;
+	if (!PyCObject_Check(object))
+	  return NULL;
+
+	pointer = PyCObject_AsVoidPtr(object);
+	SignalBase<int>* signal = (SignalBase<int>*)pointer;
+
+	std::string name;
+	try {
+	  name = signal->getName();
+	} catch (const dynamicgraph::ExceptionAbstract& exc) {
+	  PyErr_SetString(error, exc.getStringMessage().c_str());
+	  return NULL;
+	} catch (const std::exception& exc) {
+	  PyErr_SetString(error, exc.what());
+	} catch (...) {
+	  PyErr_SetString(error, "Unknown exception");
+	  return NULL;
+	}
+	return Py_BuildValue("s", name.c_str());
+      }
+
       PyObject* setValue(PyObject* self, PyObject* args)
       {
 	void * pointer = NULL;
-- 
GitLab