0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Standard / Standard_Macro.hxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
b1811c1d 15//! @file
16//! This file is intended to be the first file included to any
17//! Open CASCADE source. It defines platform-specific pre-processor
18//! macros necessary for correct compilation of Open CASCADE code.
7fd59977 19
20#ifndef _Standard_Macro_HeaderFile
21# define _Standard_Macro_HeaderFile
22
65acdce5 23#if defined(_MSC_VER) && (_MSC_VER < 1600)
24 #error C++11 compatible compiler is required (Visual Studio 2010 or newer)
25#endif
26
b1811c1d 27//! @def Standard_OVERRIDE
316ea293 28//! Should be used in declarations of virtual methods overridden in the
b1811c1d 29//! derived classes, to cause compilation error in the case if that virtual
30//! function disappears or changes its signature in the base class.
31//!
32//! Expands to C++11 keyword "override" on compilers that are known to
65acdce5 33//! support it; empty in other cases.
a3157439 34#if defined(__cplusplus) && (__cplusplus >= 201100L)
35 // part of C++11 standard
36 #define Standard_OVERRIDE override
37#elif defined(_MSC_VER) && (_MSC_VER >= 1700)
31b1749c 38 // MSVC extension since VS2012
a3157439 39 #define Standard_OVERRIDE override
40#else
41 #define Standard_OVERRIDE
42#endif
43
1790e9f2 44//! @def Standard_DELETE
45//! Alias for C++11 keyword "=delete" marking methods to be deleted.
46#if defined(__cplusplus) && (__cplusplus >= 201100L)
47 // part of C++11 standard
48 #define Standard_DELETE =delete
49#elif defined(_MSC_VER) && (_MSC_VER >= 1800)
50 // implemented since VS2013
51 #define Standard_DELETE =delete
52#else
53 #define Standard_DELETE
54#endif
55
b1811c1d 56//! @def Standard_FALLTHROUGH
57//! Should be used in a switch statement immediately before a case label,
58//! if code associated with the previous case label may fall through to that
59//! next label (i.e. does not end with "break" or "return" etc.).
60//! This macro indicates that the fall through is intentional and should not be
61//! diagnosed by a compiler that warns on fallthrough.
62//!
63//! Expands to C++17 attribute statement "[[fallthrough]];" on compilers that
64//! declare support of C++17, or to "__attribute__((fallthrough));" on
65//! GCC 7+.
66#if defined(__cplusplus) && (__cplusplus >= 201703L)
67 // part of C++17 standard
68 #define Standard_FALLTHROUGH [[fallthrough]];
69#elif defined(__GNUC__) && (__GNUC__ >= 7)
70 // gcc 7+
71 #define Standard_FALLTHROUGH __attribute__((fallthrough));
72#else
73 #define Standard_FALLTHROUGH
74#endif
75
0be7dbe1
BB
76//! @def Standard_NODISCARD
77//! This attribute may appear in a function declaration,
78//! enumeration declaration or class declaration. It tells the compiler to
79//! issue a warning, if a return value marked by that attribute is discarded.
80//!
81//! Expands to C++17 attribute statement "[[nodiscard]]" on compilers that
82//! declare support of this attribute, or equivalent attribute on GCC.
83#if defined(__has_cpp_attribute)
84 #if __has_cpp_attribute(nodiscard)
85 #define Standard_NODISCARD [[nodiscard]]
86 #else
87 #define Standard_NODISCARD
88 #endif
89#elif defined(__GNUC__) && ! defined(INTEL_COMPILER)
90 // According to available documentation, GCC-style __attribute__ ((warn_unused_result))
91 // should be available in GCC since version 3.4, and in CLang since 3.9;
92 // Intel compiler does not seem to support this
93 #define Standard_NODISCARD __attribute__ ((warn_unused_result))
94#else
95 #define Standard_NODISCARD
96#endif
97
b1811c1d 98//! @def Standard_UNUSED
99//! Macro for marking variables / functions as possibly unused
100//! so that compiler will not emit redundant "unused" warnings.
101//!
102//! Expands to "__attribute__((unused))" on GCC and CLang.
fb0b0531 103#if defined(__GNUC__) || defined(__clang__)
104 #define Standard_UNUSED __attribute__((unused))
105#else
106 #define Standard_UNUSED
107#endif
108
7fb9d6d5 109//! @def Standard_NOINLINE
110//! Macro for disallowing function inlining.
111//! Expands to "__attribute__((noinline))" on GCC and CLang.
112#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)))
113 #define Standard_NOINLINE __attribute__((noinline))
114#elif defined(_MSC_VER)
115 #define Standard_NOINLINE __declspec(noinline)
116#else
117 #define Standard_NOINLINE
118#endif
119
6f498847 120//! @def Standard_THREADLOCAL
121//! Define Standard_THREADLOCAL modifier as C++11 thread_local keyword where it is available.
122#if defined(__clang__)
123 // CLang version: standard CLang > 3.3 or XCode >= 8 (but excluding 32-bit ARM)
124 // Note: this has to be in separate #if to avoid failure of preprocessor on other platforms
125 #if __has_feature(cxx_thread_local)
126 #define Standard_THREADLOCAL thread_local
127 #endif
128#elif defined(__INTEL_COMPILER)
129 #if (defined(_MSC_VER) && _MSC_VER >= 1900 && __INTEL_COMPILER > 1400)
130 // requires msvcrt vc14+ (Visual Studio 2015+)
131 #define Standard_THREADLOCAL thread_local
132 #elif (!defined(_MSC_VER) && __INTEL_COMPILER > 1500)
133 #define Standard_THREADLOCAL thread_local
134 #endif
135#elif (defined(_MSC_VER) && _MSC_VER >= 1900)
136 // msvcrt coming with vc14+ (VS2015+)
137 #define Standard_THREADLOCAL thread_local
138#elif (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))
139 // GCC >= 4.8
140 #define Standard_THREADLOCAL thread_local
141#endif
142
143#ifndef Standard_THREADLOCAL
144 #define Standard_THREADLOCAL
145#endif
146
b1811c1d 147//! @def Standard_DEPRECATED("message")
148//! Can be used in declaration of a method or a class to mark it as deprecated.
149//! Use of such method or class will cause compiler warning (if supported by
150//! compiler and unless disabled).
151//! If macro OCCT_NO_DEPRECATED is defined, Standard_DEPRECATED is defined empty.
8ddd25b8 152#ifdef OCCT_NO_DEPRECATED
153 #define Standard_DEPRECATED(theMsg)
154#else
155#if defined(_MSC_VER)
156 #define Standard_DEPRECATED(theMsg) __declspec(deprecated(theMsg))
157#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__))
158 #define Standard_DEPRECATED(theMsg) __attribute__((deprecated(theMsg)))
159#elif defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
160 #define Standard_DEPRECATED(theMsg) __attribute__((deprecated))
161#else
162 #define Standard_DEPRECATED(theMsg)
163#endif
164#endif
165
b1811c1d 166//! @def Standard_DISABLE_DEPRECATION_WARNINGS
167//! Disables warnings on use of deprecated features (see Standard_DEPRECATED),
168//! from the current point till appearance of Standard_ENABLE_DEPRECATION_WARNINGS macro.
169//! This is useful for sections of code kept for backward compatibility and scheduled for removal.
170//!
171//! @def Standard_ENABLE_DEPRECATION_WARNINGS
172//! Enables warnings on use of deprecated features previously disabled by
173//! Standard_DISABLE_DEPRECATION_WARNINGS.
60273f77 174#if defined(__ICL) || defined (__INTEL_COMPILER)
175 #define Standard_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478))
176 #define Standard_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
ff1f0c9a 177#elif (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))) || defined(__clang__)
60273f77 178 // available since at least gcc 4.2 (maybe earlier), however only gcc 4.6+ supports this pragma inside the function body
179 // CLang also supports this gcc syntax (in addition to "clang diagnostic ignored")
180 #define Standard_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
181 #define Standard_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"")
1bd04b5a 182#elif defined(_MSC_VER)
183 #define Standard_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996))
184 #define Standard_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop))
60273f77 185#else
186 #define Standard_DISABLE_DEPRECATION_WARNINGS
187 #define Standard_ENABLE_DEPRECATION_WARNINGS
188#endif
189
d37ac0c2 190# ifdef _WIN32
7fd59977 191
192// We must be careful including windows.h: it is really poisonous stuff!
193// The most annoying are #defines of many identifiers that you could use in
194// normal code without knowing that Windows has its own knowledge of them...
195// So lets protect ourselves by switching OFF as much as possible of this in advance.
196// If someone needs more from windows.h, he is encouraged to #undef these symbols
197// or include windows.h prior to any OCCT stuff.
198// Note that we define each symbol to itself, so that it still can be used
199// e.g. as name of variable, method etc.
200#ifndef WIN32_LEAN_AND_MEAN
201#define WIN32_LEAN_AND_MEAN /* exclude extra Windows stuff */
202#endif
203#ifndef NOMINMAX
204#define NOMINMAX NOMINMAX /* avoid #define min() and max() */
205#endif
206#ifndef NOMSG
207#define NOMSG NOMSG /* avoid #define SendMessage etc. */
208#endif
209#ifndef NODRAWTEXT
210#define NODRAWTEXT NODRAWTEXT /* avoid #define DrawText etc. */
211#endif
212#ifndef NONLS
213#define NONLS NONLS /* avoid #define CompareString etc. */
214#endif
215#ifndef NOGDI
216#define NOGDI NOGDI /* avoid #define SetPrinter (winspool.h) etc. */
217#endif
218#ifndef NOSERVICE
219#define NOSERVICE NOSERVICE
220#endif
221#ifndef NOKERNEL
222#define NOKERNEL NOKERNEL
223#endif
224#ifndef NOUSER
225#define NOUSER NOUSER
226#endif
227#ifndef NOMCX
228#define NOMCX NOMCX
229#endif
230#ifndef NOIME
231#define NOIME NOIME
232#endif
233
d37ac0c2
TK
234#endif
235
b1811c1d 236//! @def Standard_EXPORT
237//! This macro should be used in declarations of public methods
238//! to ensure that they are exported from DLL on Windows and thus
239//! can be called from other (dependent) libraries or applications.
68df8478 240//!
241//! If macro OCCT_STATIC_BUILD is defined, then Standard_EXPORT
242//! is set to empty.
b1811c1d 243
68df8478 244# if defined(_WIN32) && !defined(OCCT_STATIC_BUILD) && !defined(HAVE_NO_DLL)
d37ac0c2
TK
245
246//======================================================
247// Windows-specific definitions
248//======================================================
249
250# ifndef Standard_EXPORT
251# define Standard_EXPORT __declspec( dllexport )
252// For global variables :
253# define Standard_EXPORTEXTERN __declspec( dllexport ) extern
254# define Standard_EXPORTEXTERNC extern "C" __declspec( dllexport )
255# endif /* Standard_EXPORT */
256
257# ifndef Standard_IMPORT
258# define Standard_IMPORT __declspec( dllimport ) extern
259# define Standard_IMPORTC extern "C" __declspec( dllimport )
260# endif /* Standard_IMPORT */
261
57c28b61 262# else /* UNIX */
7fd59977 263
264//======================================================
d37ac0c2 265// UNIX / static library definitions
7fd59977 266//======================================================
267
268# ifndef Standard_EXPORT
269# define Standard_EXPORT
270// For global variables :
271# define Standard_EXPORTEXTERN extern
272# define Standard_EXPORTEXTERNC extern "C"
273# endif /* Standard_EXPORT */
274
275# ifndef Standard_IMPORT
276# define Standard_IMPORT extern
277# define Standard_IMPORTC extern "C"
278# endif /* Standard_IMPORT */
279
280// Compatibility with old SUN compilers
281
282// This preprocessor directive is a kludge to get around
283// a bug in the Sun Workshop 5.0 compiler, it keeps the
284// /usr/include/memory.h file from being #included
285// with an incompatible extern "C" definition of memchr
286// October 18, 2000 <rboehne@ricardo-us.com>
287#if __SUNPRO_CC_COMPAT == 5
288#define _MEMORY_H
289#endif
290
57c28b61 291# endif /* _WIN32 */
7fd59977 292
b1811c1d 293//! @def OCCT_UWP
294//! This macro is defined on Windows platform in the case if the code
295//! is being compiled for UWP (Universal Windows Platform).
742cc8b0 296#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP
297 #define OCCT_UWP
298#else
299 #ifdef OCCT_UWP
300 #undef OCCT_UWP
301 #endif
302#endif
303
b84b6721 304//! @def Standard_ATOMIC
305//! Definition of Standard_ATOMIC for C++11 or visual studio that supports it.
306//! Before usage there must be "atomic" included in the following way:
307//! #ifdef Standard_HASATOMIC
308//! #include <atomic>
309//! #endif
310#if (defined(__cplusplus) && __cplusplus >= 201100L) || (defined(_MSC_VER) && _MSC_VER >= 1800) || \
311 (defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)))
312 #define Standard_HASATOMIC
313 #define Standard_ATOMIC(theType) std::atomic<theType>
314#else
315 #define Standard_ATOMIC(theType) theType
316#endif
317
1a1739b2 318//! @def Standard_Noexcept
319//! Definition of Standard_Noexcept:
320//! if noexcept is accessible, Standard_Noexcept is "noexcept" and "throw()" otherwise.
321#ifdef _MSC_VER
322 #if _MSC_VER >= 1900
323 #define Standard_Noexcept noexcept
324 #else
325 #define Standard_Noexcept throw()
326 #endif
327#else
328 #if __cplusplus >= 201103L
329 #define Standard_Noexcept noexcept
330 #else
331 #define Standard_Noexcept throw()
332 #endif
333#endif
b84b6721 334
742cc8b0 335#endif