pinocchio  3.3.1
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
check.hpp
1 //
2 // Copyright (c) 2016-2018 CNRS
3 //
4 
5 #ifndef __pinocchio_check_hpp__
6 #define __pinocchio_check_hpp__
7 
8 #include "pinocchio/multibody/model.hpp"
9 #include "pinocchio/multibody/data.hpp"
10 #include <boost/fusion/container/list.hpp>
11 #include <boost/fusion/container/generation/make_list.hpp>
12 
13 #ifndef PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE
14  #define PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE 5
15 #endif
16 
17 namespace pinocchio
18 {
19 
21  template<typename AlgorithmCheckerDerived>
23  {
24  inline AlgorithmCheckerDerived & derived()
25  {
26  return *static_cast<AlgorithmCheckerDerived *>(this);
27  }
28 
29  inline const AlgorithmCheckerDerived & derived() const
30  {
31  return *static_cast<const AlgorithmCheckerDerived *>(this);
32  }
33 
34  template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl>
35  inline bool checkModel(const ModelTpl<Scalar, Options, JointCollectionTpl> & model) const
36  {
37  return derived().checkModel_impl(model);
38  }
39  };
40 
41 #define PINOCCHIO_DEFINE_ALGO_CHECKER(NAME) \
42  struct NAME##Checker : public AlgorithmCheckerBase<NAME##Checker> \
43  { \
44  template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl> \
45  inline bool checkModel_impl(const ModelTpl<Scalar, Options, JointCollectionTpl> &) const; \
46  }
47 
49  PINOCCHIO_DEFINE_ALGO_CHECKER(Parent);
50 
51 #if !defined(BOOST_FUSION_HAS_VARIADIC_LIST)
53  template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
54  PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE, class D, boost::fusion::void_)>
57  AlgorithmCheckerList<BOOST_PP_ENUM_PARAMS(PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE, D)>>
58  {
59  typedef typename boost::fusion::list<BOOST_PP_ENUM_PARAMS(
60  PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE, D)>
61  ArgType;
62 
63  AlgorithmCheckerList(const ArgType & checkerList)
64  : checkerList(checkerList)
65  {
66  }
67 
68  // Calls model.check for each checker in the fusion::list.
69  // Each list element is supposed to implement the AlgorithmCheckerBase API.
70  template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl>
71  bool checkModel_impl(const ModelTpl<Scalar, Options, JointCollectionTpl> & model) const;
72 
73  const ArgType & checkerList;
74  };
75 
76  #define MAKE_ALGO_CHECKER_LIST(z, n, _) \
77  \
78  template<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), class D)> \
79  AlgorithmCheckerList<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), D)> makeAlgoCheckerList( \
80  BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n), D, const & arg)) \
81  { \
82  return AlgorithmCheckerList<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), D)>( \
83  boost::fusion::make_list(BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), arg))); \
84  }
85 
86  BOOST_PP_REPEAT(PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE, MAKE_ALGO_CHECKER_LIST, BOOST_PP_EMPTY)
87 #else
88  template<class... D>
89  struct AlgorithmCheckerList : AlgorithmCheckerBase<AlgorithmCheckerList<D...>>
90  {
91  typedef typename boost::fusion::list<D...> ArgType;
92 
93  AlgorithmCheckerList(const ArgType & checkerList)
94  : checkerList(checkerList)
95  {
96  }
97 
98  // Calls model.check for each checker in the fusion::list.
99  // Each list element is supposed to implement the AlgorithmCheckerBase API.
100  template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl>
101  bool checkModel_impl(const ModelTpl<Scalar, Options, JointCollectionTpl> & model) const;
102 
103  const ArgType & checkerList;
104  };
105 
106  template<class... T>
107  AlgorithmCheckerList<T...> makeAlgoCheckerList(const T &... args)
108  {
109  return AlgorithmCheckerList<T...>(boost::fusion::make_list(args...));
110  }
111 
112 #endif
113 
120  template<typename Scalar, int Options, template<typename, int> class JointCollectionTpl>
121  inline bool checkData(
124 
125 } // namespace pinocchio
126 
127 /* --- Details -------------------------------------------------------------------- */
128 #include "pinocchio/algorithm/check.hxx"
129 
130 #endif // ifndef __pinocchio_check_hpp__
Main pinocchio namespace.
Definition: treeview.dox:11
bool checkData(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data)
CRTP class describing the API of the checkers.
Definition: check.hpp:23
Checker having a list of Checker as input argument.
Definition: check.hpp:58