From 9c2f0c0ac5a59f615e8f3c65e67dc4fa8db9a801 Mon Sep 17 00:00:00 2001
From: jcarpent <jcarpent@laas.fr>
Date: Sun, 24 Jul 2016 22:29:27 +0200
Subject: [PATCH] [C++] Move operator== to the JointModelBase class

---
 src/multibody/joint/joint-base.hpp            | 13 +++++++++++--
 src/multibody/joint/joint-dense.hpp           | 13 -------------
 src/multibody/joint/joint-free-flyer.hpp      | 12 ------------
 src/multibody/joint/joint-planar.hpp          | 12 ------------
 .../joint/joint-prismatic-unaligned.hpp       | 14 --------------
 src/multibody/joint/joint-prismatic.hpp       | 12 ------------
 .../joint/joint-revolute-unaligned.hpp        | 14 --------------
 .../joint/joint-revolute-unbounded.hpp        | 13 -------------
 src/multibody/joint/joint-revolute.hpp        | 13 -------------
 src/multibody/joint/joint-spherical-ZYX.hpp   | 13 -------------
 src/multibody/joint/joint-spherical.hpp       | 12 ------------
 src/multibody/joint/joint-translation.hpp     | 12 ------------
 src/multibody/joint/joint.hpp                 | 19 +++----------------
 13 files changed, 14 insertions(+), 158 deletions(-)

diff --git a/src/multibody/joint/joint-base.hpp b/src/multibody/joint/joint-base.hpp
index 203d7849d..ec9f3a3b5 100644
--- a/src/multibody/joint/joint-base.hpp
+++ b/src/multibody/joint/joint-base.hpp
@@ -386,7 +386,17 @@ namespace se3
     
     std::string shortname() const { return derived().shortname(); }
     static std::string classname() { return Derived::classname(); }
-
+    
+    template <class OtherDerived>
+    bool operator==(const JointModelBase<OtherDerived> & other) const { return derived().isEqual(other); }
+    
+    template <class OtherDerived>
+    bool isEqual(const JointModelBase<OtherDerived> &) const { return false; }
+    
+    bool isEqual(const JointModelBase<Derived> & other) const
+    {
+      return other.id() == id() && other.idx_q() == idx_q() && other.idx_v() == idx_v();
+    }
 
     /* Acces to dedicated segment in robot config space.  */
     // Const access
@@ -420,7 +430,6 @@ namespace se3
     typename SizeDepType<NV>::template SegmentReturn<D>::Type 
     jointVelocitySelector_impl( Eigen::MatrixBase<D>& a) const { return a.template segment<NV>(i_v); }
 
-
     template<typename D>
     typename SizeDepType<NV>::template ColsReturn<D>::ConstType 
     jointCols(const Eigen::MatrixBase<D>& A) const       { return derived().jointCols_impl(A); }
diff --git a/src/multibody/joint/joint-dense.hpp b/src/multibody/joint/joint-dense.hpp
index 58eeb95a0..324ef6251 100644
--- a/src/multibody/joint/joint-dense.hpp
+++ b/src/multibody/joint/joint-dense.hpp
@@ -241,19 +241,6 @@ namespace se3
     static std::string classname() { return std::string("JointModelDense"); }
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModelDense> & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
-
   }; // struct JointModelDense
 
   template<>
diff --git a/src/multibody/joint/joint-free-flyer.hpp b/src/multibody/joint/joint-free-flyer.hpp
index 5b4f02c2b..9edc40e1b 100644
--- a/src/multibody/joint/joint-free-flyer.hpp
+++ b/src/multibody/joint/joint-free-flyer.hpp
@@ -390,18 +390,6 @@ namespace se3
     static std::string classname() { return std::string("JointModelFreeFlyer"); }
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModelFreeFlyer> & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
   }; // struct JointModelFreeFlyer
 
 } // namespace se3
diff --git a/src/multibody/joint/joint-planar.hpp b/src/multibody/joint/joint-planar.hpp
index 2fdda2483..0f601fa30 100644
--- a/src/multibody/joint/joint-planar.hpp
+++ b/src/multibody/joint/joint-planar.hpp
@@ -443,18 +443,6 @@ namespace se3
     static std::string classname() { return std::string("JointModelPlanar");}
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModelPlanar> & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
   }; // struct JointModelPlanar
 
 } // namespace se3
diff --git a/src/multibody/joint/joint-prismatic-unaligned.hpp b/src/multibody/joint/joint-prismatic-unaligned.hpp
index d27975c4b..e5393a2a8 100644
--- a/src/multibody/joint/joint-prismatic-unaligned.hpp
+++ b/src/multibody/joint/joint-prismatic-unaligned.hpp
@@ -449,20 +449,6 @@ namespace se3
     static std::string classname() { return std::string("JointModelPrismaticUnaligned"); }
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator== (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator== (const JointModelBase<JointModelPrismaticUnaligned> & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
-    
-  public:
     Vector3 axis;
   }; // struct JointModelPrismaticUnaligned
 
diff --git a/src/multibody/joint/joint-prismatic.hpp b/src/multibody/joint/joint-prismatic.hpp
index c00b2d147..b278c1136 100644
--- a/src/multibody/joint/joint-prismatic.hpp
+++ b/src/multibody/joint/joint-prismatic.hpp
@@ -504,18 +504,6 @@ namespace se3
     static std::string classname();
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModelPrismatic> & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
   }; // struct JointModelPrismatic
 
   typedef JointPrismatic<0> JointPX;
