src/macros.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2017-2020 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_macros_hpp__
6 #define __pinocchio_macros_hpp__
7 
8 // On Windows, __cplusplus is not necessarily set to the C++ version being used.
9 // See https://docs.microsoft.com/fr-fr/cpp/build/reference/zc-cplusplus?view=vs-2019 for further information.
10 
11 #if (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703))
12  #define PINOCCHIO_WITH_CXX17_SUPPORT
13 #endif
14 
15 #if (__cplusplus >= 201403L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201403))
16  #define PINOCCHIO_WITH_CXX14_SUPPORT
17 #endif
18 
19 #if (__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600))
20  #define PINOCCHIO_WITH_CXX11_SUPPORT
21 #endif
22 
23 #define PINOCCHIO_STRING_LITERAL(string) #string
24 
25 // For more details, visit https://stackoverflow.com/questions/171435/portability-of-warning-preprocessor-directive
26 #if defined(__GNUC__) || defined(__clang__)
27  #define PINOCCHIO_PRAGMA(x) _Pragma(#x)
28  #define PINOCCHIO_PRAGMA_MESSAGE(the_message) PINOCCHIO_PRAGMA(GCC message #the_message)
29  #define PINOCCHIO_PRAGMA_WARNING(the_message) PINOCCHIO_PRAGMA(GCC warning #the_message)
30  #define PINOCCHIO_PRAGMA_DEPRECATED(the_message) PINOCCHIO_PRAGMA_WARNING(Deprecated: #the_message)
31  #define PINOCCHIO_PRAGMA_DEPRECATED_HEADER(old_header,new_header) \
32  PINOCCHIO_PRAGMA_WARNING(Deprecated header file: #old_header has been replaced by #new_header.\n Please use #new_header instead of #old_header.)
33 #endif
34 
35 // This macro can be used to prevent from macro expansion, similarly to EIGEN_NOT_A_MACRO
36 #define PINOCCHIO_NOT_A_MACRO
37 
38 namespace pinocchio
39 {
40  namespace helper
41  {
42  template<typename T> struct argument_type;
43  template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
44  }
45 }
46 
48 #define PINOCCHIO_MACRO_EMPTY_ARG
49 
51 #define PINOCCHIO_UNUSED_VARIABLE(var) (void)(var)
52 
54 #define PINOCCHIO_ASSERT_MATRIX_SPECIFIC_SIZE(type,M,nrows,ncols) \
55  EIGEN_STATIC_ASSERT( (type::RowsAtCompileTime == Eigen::Dynamic || type::RowsAtCompileTime == nrows) \
56  && (type::ColsAtCompileTime == Eigen::Dynamic || type::ColsAtCompileTime == ncols),\
57  THIS_METHOD_IS_ONLY_FOR_MATRICES_OF_A_SPECIFIC_SIZE); \
58  assert(M.rows()==nrows && M.cols()==ncols);
59 
63 #define PINOCCHIO_STATIC_ASSERT(condition,msg) \
64  { int msg[(condition) ? 1 : -1]; /*avoid unused-variable warning*/ (void) msg; }
65 
66 namespace pinocchio
67 {
68  namespace helper
69  {
70  template<typename D, template<typename> class TypeAccess>
72  {
74  };
75  }
76 }
77 
79 #if defined(__GNUC__) || defined(__clang__)
80 # define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
81 # define PINOCCHIO_COMPILER_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
82 # define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
83 #elif defined (WIN32)
84 # define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH _Pragma("warning(push)")
85 # define PINOCCHIO_COMPILER_DIAGNOSTIC_POP _Pragma("warning(pop)")
86 # define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS _Pragma("warning(disable : 4996)")
87 #else
88 # define PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
89 # define PINOCCHIO_COMPILER_DIAGNOSTIC_POP
90 # define PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
91 #endif // __GNUC__
92 
93 // Handle explicitely the GCC boring warning: 'anonymous variadic macros were introduced in C++11'
94 #include <exception>
95 #include <stdexcept>
96 
97 #if defined(__GNUC__)
98  #pragma GCC system_header
99 #endif
100 
101 #if defined(__GNUC__) || defined(__clang__)
102  #pragma GCC diagnostic push
103  #pragma GCC diagnostic ignored "-Wvariadic-macros"
104 #endif
105 
107 #if !defined(PINOCCHIO_NO_THROW)
108  #define PINOCCHIO_THROW(condition,exception_type,message) \
109  if (!(condition)) { throw exception_type(message); }
110 #else
111  #define PINOCCHIO_THROW(condition,exception_type,message)
112 #endif
113 
114 #define _PINOCCHIO_EXPAND(x) x
115 #define _PINOCCHIO_GET_OVERRIDE_FOR_CHECK_INPUT_ARGUMENT(_1, _2, MACRO_NAME, ...) MACRO_NAME
116 
117 #define _PINOCCHIO_CHECK_INPUT_ARGUMENT_2(condition, message) \
118  PINOCCHIO_THROW(condition,std::invalid_argument,message)
119 
120 #define _PINOCCHIO_CHECK_INPUT_ARGUMENT_1(condition) \
121  _PINOCCHIO_CHECK_INPUT_ARGUMENT_2(condition,\
122  "The following check on the input argument has failed: "#condition)
123 
124 #define _PINOCCHIO_CHECK_INPUT_ARGUMENT_0
125 
127 #define PINOCCHIO_CHECK_INPUT_ARGUMENT(...) \
128  _PINOCCHIO_EXPAND(_PINOCCHIO_EXPAND(_PINOCCHIO_GET_OVERRIDE_FOR_CHECK_INPUT_ARGUMENT(__VA_ARGS__,_PINOCCHIO_CHECK_INPUT_ARGUMENT_2,\
129  _PINOCCHIO_CHECK_INPUT_ARGUMENT_1,_PINOCCHIO_CHECK_INPUT_ARGUMENT_0))(__VA_ARGS__))
130 
131 #define _PINOCCHIO_GET_OVERRIDE_FOR_CHECK_ARGUMENT_SIZE(_1, _2, _3, MACRO_NAME, ...) MACRO_NAME
132 
133 #define _PINOCCHIO_CHECK_ARGUMENT_SIZE_3(size, expected_size, message) \
134  if (size != expected_size) { \
135  std::ostringstream oss; \
136  oss << "wrong argument size: expected " << expected_size << ", got " << size << std::endl; \
137  oss << "hint: " << message << std::endl; \
138  PINOCCHIO_THROW(false, std::invalid_argument, oss.str()); \
139  }
140 
141 #define _PINOCCHIO_CHECK_ARGUMENT_SIZE_2(size, expected_size) \
142  _PINOCCHIO_CHECK_ARGUMENT_SIZE_3(size, expected_size, PINOCCHIO_STRING_LITERAL(size) " is different from " PINOCCHIO_STRING_LITERAL(expected_size))
143 
144 #define _PINOCCHIO_CHECK_ARGUMENT_SIZE_1
145 
147 #define PINOCCHIO_CHECK_ARGUMENT_SIZE(...) \
148  _PINOCCHIO_EXPAND(_PINOCCHIO_EXPAND(_PINOCCHIO_GET_OVERRIDE_FOR_CHECK_ARGUMENT_SIZE(__VA_ARGS__,_PINOCCHIO_CHECK_ARGUMENT_SIZE_3, \
149  _PINOCCHIO_CHECK_ARGUMENT_SIZE_2, _PINOCCHIO_CHECK_ARGUMENT_SIZE_1))(__VA_ARGS__))
150 
151 #if defined(__GNUC__) || defined(__clang__)
152  #pragma GCC diagnostic pop
153 #endif
154 
155 #endif // ifndef __pinocchio_macros_hpp__
U
Definition: ocp.py:61
TypeAccess< typename argument_type< void(D)>::type >::type type
Definition: src/macros.hpp:73
Main pinocchio namespace.
Definition: timings.cpp:30


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:04