include/pinocchio/macros.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2017-2022 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_macros_hpp__
6 #define __pinocchio_macros_hpp__
7 
8 #include <sstream>
9 
10 // On Windows, __cplusplus is not necessarily set to the C++ version being used.
11 // See https://docs.microsoft.com/fr-fr/cpp/build/reference/zc-cplusplus?view=vs-2019 for further
12 // information.
13 
14 #if (__cplusplus >= 202002L)
15  #define PINOCCHIO_WITH_CXX20_SUPPORT
16 #endif
17 
18 #if (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703))
19  #define PINOCCHIO_WITH_CXX17_SUPPORT
20 #endif
21 
22 #if (__cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201403))
23  #define PINOCCHIO_WITH_CXX14_SUPPORT
24 #endif
25 
26 #if (__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600))
27  #define PINOCCHIO_WITH_CXX11_SUPPORT
28 #endif
29 
30 #define PINOCCHIO_STRING_LITERAL(string) #string
31 
32 // For more details, visit
33 // https://stackoverflow.com/questions/171435/portability-of-warning-preprocessor-directive
34 #if defined(__GNUC__) || defined(__clang__)
35  #define PINOCCHIO_PRAGMA(x) _Pragma(#x)
36  #define PINOCCHIO_PRAGMA_MESSAGE(the_message) PINOCCHIO_PRAGMA(GCC message #the_message)
37  #define PINOCCHIO_PRAGMA_WARNING(the_message) PINOCCHIO_PRAGMA(GCC warning #the_message)
38  #define PINOCCHIO_PRAGMA_DEPRECATED(the_message) \
39  PINOCCHIO_PRAGMA_WARNING(Deprecated : #the_message)
40  #define PINOCCHIO_PRAGMA_DEPRECATED_HEADER(old_header, new_header) \
41  PINOCCHIO_PRAGMA_WARNING(Deprecated header file \
42  : #old_header has been replaced \
43  by #new_header.\n Please use #new_header instead of #old_header.)
44 #else
45  #define PINOCCHIO_PRAGMA(x)
46  #define PINOCCHIO_PRAGMA_MESSAGE(the_message)
47  #define PINOCCHIO_PRAGMA_WARNING(the_message)
48  #define PINOCCHIO_PRAGMA_DEPRECATED(the_message)
49  #define PINOCCHIO_PRAGMA_DEPRECATED_HEADER(old_header, new_header)
50 #endif
51 
52 // This macro can be used to prevent from macro expansion, similarly to EIGEN_NOT_A_MACRO
53 #define PINOCCHIO_NOT_A_MACRO
54 
55 namespace pinocchio
56 {
57  namespace helper
58  {
59  template<typename T>
60  struct argument_type;
61  template<typename T, typename U>
62  struct argument_type<T(U)>
63  {
64  typedef U type;
65  };
66  } // namespace helper
67 } // namespace pinocchio
68 
70 #define PINOCCHIO_MACRO_EMPTY_ARG
71 
73 #define PINOCCHIO_UNUSED_VARIABLE(var) (void)(var)
74 
76 #define PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE(type, M, nrows, ncols) \
77  EIGEN_STATIC_ASSERT( \
78  (type::RowsAtCompileTime == Eigen::Dynamic || type::RowsAtCompileTime == nrows) \
79  && (type::ColsAtCompileTime == Eigen::Dynamic || type::ColsAtCompileTime == ncols), \
80  THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE); \
81  assert(M.rows() == nrows && M.cols() == ncols);
82 
86 #define PINOCCHIO_STATIC_ASSERT(condition, msg) \
87  { \
88  int msg[(condition) ? 1 : -1]; /*avoid unused-variable warning*/ \
89  (void)msg; \
90  }
91 
92 namespace pinocchio
93 {
94  namespace helper
95  {
96  template<typename D, template<typename> class TypeAccess>
98  {
99  typedef typename TypeAccess<typename argument_type<void(D)>::type>::type type;
100  };
101  } // namespace helper
102 } // namespace pinocchio
103 
105 #if defined(__GNUC__) || defined(__clang__)
106  #define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
107  #define PINOCCHIO_COMPILER_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
108  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS \
109  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
110  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_VARIADIC_MACROS \
111  _Pragma("GCC diagnostic ignored \"-Wvariadic-macros\"")
112  #if defined(__clang__)
113  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED
114  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED \
115  _Pragma("GCC diagnostic ignored \"-Wself-assign-overloaded\"")
116  #else
117  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED \
118  _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
119  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED
120  #endif
121 #elif defined(WIN32)
122  #define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH _Pragma("warning(push)")
123  #define PINOCCHIO_COMPILER_DIAGNOSTIC_POP _Pragma("warning(pop)")
124  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS \
125  _Pragma("warning(disable : 4996)")
126  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_VARIADIC_MACROS
127  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED
128  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED
129 #else
130  #define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
131  #define PINOCCHIO_COMPILER_DIAGNOSTIC_POP
132  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
133  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_VARIADIC_MACROS
134  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED
135  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED
136 #endif // __GNUC__ || __clang__
137 
138 // Handle explicitely the GCC boring warning: 'anonymous variadic macros were introduced in C++11'
139 #include <exception>
140 #include <stdexcept>
141 #include <sstream>
142 
143 #if defined(__GNUC__)
144  #pragma GCC system_header
145 #endif
146 
149 
150 #if WIN32
151  #define PINOCCHIO_PRETTY_FUNCTION __FUNCSIG__
152 #else
153  #define PINOCCHIO_PRETTY_FUNCTION __PRETTY_FUNCTION__
154 #endif
155 
158 #if !defined(PINOCCHIO_NO_THROW)
159  #define PINOCCHIO_THROW(condition, exception_type, message) \
160  if (!(condition)) \
161  { \
162  throw exception_type(message); \
163  }
164 
165  #define PINOCCHIO_THROW_PRETTY(exception, message) \
166  { \
167  std::stringstream ss; \
168  ss << "From file: " << __FILE__ << "\n"; \
169  ss << "in function: " << PINOCCHIO_PRETTY_FUNCTION << "\n"; \
170  ss << "at line: " << __LINE__ << "\n"; \
171  ss << "message: " << message << "\n"; \
172  throw exception(ss.str()); \
173  }
174 #else
175  #define PINOCCHIO_THROW(condition, exception_type, message)
176  #define PINOCCHIO_THROW_PRETTY(exception, message)
177 #endif
178 
179 #define _PINOCCHIO_EXPAND(x) x
180 #define _PINOCCHIO_GET_OVERRIDE_FOR_CHECK_INPUT_ARGUMENT(_1, _2, MACRO_NAME, ...) MACRO_NAME
181 
182 #define _PINOCCHIO_CHECK_INPUT_ARGUMENT_2(condition, message) \
183  PINOCCHIO_THROW(condition, std::invalid_argument, message)
184 
185 #define _PINOCCHIO_CHECK_INPUT_ARGUMENT_1(condition) \
186  _PINOCCHIO_CHECK_INPUT_ARGUMENT_2( \
187  condition, "The following check on the input argument has failed: " #condition)
188 
189 #define _PINOCCHIO_CHECK_INPUT_ARGUMENT_0
190 
193 #define PINOCCHIO_CHECK_INPUT_ARGUMENT(...) \
194  _PINOCCHIO_EXPAND(_PINOCCHIO_EXPAND(_PINOCCHIO_GET_OVERRIDE_FOR_CHECK_INPUT_ARGUMENT( \
195  __VA_ARGS__, _PINOCCHIO_CHECK_INPUT_ARGUMENT_2, _PINOCCHIO_CHECK_INPUT_ARGUMENT_1, \
196  _PINOCCHIO_CHECK_INPUT_ARGUMENT_0))(__VA_ARGS__))
197 
198 #define _PINOCCHIO_GET_OVERRIDE_FOR_CHECK_ARGUMENT_SIZE(_1, _2, _3, MACRO_NAME, ...) MACRO_NAME
199 
200 #define _PINOCCHIO_CHECK_ARGUMENT_SIZE_3(size, expected_size, message) \
201  if (size != expected_size) \
202  { \
203  std::ostringstream oss; \
204  oss << "wrong argument size: expected " << expected_size << ", got " << size << std::endl; \
205  oss << "hint: " << message << std::endl; \
206  PINOCCHIO_THROW(false, std::invalid_argument, oss.str()); \
207  }
208 
209 #define _PINOCCHIO_CHECK_ARGUMENT_SIZE_2(size, expected_size) \
210  _PINOCCHIO_CHECK_ARGUMENT_SIZE_3( \
211  size, expected_size, \
212  PINOCCHIO_STRING_LITERAL(size) " is different from " PINOCCHIO_STRING_LITERAL(expected_size))
213 
214 #define _PINOCCHIO_CHECK_ARGUMENT_SIZE_1
215 
217 #define PINOCCHIO_CHECK_ARGUMENT_SIZE(...) \
218  _PINOCCHIO_EXPAND(_PINOCCHIO_EXPAND(_PINOCCHIO_GET_OVERRIDE_FOR_CHECK_ARGUMENT_SIZE( \
219  __VA_ARGS__, _PINOCCHIO_CHECK_ARGUMENT_SIZE_3, _PINOCCHIO_CHECK_ARGUMENT_SIZE_2, \
220  _PINOCCHIO_CHECK_ARGUMENT_SIZE_1))(__VA_ARGS__))
221 
223 
224 #endif // ifndef __pinocchio_macros_hpp__
simulation-contact-dynamics.T
int T
Definition: simulation-contact-dynamics.py:94
PINOCCHIO_COMPILER_DIAGNOSTIC_POP
#define PINOCCHIO_COMPILER_DIAGNOSTIC_POP
Definition: include/pinocchio/macros.hpp:131
pinocchio::helper::argument_type< T(U)>::type
U type
Definition: include/pinocchio/macros.hpp:64
PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_VARIADIC_MACROS
#define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_VARIADIC_MACROS
Definition: include/pinocchio/macros.hpp:133
pinocchio::helper::handle_return_type_without_typename::type
TypeAccess< typename argument_type< void(D)>::type >::type type
Definition: include/pinocchio/macros.hpp:99
PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
#define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
macros for pragma push/pop/ignore deprecated warnings
Definition: include/pinocchio/macros.hpp:130
pinocchio::helper::handle_return_type_without_typename
Definition: include/pinocchio/macros.hpp:97
ocp.U
U
Definition: ocp.py:61
pinocchio::helper::argument_type
Definition: include/pinocchio/macros.hpp:60
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Sat Jun 22 2024 02:41:48