MRPT  1.9.9
common.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 /* ------------------------------------
13  Disable some warnings
14  ------------------------------------ */
15 #if defined(_MSC_VER)
16 #pragma warning(disable : 4127) // Disable conditional expression is constant
17 // (it shows up in templates where it's
18 // correct)
19 #pragma warning(disable : 4244) // argument conversion "possible loss of data"
20 #pragma warning(disable : 4503) // (Compiler: Visual C++ 2010) Disable warning
21 // for too long decorated name
22 #pragma warning(disable : 4714) // force inlined -> not inlined (in Eigen3)
23 #pragma warning(disable : 4267) // truncation size_t -> type
24 #pragma warning(disable : 4290) // Visual C++ does not implement decl.
25 // specifiers: throw(A,B,...)
26 #pragma warning(disable : 4251) // Visual C++ 2003+ warnings on STL classes
27 // when exporting to DLL...
28 #pragma warning(disable : 4275) // DLL export class derived from STL
29 #pragma warning( \
30  disable : 4251) // Warnings are emited even if a DLL export class
31 // contains a *private* STL field (?)
32 #if (_MSC_VER >= 1400)
33 // MS believes they have the right to deprecate functions in the C++ Standard
34 // STL... disable their warnings:
35 #ifndef _SCL_SECURE_NO_WARNINGS
36 #define _SCL_SECURE_NO_WARNINGS
37 #endif
38 // For the new secure library in VC++8
39 #if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
40 #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
41 #endif
42 #endif
43 #endif
44 
45 // Avoid conflicting declaration of max macro in windows headers
46 #if defined(_WIN32) && !defined(NOMINMAX)
47 #define NOMINMAX
48 #ifdef max
49 #undef max
50 #undef min
51 #endif
52 #endif
53 
54 // Generic constants and defines:
55 // ---------------------------------------------------------
56 // M_PI: Rely on standard <cmath>
57 #ifndef M_2PI
58 #define M_2PI 6.283185307179586476925286766559 // The 2*PI constant
59 #endif
60 
61 #define M_PIf 3.14159265358979f
62 #define M_2PIf 6.28318530717959f
63 
64 /** MRPT_CHECK_GCC_VERSION(MAJ,MIN) */
65 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
66 #define MRPT_CHECK_GCC_VERSION(major, minor) \
67  ((__GNUC__ > (major)) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
68 #else
69 #define MRPT_CHECK_GCC_VERSION(major, minor) 0
70 #endif
71 
72 /** MRPT_CHECK_VISUALC_VERSION(Version) Version=8 for 2005, 9=2008, 10=2010,
73  * 11=2012, 12=2013, 14=2015 */
74 #ifndef _MSC_VER
75 #define MRPT_VISUALC_VERSION(major) 0
76 #define MRPT_CHECK_VISUALC_VERSION(major) 0
77 #else
78 /* (From wxWidgets macros):
79 Things used to be simple with the _MSC_VER value and the version number
80 increasing in lock step, but _MSC_VER value of 1900 is VC14 and not the
81 non existing (presumably for the superstitious reasons) VC13, so we now
82 need to account for this with an extra offset.
83 */
84 #define MRPT_VISUALC_VERSION(major) \
85  ((6 + (major >= 14 ? (-1) : 0) + major) * 100)
86 #define MRPT_CHECK_VISUALC_VERSION(major) \
87  (_MSC_VER >= MRPT_VISUALC_VERSION(major))
88 #endif
89 
90 #ifndef __has_feature
91 #define __has_feature(x) 0 // Compatibility with non-clang compilers.
92 #endif
93 #ifndef __has_extension
94 #define __has_extension __has_feature // Compatibility with pre-3.0 compilers.
95 #endif
96 
97 // A cross-compiler definition for "deprecated"-warnings
98 /** Usage: MRPT_DEPRECATED("Use XX instead") void myFunc(double); */
99 #if defined(__clang__) && defined(__has_extension)
100 #if __has_extension(attribute_deprecated_with_message)
101 #define MRPT_DEPRECATED(msg) __attribute__((deprecated(msg)))
102 #else
103 #define MRPT_DEPRECATED(msg) __attribute__((deprecated))
104 #endif
105 #elif MRPT_CHECK_GCC_VERSION(4, 5)
106 #define MRPT_DEPRECATED(msg) __attribute__((deprecated(msg)))
107 #elif MRPT_CHECK_VISUALC_VERSION(8)
108 #define MRPT_DEPRECATED(msg) __declspec(deprecated("deprecated: " msg))
109 #else
110 #define MRPT_DEPRECATED(msg)
111 #endif
112 
113 /** Declare MRPT_TODO(message) */
114 #if defined(_MSC_VER)
115 #define MRPT_DO_PRAGMA(x) __pragma(x)
116 #define __STR2__(x) #x
117 #define __STR1__(x) __STR2__(x)
118 #define __MSVCLOC__ __FILE__ "("__STR1__(__LINE__) ") : "
119 #define MRPT_MSG_PRAGMA(_msg) MRPT_DO_PRAGMA(message(__MSVCLOC__ _msg))
120 #elif defined(__GNUC__)
121 #define MRPT_DO_PRAGMA(x) _Pragma(#x)
122 #define MRPT_MSG_PRAGMA(_msg) MRPT_DO_PRAGMA(message(_msg))
123 #else
124 #define MRPT_DO_PRAGMA(x)
125 #define MRPT_MSG_PRAGMA(_msg)
126 #endif
127 
128 #define MRPT_WARNING(x) MRPT_MSG_PRAGMA("Warning: " x)
129 #define MRPT_TODO(x) MRPT_MSG_PRAGMA("TODO: " x)
130 
131 // Define a decl. modifier for printf-like format checks at compile time:
132 #ifdef __GNUC__
133 #define MRPT_printf_format_check(_FMT_, _VARARGS_) \
134  __attribute__((__format__(__printf__, _FMT_, _VARARGS_)))
135 #else
136 #define MRPT_printf_format_check(_FMT_, _VARARGS_)
137 #endif
138 // Define a decl. modifier for scanf-like format checks at compile time:
139 #ifdef __GNUC__
140 #define MRPT_scanf_format_check(_FMT_, _VARARGS_) \
141  __attribute__((__format__(__scanf__, _FMT_, _VARARGS_)))
142 #else
143 #define MRPT_scanf_format_check(_FMT_, _VARARGS_)
144 #endif
145 
146 /** A macro for obtaining the name of the current function: */
147 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
148 #define __CURRENT_FUNCTION_NAME__ __FUNCTION__
149 #else
150 #define __CURRENT_FUNCTION_NAME__ __PRETTY_FUNCTION__
151 #endif
152 
153 // Define a decl. modifier for printf-like format checks at compile time:
154 #ifdef __GNUC__
155 #define MRPT_printf_format_check(_FMT_, _VARARGS_) \
156  __attribute__((__format__(__printf__, _FMT_, _VARARGS_)))
157 #else
158 #define MRPT_printf_format_check(_FMT_, _VARARGS_)
159 #endif
160 
161 // Define a decl. modifier for scanf-like format checks at compile time:
162 #ifdef __GNUC__
163 #define MRPT_scanf_format_check(_FMT_, _VARARGS_) \
164  __attribute__((__format__(__scanf__, _FMT_, _VARARGS_)))
165 #else
166 #define MRPT_scanf_format_check(_FMT_, _VARARGS_)
167 #endif
168 
169 /** Tells the compiler we really want to inline that function */
170 #if (defined _MSC_VER) || (defined __INTEL_COMPILER)
171 #define MRPT_FORCE_INLINE __forceinline
172 #else
173 #define MRPT_FORCE_INLINE inline
174 #endif
175 
176 /** Determines whether this is an X86 or AMD64 platform */
177 #if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || \
178  defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) || \
179  defined(__i386__) || defined(__i386) || defined(_M_I86) || \
180  defined(i386) || defined(_M_IX86) || defined(_X86_)
181 #define MRPT_IS_X86_AMD64 1
182 #endif
183 
184 /** Can be used to avoid "not used parameters" warnings from the compiler
185 */
186 #define MRPT_UNUSED_PARAM(a) (void)(a)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020