pinocchio  UNKNOWN
All Classes Namespaces Functions Variables Typedefs Enumerations Modules Pages
check.hpp
1 //
2 // Copyright (c) 2016-2018 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_check_hpp__
19 #define __se3_check_hpp__
20 
21 #include "pinocchio/multibody/model.hpp"
22 #include "pinocchio/multibody/data.hpp"
23 #include <boost/fusion/container/list.hpp>
24 #include <boost/fusion/container/generation/make_list.hpp>
25 
26 #ifndef PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE
27 #define PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE 5
28 #endif
29 
30 namespace se3
31 {
32 
34  template<typename AlgorithmCheckerDerived>
36  {
37  inline AlgorithmCheckerDerived& derived()
38  { return *static_cast< AlgorithmCheckerDerived*>(this); }
39 
40  inline const AlgorithmCheckerDerived& derived() const
41  { return *static_cast<const AlgorithmCheckerDerived*>(this); }
42 
43  inline bool checkModel(const Model & model) const { return derived().checkModel_impl(model); }
44  };
45 
46 #define DEFINE_ALGO_CHECKER(NAME) \
47  struct NAME##Checker : public AlgorithmCheckerBase<NAME##Checker> \
48  { \
49  inline bool checkModel_impl( const Model& ) const; \
50  }
51 
53  DEFINE_ALGO_CHECKER(Parent);
54 
55 #if !defined(BOOST_FUSION_HAS_VARIADIC_LIST)
56  template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE,class D,boost::fusion::void_)>
58  struct AlgorithmCheckerList: AlgorithmCheckerBase< AlgorithmCheckerList<BOOST_PP_ENUM_PARAMS(PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE,D)> >
59  {
60  typedef typename boost::fusion::list<BOOST_PP_ENUM_PARAMS(PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE,D)> ArgType;
61 
62  AlgorithmCheckerList(const ArgType & checkerList)
63  : checkerList(checkerList) {}
64 
65  // Calls model.check for each checker in the fusion::list.
66  // Each list element is supposed to implement the AlgorithmCheckerBase API.
67  bool checkModel_impl(const Model & model) const;
68 
69  const ArgType & checkerList;
70  };
71 
72 #define MAKE_ALGO_CHECKER_LIST(z,n,_) \
73  \
74  template<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class D)> \
75  AlgorithmCheckerList<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),D)> makeAlgoCheckerList(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n) , D, const & arg)) \
76  { return AlgorithmCheckerList<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),D)>(boost::fusion::make_list(BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),arg))); } \
77 
78  BOOST_PP_REPEAT(PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE, MAKE_ALGO_CHECKER_LIST, BOOST_PP_EMPTY)
79 #else
80  template <class ...D>
81  struct AlgorithmCheckerList: AlgorithmCheckerBase< AlgorithmCheckerList<D...> >
82  {
83  typedef typename boost::fusion::list<D...> ArgType;
84 
85  AlgorithmCheckerList(const ArgType & checkerList)
86  : checkerList(checkerList) {}
87 
88  // Calls model.check for each checker in the fusion::list.
89  // Each list element is supposed to implement the AlgorithmCheckerBase API.
90  bool checkModel_impl(const Model & model) const;
91 
92  const ArgType & checkerList;
93  };
94 
95  template <class ...T>
96  AlgorithmCheckerList<T...> makeAlgoCheckerList(const T&... args)
97  {
98  return AlgorithmCheckerList<T...>(boost::fusion::make_list(args...));
99  }
100 
101 #endif
102 
109  inline bool checkData(const Model & model, const Data & data);
110 
111 } // namespace se3
112 
113 
114  /* --- Details -------------------------------------------------------------------- */
115 #include "pinocchio/algorithm/check.hxx"
116 
117 #endif // ifndef __se3_check_hpp__
bool checkData(const Model &model, const Data &data)
Definition: check.hxx:69
CRTP class describing the API of the checkers.
Definition: check.hpp:35
Checker having a list of Checker as input argument.
Definition: check.hpp:58