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 : #old_header has been replaced \
42  by #new_header.\n Please use #new_header instead of #old_header.)
43 #else
44  #define PINOCCHIO_PRAGMA(x)
45  #define PINOCCHIO_PRAGMA_MESSAGE(the_message)
46  #define PINOCCHIO_PRAGMA_WARNING(the_message)
47  #define PINOCCHIO_PRAGMA_DEPRECATED(the_message)
48  #define PINOCCHIO_PRAGMA_DEPRECATED_HEADER(old_header, new_header)
49 #endif
50 
53 #define PINOCCHIO_DONT_INLINE EIGEN_DONT_INLINE
54 
55 // This macro can be used to prevent from macro expansion, similarly to EIGEN_NOT_A_MACRO
56 #define PINOCCHIO_NOT_A_MACRO
57 
58 namespace pinocchio
59 {
60  namespace helper
61  {
62  template<typename T>
63  struct argument_type;
64  template<typename T, typename U>
65  struct argument_type<T(U)>
66  {
67  typedef U type;
68  };
69  } // namespace helper
70 } // namespace pinocchio
71 
73 #define PINOCCHIO_MACRO_EMPTY_ARG
74 
76 #define PINOCCHIO_UNUSED_VARIABLE(var) (void)(var)
77 
79 #define PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE(type, M, nrows, ncols) \
80  EIGEN_STATIC_ASSERT( \
81  (type::RowsAtCompileTime == Eigen::Dynamic || type::RowsAtCompileTime == nrows) \
82  && (type::ColsAtCompileTime == Eigen::Dynamic || type::ColsAtCompileTime == ncols), \
83  THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE); \
84  assert(M.rows() == nrows && M.cols() == ncols);
85 
89 #define PINOCCHIO_STATIC_ASSERT(condition, msg) \
90  { \
91  int msg[(condition) ? 1 : -1]; /*avoid unused-variable warning*/ \
92  (void)msg; \
93  }
94 
95 namespace pinocchio
96 {
97  namespace helper
98  {
99  template<typename D, template<typename> class TypeAccess>
101  {
102  typedef typename TypeAccess<typename argument_type<void(D)>::type>::type type;
103  };
104  } // namespace helper
105 } // namespace pinocchio
106 
108 #if defined(__GNUC__) || defined(__clang__)
109  #define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
110  #define PINOCCHIO_COMPILER_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
111  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS \
112  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
113  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_VARIADIC_MACROS \
114  _Pragma("GCC diagnostic ignored \"-Wvariadic-macros\"")
115  #if defined(__clang__)
116  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED
117  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED \
118  _Pragma("GCC diagnostic ignored \"-Wself-assign-overloaded\"")
119  #else
120  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED \
121  _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
122  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED
123  #endif
124 #elif defined(WIN32)
125  #define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH _Pragma("warning(push)")
126  #define PINOCCHIO_COMPILER_DIAGNOSTIC_POP _Pragma("warning(pop)")
127  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS \
128  _Pragma("warning(disable : 4996)")
129  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_VARIADIC_MACROS
130  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED
131  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED
132 #else
133  #define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
134  #define PINOCCHIO_COMPILER_DIAGNOSTIC_POP
135  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
136  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_VARIADIC_MACROS
137  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED
138  #define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED
139 #endif // __GNUC__ || __clang__
140 
141 // Handle explicitely the GCC boring warning: 'anonymous variadic macros were introduced in C++11'
142 #include <exception>
143 #include <stdexcept>
144 #include <sstream>
145 
146 #if defined(__GNUC__)
147  #pragma GCC system_header
148 #endif
149 
152 
153 #if WIN32
154  #define PINOCCHIO_PRETTY_FUNCTION __FUNCSIG__
155 #else
156  #define PINOCCHIO_PRETTY_FUNCTION __PRETTY_FUNCTION__
157 #endif
158 
161 #if !defined(PINOCCHIO_NO_THROW)
162  #define PINOCCHIO_THROW(condition, exception_type, message) \
163  if (!(condition)) \
164  { \
165  throw exception_type(message); \
166  }
167 
168  #define PINOCCHIO_THROW_PRETTY(exception, message) \
169  { \
170  std::stringstream ss; \
171  ss << "From file: " << __FILE__ << "\n"; \
172  ss << "in function: " << PINOCCHIO_PRETTY_FUNCTION << "\n"; \
173  ss << "at line: " << __LINE__ << "\n"; \
174  ss << "message: " << message << "\n"; \
175  throw exception(ss.str()); \
176  }
177 #else
178  #define PINOCCHIO_THROW(condition, exception_type, message)
179  #define PINOCCHIO_THROW_PRETTY(exception, message)
180 #endif
181 
182 #define _PINOCCHIO_EXPAND(x) x
183 #define _PINOCCHIO_GET_OVERRIDE_FOR_CHECK_INPUT_ARGUMENT(_1, _2, MACRO_NAME, ...) MACRO_NAME
184 
185 #define _PINOCCHIO_CHECK_INPUT_ARGUMENT_2(condition, message) \
186  PINOCCHIO_THROW(condition, std::invalid_argument, message)
187 
188 #define _PINOCCHIO_CHECK_INPUT_ARGUMENT_1(condition) \
189  _PINOCCHIO_CHECK_INPUT_ARGUMENT_2( \
190  condition, "The following check on the input argument has failed: " #condition)
191 
192 #define _PINOCCHIO_CHECK_INPUT_ARGUMENT_0
193 
196 #define PINOCCHIO_CHECK_INPUT_ARGUMENT(...) \
197  _PINOCCHIO_EXPAND(_PINOCCHIO_EXPAND(_PINOCCHIO_GET_OVERRIDE_FOR_CHECK_INPUT_ARGUMENT( \
198  __VA_ARGS__, _PINOCCHIO_CHECK_INPUT_ARGUMENT_2, _PINOCCHIO_CHECK_INPUT_ARGUMENT_1, \
199  _PINOCCHIO_CHECK_INPUT_ARGUMENT_0))(__VA_ARGS__))
200 
201 #define _PINOCCHIO_GET_OVERRIDE_FOR_CHECK_ARGUMENT_SIZE(_1, _2, _3, MACRO_NAME, ...) MACRO_NAME
202 
203 #define _PINOCCHIO_CHECK_ARGUMENT_SIZE_3(size, expected_size, message) \
204  if (size != expected_size) \
205  { \
206  std::ostringstream oss; \
207  oss << "wrong argument size: expected " << expected_size << ", got " << size << std::endl; \
208  oss << "hint: " << message << std::endl; \
209  PINOCCHIO_THROW(false, std::invalid_argument, oss.str()); \
210  }
211 
212 #define _PINOCCHIO_CHECK_ARGUMENT_SIZE_2(size, expected_size) \
213  _PINOCCHIO_CHECK_ARGUMENT_SIZE_3( \
214  size, expected_size, \
215  PINOCCHIO_STRING_LITERAL(size) " is different from " PINOCCHIO_STRING_LITERAL(expected_size))
216 
217 #define _PINOCCHIO_CHECK_ARGUMENT_SIZE_1
218 
220 #define PINOCCHIO_CHECK_ARGUMENT_SIZE(...) \
221  _PINOCCHIO_EXPAND(_PINOCCHIO_EXPAND(_PINOCCHIO_GET_OVERRIDE_FOR_CHECK_ARGUMENT_SIZE( \
222  __VA_ARGS__, _PINOCCHIO_CHECK_ARGUMENT_SIZE_3, _PINOCCHIO_CHECK_ARGUMENT_SIZE_2, \
223  _PINOCCHIO_CHECK_ARGUMENT_SIZE_1))(__VA_ARGS__))
224 
226 
227 #endif // ifndef __pinocchio_macros_hpp__
simulation-contact-dynamics.T
int T
Definition: simulation-contact-dynamics.py:89
PINOCCHIO_COMPILER_DIAGNOSTIC_POP
#define PINOCCHIO_COMPILER_DIAGNOSTIC_POP
Definition: include/pinocchio/macros.hpp:134
pinocchio::helper::argument_type< T(U)>::type
U type
Definition: include/pinocchio/macros.hpp:67
PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_VARIADIC_MACROS
#define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_VARIADIC_MACROS
Definition: include/pinocchio/macros.hpp:136
pinocchio::helper::handle_return_type_without_typename::type
TypeAccess< typename argument_type< void(D)>::type >::type type
Definition: include/pinocchio/macros.hpp:102
PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
#define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
macros for pragma push/pop/ignore deprecated warnings
Definition: include/pinocchio/macros.hpp:133
pinocchio::helper::handle_return_type_without_typename
Definition: include/pinocchio/macros.hpp:100
ocp.U
U
Definition: ocp.py:81
pinocchio::helper::argument_type
Definition: include/pinocchio/macros.hpp:63
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:33


pinocchio
Author(s):
autogenerated on Wed May 28 2025 02:41:20