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


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:47