From 7faed535513d98a671bf807ecb63e2c27003212e Mon Sep 17 00:00:00 2001
From: Damien Petit <damien.gerard.petit@gmail.com>
Date: Thu, 12 Sep 2013 02:38:41 +0900
Subject: [PATCH] add support for unsigned int values import/export (close #2)

---
 src/converter.hh   | 12 ++++++++++++
 src/ros_export.cpp |  3 +++
 src/ros_import.cpp |  3 +++
 src/sot_to_ros.cpp |  1 +
 src/sot_to_ros.hh  | 20 ++++++++++++++++++++
 5 files changed, 39 insertions(+)

diff --git a/src/converter.hh b/src/converter.hh
index 4cc8e56..e53cbf5 100644
--- a/src/converter.hh
+++ b/src/converter.hh
@@ -55,6 +55,17 @@ namespace dynamicgraph
     dst = src.data;
   }
 
+  // Unsigned
+  SOT_TO_ROS_IMPL(unsigned int)
+  {
+    dst.data = src;
+  }
+
+  ROS_TO_SOT_IMPL(unsigned int)
+  {
+    dst = src.data;
+  }
+
   // Vector
   SOT_TO_ROS_IMPL(ml::Vector)
   {
@@ -210,6 +221,7 @@ namespace dynamicgraph
   struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
 
   DG_BRIDGE_MAKE_SHPTR_IMPL(double);
+  DG_BRIDGE_MAKE_SHPTR_IMPL(unsigned int);
   DG_BRIDGE_MAKE_SHPTR_IMPL(ml::Vector);
   DG_BRIDGE_MAKE_SHPTR_IMPL(specific::Vector3);
   DG_BRIDGE_MAKE_SHPTR_IMPL(ml::Matrix);
diff --git a/src/ros_export.cpp b/src/ros_export.cpp
index 70a5f6e..aafa3e1 100644
--- a/src/ros_export.cpp
+++ b/src/ros_export.cpp
@@ -6,6 +6,7 @@
 
 #include <ros/ros.h>
 #include <std_msgs/Float64.h>
+#include <std_msgs/UInt32.h>
 
 #include <dynamic-graph/factory.h>
 
@@ -73,6 +74,8 @@ namespace dynamicgraph
 
 	if (type == "double")
 	  entity.add<double> (signal, topic);
+	else if (type == "unsigned")
+	  entity.add<unsigned int> (signal, topic);
 	else if (type == "matrix")
 	  entity.add<ml::Matrix> (signal, topic);
 	else if (type == "vector")
diff --git a/src/ros_import.cpp b/src/ros_import.cpp
index 4497b6e..88279b0 100644
--- a/src/ros_import.cpp
+++ b/src/ros_import.cpp
@@ -9,6 +9,7 @@
 
 #include <ros/ros.h>
 #include <std_msgs/Float64.h>
+#include <std_msgs/UInt32.h>
 
 #include <dynamic-graph/factory.h>
 #include <dynamic-graph/command.h>
@@ -77,6 +78,8 @@ namespace dynamicgraph
 
 	if (type == "double")
 	  entity.add<double> (signal, topic);
+	else if (type == "unsigned")
+	  entity.add<unsigned int> (signal, topic);
 	else if (type == "matrix")
 	  entity.add<ml::Matrix> (signal, topic);
 	else if (type == "vector")
diff --git a/src/sot_to_ros.cpp b/src/sot_to_ros.cpp
index 1b52ae9..701087c 100644
--- a/src/sot_to_ros.cpp
+++ b/src/sot_to_ros.cpp
@@ -4,6 +4,7 @@ namespace dynamicgraph
 {
 
   const char* SotToRos<double>::signalTypeName = "Double";
+  const char* SotToRos<unsigned int>::signalTypeName = "Unsigned";
   const char* SotToRos<ml::Matrix>::signalTypeName = "Matrix";
   const char* SotToRos<ml::Vector>::signalTypeName = "Vector";
   const char* SotToRos<specific::Vector3>::signalTypeName = "Vector3";
diff --git a/src/sot_to_ros.hh b/src/sot_to_ros.hh
index 2088175..8878789 100644
--- a/src/sot_to_ros.hh
+++ b/src/sot_to_ros.hh
@@ -7,6 +7,7 @@
 
 # include <jrl/mal/boost.hh>
 # include <std_msgs/Float64.h>
+# include <std_msgs/UInt32.h>
 # include "dynamic_graph_bridge/Matrix.h"
 # include "dynamic_graph_bridge/Vector.h"
 
@@ -67,6 +68,25 @@ namespace dynamicgraph
     }
   };
 
+  template <>
+  struct SotToRos<unsigned int>
+  {
+    typedef unsigned int sot_t;
+    typedef std_msgs::UInt32 ros_t;
+    typedef std_msgs::UInt32ConstPtr ros_const_ptr_t;
+    typedef dynamicgraph::Signal<sot_t, int> signal_t;
+    typedef dynamicgraph::SignalPtr<sot_t, int> signalIn_t;
+    typedef boost::function<sot_t& (sot_t&, int)> callback_t;
+
+    static const char* signalTypeName;
+
+    template <typename S>
+    static void setDefault(S& s)
+    {
+      s.setConstant (0);
+    }
+  };
+
   template <>
   struct SotToRos<ml::Matrix>
   {
-- 
GitLab