utils/static-if.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2020 INRIA
3 //
4 
5 #ifndef __pinocchio_utils_static_if_hpp__
6 #define __pinocchio_utils_static_if_hpp__
7 
8 #include "pinocchio/fwd.hpp"
9 
10 namespace pinocchio
11 {
12  namespace internal
13  {
14 
16  {
17  LT,
18  LE,
19  EQ,
20  GE,
22  };
23 
24  template<typename LhsType, typename RhsType, typename ThenType, typename ElseType>
26 
27  template<typename LhsType, typename RhsType>
29 
31  template<typename LhsType, typename RhsType, typename return_type>
32  struct traits<if_then_else_impl<LhsType, RhsType, return_type, return_type>>
33  {
34  typedef return_type ReturnType;
35  };
36 
37  template<typename condition_type, typename ThenType, typename ElseType>
38  struct if_then_else_impl<condition_type, condition_type, ThenType, ElseType>
39  {
41 
42  static inline ReturnType run(
43  const ComparisonOperators op,
44  const condition_type & lhs_value,
45  const condition_type & rhs_value,
46  const ThenType & then_value,
47  const ElseType & else_value)
48  {
49  switch (op)
50  {
51  case EQ:
52  if (lhs_value == rhs_value)
53  return then_value;
54  else
55  return else_value;
56  break;
57  case LT:
58  if (lhs_value < rhs_value)
59  return then_value;
60  else
61  return else_value;
62  break;
63  case LE:
64  if (lhs_value <= rhs_value)
65  return then_value;
66  else
67  return else_value;
68  break;
69  case GE:
70  if (lhs_value >= rhs_value)
71  return then_value;
72  else
73  return else_value;
74  break;
75  case GT:
76  if (lhs_value > rhs_value)
77  return then_value;
78  else
79  return else_value;
80  break;
81  }
83  std::logic_error, "ComparisonOperators " << static_cast<int>(op) << " is not managed");
84  }
85  };
86 
87  template<typename LhsType, typename RhsType, typename ThenType, typename ElseType>
88  inline typename if_then_else_impl<LhsType, RhsType, ThenType, ElseType>::ReturnType
90  const ComparisonOperators op,
91  const LhsType & lhs_value,
92  const RhsType & rhs_value,
93  const ThenType & then_value,
94  const ElseType & else_value)
95  {
97  return algo::run(op, lhs_value, rhs_value, then_value, else_value);
98  }
99 
100  // Generic
101  template<typename LhsType, typename RhsType>
102  struct comparison_eq_impl
103  {
104  static inline bool run(const LhsType & lhs_value, const RhsType & rhs_value)
105  {
106  return lhs_value == rhs_value;
107  }
108  };
109 
110  template<typename condition_type>
111  struct comparison_eq_impl<condition_type, condition_type>
112  {
113  static inline bool run(const condition_type & lhs_value, const condition_type & rhs_value)
114  {
115  return lhs_value == rhs_value;
116  }
117  };
118 
119  template<typename LhsType, typename RhsType>
120  inline bool comparison_eq(const LhsType & lhs_value, const RhsType & rhs_value)
121  {
123  return algo::run(lhs_value, rhs_value);
124  }
125  } // namespace internal
126 } // namespace pinocchio
127 
128 #endif
omniidl_be_python_with_docstring.run
def run(tree, args)
Definition: cmake/hpp/idl/omniidl_be_python_with_docstring.py:140
pinocchio::internal::ComparisonOperators
ComparisonOperators
Definition: utils/static-if.hpp:15
pinocchio::internal::GT
@ GT
Definition: utils/static-if.hpp:21
fwd.hpp
pinocchio::internal::if_then_else_impl
Definition: utils/static-if.hpp:25
pinocchio::internal::if_then_else
if_then_else_impl< LhsType, RhsType, ThenType, ElseType >::ReturnType if_then_else(const ComparisonOperators op, const LhsType &lhs_value, const RhsType &rhs_value, const ThenType &then_value, const ElseType &else_value)
Definition: utils/static-if.hpp:89
pinocchio::internal::if_then_else_impl< condition_type, condition_type, ThenType, ElseType >::ReturnType
internal::traits< if_then_else_impl >::ReturnType ReturnType
Definition: utils/static-if.hpp:40
pinocchio::internal::comparison_eq_impl
Definition: utils/static-if.hpp:28
pinocchio::internal::comparison_eq_impl< condition_type, condition_type >::run
static bool run(const condition_type &lhs_value, const condition_type &rhs_value)
Definition: utils/static-if.hpp:113
PINOCCHIO_THROW_PRETTY
#define PINOCCHIO_THROW_PRETTY(exception, message)
Definition: include/pinocchio/macros.hpp:159
pinocchio::internal::EQ
@ EQ
Definition: utils/static-if.hpp:19
pinocchio::internal::traits< if_then_else_impl< LhsType, RhsType, return_type, return_type > >::ReturnType
return_type ReturnType
Definition: utils/static-if.hpp:34
pinocchio::internal::comparison_eq
bool comparison_eq(const LhsType &lhs_value, const RhsType &rhs_value)
Definition: utils/static-if.hpp:120
pinocchio::internal::if_then_else_impl< condition_type, condition_type, ThenType, ElseType >::run
static ReturnType run(const ComparisonOperators op, const condition_type &lhs_value, const condition_type &rhs_value, const ThenType &then_value, const ElseType &else_value)
Definition: utils/static-if.hpp:42
pinocchio::internal::traits
Definition: fwd.hpp:83
pinocchio::internal::LT
@ LT
Definition: utils/static-if.hpp:17
pinocchio::internal::GE
@ GE
Definition: utils/static-if.hpp:20
pinocchio::internal::comparison_eq_impl::run
static bool run(const LhsType &lhs_value, const RhsType &rhs_value)
Definition: utils/static-if.hpp:104
pinocchio::internal::LE
@ LE
Definition: utils/static-if.hpp:18
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Sat Jun 1 2024 02:40:38