diff --git a/src/multibody/joint/joint-revolute-unaligned.hpp b/src/multibody/joint/joint-revolute-unaligned.hpp
index de08f861b..690fb3bc5 100644
--- a/src/multibody/joint/joint-revolute-unaligned.hpp
+++ b/src/multibody/joint/joint-revolute-unaligned.hpp
@@ -453,20 +453,6 @@ namespace se3
     static std::string classname() { return std::string("JointModelRevoluteUnaligned"); }
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModelRevoluteUnaligned> & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
-    
-  public:
     Motion::Vector3 axis;
   }; // struct JointModelRevoluteUnaligned
 
diff --git a/src/multibody/joint/joint-revolute-unbounded.hpp b/src/multibody/joint/joint-revolute-unbounded.hpp
index 01f8992e2..4e06b542a 100644
--- a/src/multibody/joint/joint-revolute-unbounded.hpp
+++ b/src/multibody/joint/joint-revolute-unbounded.hpp
@@ -254,19 +254,6 @@ namespace se3
     static std::string classname();
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModelRevoluteUnbounded <axis> > & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
-
   }; // struct JointModelRevoluteUnbounded
 
   typedef JointRevoluteUnbounded<0> JointRUBX;
diff --git a/src/multibody/joint/joint-revolute.hpp b/src/multibody/joint/joint-revolute.hpp
index d85d2fb11..70877c02e 100644
--- a/src/multibody/joint/joint-revolute.hpp
+++ b/src/multibody/joint/joint-revolute.hpp
@@ -538,19 +538,6 @@ namespace se3
     static std::string classname();
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModelRevolute <axis> > & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
-
   }; // struct JointModelRevolute
 
   typedef JointRevolute<0> JointRX;
diff --git a/src/multibody/joint/joint-spherical-ZYX.hpp b/src/multibody/joint/joint-spherical-ZYX.hpp
index 22ba87fab..5c58d9b57 100644
--- a/src/multibody/joint/joint-spherical-ZYX.hpp
+++ b/src/multibody/joint/joint-spherical-ZYX.hpp
@@ -470,19 +470,6 @@ namespace se3
     static std::string classname() { return std::string("JointModelSphericalZYX"); }
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModelSphericalZYX> & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
-
   }; // struct JointModelSphericalZYX
 
 } // namespace se3
diff --git a/src/multibody/joint/joint-spherical.hpp b/src/multibody/joint/joint-spherical.hpp
index 6c30e0f4a..05b856370 100644
--- a/src/multibody/joint/joint-spherical.hpp
+++ b/src/multibody/joint/joint-spherical.hpp
@@ -415,18 +415,6 @@ namespace se3
     static std::string classname() { return std::string("JointModelSpherical"); }
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModelSpherical> & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
   }; // struct JointModelSpherical
 
 } // namespace se3
diff --git a/src/multibody/joint/joint-translation.hpp b/src/multibody/joint/joint-translation.hpp
index 182688ae3..c78e63b42 100644
--- a/src/multibody/joint/joint-translation.hpp
+++ b/src/multibody/joint/joint-translation.hpp
@@ -382,18 +382,6 @@ namespace se3
     static std::string classname() { return std::string("JointModelTranslation"); }
     std::string shortname() const { return classname(); }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModelTranslation> & jmodel) const
-    {
-      return jmodel.id() == id()
-              && jmodel.idx_q() == idx_q()
-              && jmodel.idx_v() == idx_v();
-    }
   }; // struct JointModelTranslation
   
 } // namespace se3
diff --git a/src/multibody/joint/joint.hpp b/src/multibody/joint/joint.hpp
index a2e6fb4d0..6017881eb 100644
--- a/src/multibody/joint/joint.hpp
+++ b/src/multibody/joint/joint.hpp
@@ -90,8 +90,9 @@ namespace se3
     typedef Joint JointDerived;
     SE3_JOINT_TYPEDEF;
     SE3_JOINT_USE_INDEXES;
-    using JointModelBase<JointModel>::id;
-    using JointModelBase<JointModel>::setIndexes;
+    using Base::id;
+    using Base::setIndexes;
+    using Base::operator==;
 
     JointModelVariant& toVariant() { return *static_cast<JointModelVariant*>(this); }
     const JointModelVariant& toVariant() const { return *static_cast<const JointModelVariant*>(this); }
@@ -159,20 +160,6 @@ namespace se3
     std::string shortname() const { return ::se3::shortname(*this); }
     static std::string classname() { return "JointModel"; }
 
-    template <class D>
-    bool operator == (const JointModelBase<D> &) const
-    {
-      return false;
-    }
-    
-    bool operator == (const JointModelBase<JointModel> & jmodel) const
-    {
-      return jmodel.id() == id()
-          && jmodel.idx_q() == idx_q()
-          && jmodel.idx_v() == idx_v();
-    }
-
-
     int     nq_impl() const { return ::se3::nq(*this); }
     int     nv_impl() const { return ::se3::nv(*this); }
 
-- 
GitLab