pinocchio  3.2.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
constraint-data-generic.hpp
1 //
2 // Copyright (c) 2023 INRIA
3 //
4 
5 #ifndef __pinocchio_algorithm_constraint_data_generic_hpp__
6 #define __pinocchio_algorithm_constraint_data_generic_hpp__
7 
8 #include "pinocchio/algorithm/constraints/fwd.hpp"
9 #include "pinocchio/algorithm/constraints/constraint-model-base.hpp"
10 #include "pinocchio/algorithm/constraints/constraint-data-base.hpp"
11 #include "pinocchio/algorithm/constraints/visitors/constraint-model-visitor.hpp"
12 
13 namespace pinocchio
14 {
15 
16  template<
17  typename _Scalar,
18  int _Options,
19  template<typename S, int O>
20  class ConstraintCollectionTpl>
21  struct traits<ConstraintDataTpl<_Scalar, _Options, ConstraintCollectionTpl>>
22  {
23  typedef _Scalar Scalar;
24  enum
25  {
26  Options = _Options
27  };
29  };
30 
31  template<
32  typename _Scalar,
33  int _Options,
34  template<typename S, int O>
37  : ConstraintDataBase<ConstraintDataTpl<_Scalar, _Options, ConstraintCollectionTpl>>
38  , ConstraintCollectionTpl<_Scalar, _Options>::ConstraintDataVariant
39  {
41  typedef _Scalar Scalar;
42  enum
43  {
44  Options = _Options
45  };
46 
48  typedef typename ConstraintCollection::ConstraintDataVariant ConstraintDataVariant;
49  typedef typename ConstraintCollection::ConstraintModelVariant ConstraintModelVariant;
50 
52  : ConstraintDataVariant()
53  {
54  }
55 
56  ConstraintDataTpl(const ConstraintDataVariant & cdata_variant)
57  : ConstraintDataVariant(cdata_variant)
58  {
59  }
60 
61  template<typename ContraintDataDerived>
63  : ConstraintDataVariant((ConstraintDataVariant)cdata.derived())
64  {
65  BOOST_MPL_ASSERT(
66  (boost::mpl::contains<typename ConstraintDataVariant::types, ContraintDataDerived>));
67  }
68 
69  ConstraintDataVariant & toVariant()
70  {
71  return static_cast<ConstraintDataVariant &>(*this);
72  }
73 
74  const ConstraintDataVariant & toVariant() const
75  {
76  return static_cast<const ConstraintDataVariant &>(*this);
77  }
78 
79  template<typename ConstraintDataDerived>
80  bool isEqual(const ConstraintDataBase<ConstraintDataDerived> & other) const
81  {
82  return ::pinocchio::isEqual(*this, other.derived());
83  }
84 
85  bool isEqual(const ConstraintDataTpl & other) const
86  {
87  return /*Base::isEqual(other) &&*/ toVariant() == other.toVariant();
88  }
89 
90  bool operator==(const ConstraintDataTpl & other) const
91  {
92  return isEqual(other);
93  }
94 
95  bool operator!=(const ConstraintDataTpl & other) const
96  {
97  return !(*this == other);
98  }
99  };
100 
101  template<
102  typename ConstraintDataDerived,
103  typename Scalar,
104  int Options,
105  template<typename S, int O>
107  bool operator==(
110  {
111  return data2 == data1.derived();
112  }
113 
114 } // namespace pinocchio
115 
116 #endif // ifndef __pinocchio_algorithm_constraint_data_generic_hpp__
Main pinocchio namespace.
Definition: treeview.dox:11
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:72