pinocchio  3.3.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> class ConstraintCollectionTpl>
20  struct traits<ConstraintDataTpl<_Scalar, _Options, ConstraintCollectionTpl>>
21  {
22  typedef _Scalar Scalar;
23  enum
24  {
25  Options = _Options
26  };
28  };
29 
30  template<
31  typename _Scalar,
32  int _Options,
33  template<typename S, int O> class ConstraintCollectionTpl>
35  : ConstraintDataBase<ConstraintDataTpl<_Scalar, _Options, ConstraintCollectionTpl>>
36  , ConstraintCollectionTpl<_Scalar, _Options>::ConstraintDataVariant
37  {
39  typedef _Scalar Scalar;
40  enum
41  {
42  Options = _Options
43  };
44 
46  typedef typename ConstraintCollection::ConstraintDataVariant ConstraintDataVariant;
47  typedef typename ConstraintCollection::ConstraintModelVariant ConstraintModelVariant;
48 
50  : ConstraintDataVariant()
51  {
52  }
53 
54  ConstraintDataTpl(const ConstraintDataVariant & cdata_variant)
55  : ConstraintDataVariant(cdata_variant)
56  {
57  }
58 
59  template<typename ContraintDataDerived>
61  : ConstraintDataVariant((ConstraintDataVariant)cdata.derived())
62  {
63  BOOST_MPL_ASSERT(
64  (boost::mpl::contains<typename ConstraintDataVariant::types, ContraintDataDerived>));
65  }
66 
67  ConstraintDataVariant & toVariant()
68  {
69  return static_cast<ConstraintDataVariant &>(*this);
70  }
71 
72  const ConstraintDataVariant & toVariant() const
73  {
74  return static_cast<const ConstraintDataVariant &>(*this);
75  }
76 
77  template<typename ConstraintDataDerived>
78  bool isEqual(const ConstraintDataBase<ConstraintDataDerived> & other) const
79  {
80  return ::pinocchio::isEqual(*this, other.derived());
81  }
82 
83  bool isEqual(const ConstraintDataTpl & other) const
84  {
85  return /*Base::isEqual(other) &&*/ toVariant() == other.toVariant();
86  }
87 
88  bool operator==(const ConstraintDataTpl & other) const
89  {
90  return isEqual(other);
91  }
92 
93  bool operator!=(const ConstraintDataTpl & other) const
94  {
95  return !(*this == other);
96  }
97  };
98 
99  template<
100  typename ConstraintDataDerived,
101  typename Scalar,
102  int Options,
103  template<typename S, int O> class ConstraintCollectionTpl>
104  bool operator==(
107  {
108  return data2 == data1.derived();
109  }
110 
111 } // namespace pinocchio
112 
113 #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