From 0f6d88d345d8a5d93f8cd64043f8a128dda7f2a2 Mon Sep 17 00:00:00 2001
From: Justin Carpentier <justin.carpentier@inria.fr>
Date: Wed, 29 Jan 2020 16:11:06 +0100
Subject: [PATCH] utils: add name methods for Scalar types

---
 CMakeLists.txt                        |  5 +++
 include/eigenpy/utils/scalar-name.hpp | 44 +++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 include/eigenpy/utils/scalar-name.hpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 265c78e..55e5098 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -71,6 +71,10 @@ SEARCH_FOR_BOOST()
 # ----------------------------------------------------
 # --- INCLUDE ----------------------------------------
 # ----------------------------------------------------
+SET(${PROJECT_NAME}_UTILS_HEADERS
+  include/eigenpy/utils/scalar-name.hpp
+  )
+
 SET(${PROJECT_NAME}_SOLVERS_HEADERS
   include/eigenpy/solvers/solvers.hpp
   include/eigenpy/solvers/preconditioners.hpp
@@ -83,6 +87,7 @@ SET(${PROJECT_NAME}_SOLVERS_HEADERS
   )
 
 SET(${PROJECT_NAME}_HEADERS
+  ${${PROJECT_NAME}_UTILS_HEADERS}
   ${${PROJECT_NAME}_SOLVERS_HEADERS}
   include/eigenpy/computation-info.hpp
   include/eigenpy/eigenpy.hpp
diff --git a/include/eigenpy/utils/scalar-name.hpp b/include/eigenpy/utils/scalar-name.hpp
new file mode 100644
index 0000000..2d3a949
--- /dev/null
+++ b/include/eigenpy/utils/scalar-name.hpp
@@ -0,0 +1,44 @@
+/*
+* Copyright 2020 INRIA
+*/
+
+#ifndef __eigenpy_utils_scalar_name_hpp__
+#define __eigenpy_utils_scalar_name_hpp__
+
+#include <string>
+#include <complex>
+
+namespace eigenpy
+{
+  template<typename Scalar>
+  struct scalar_name
+  {
+    static std::string shortname();
+  };
+
+  template<>
+  struct scalar_name<float>
+  {
+    static std::string shortname() { return "f"; };
+  };
+
+  template<>
+  struct scalar_name<double>
+  {
+    static std::string shortname() { return "d"; };
+  };
+
+  template<>
+  struct scalar_name<long double>
+  {
+    static std::string shortname() { return "ld"; };
+  };
+
+  template<typename Scalar>
+  struct scalar_name< std::complex<Scalar> >
+  {
+    static std::string shortname() { return "c" + scalar_name<Scalar>(); };
+  };
+}
+
+#endif // ifndef __eigenpy_utils_scalar_name_hpp__
-- 
GitLab