X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=blobdiff_plain;f=src%2FStandard%2FStandard_Macro.hxx;h=b1038fafd61f676e917bca4df31ce683bb912d3e;hp=9a47dd9085f0ae4dcac515c6f14820fa74112998;hb=b1811c1d2b78aab36e2e75d0a2191cc768e9c232;hpb=03155c18a585b9f62c37c12f38f93b3b0ebb93e4 diff --git a/src/Standard/Standard_Macro.hxx b/src/Standard/Standard_Macro.hxx index 9a47dd9085..b1038fafd6 100644 --- a/src/Standard/Standard_Macro.hxx +++ b/src/Standard/Standard_Macro.hxx @@ -12,49 +12,106 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -// Purpose: This file is intended to be the first file #included to any -// Open CASCADE source. It defines platform-specific pre-processor -// macros necessary for correct compilation of Open CASCADE code +//! @file +//! This file is intended to be the first file included to any +//! Open CASCADE source. It defines platform-specific pre-processor +//! macros necessary for correct compilation of Open CASCADE code. #ifndef _Standard_Macro_HeaderFile # define _Standard_Macro_HeaderFile -// Standard OCC macros: Handle(), STANDARD_TYPE() -# define Handle(ClassName) Handle_##ClassName -# define STANDARD_TYPE(aType) aType##_Type_() - +//! @def Standard_OVERRIDE +//! Should be used in declarations of virtual methods overriden in the +//! derived classes, to cause compilation error in the case if that virtual +//! function disappears or changes its signature in the base class. +//! +//! Expands to C++11 keyword "override" on compilers that are known to +//! suppot it; empty in other cases. #if defined(__cplusplus) && (__cplusplus >= 201100L) // part of C++11 standard #define Standard_OVERRIDE override #elif defined(_MSC_VER) && (_MSC_VER >= 1700) - // MSVC extension since VS2005 + // MSVC extension since VS2012 #define Standard_OVERRIDE override #else #define Standard_OVERRIDE #endif -//====================================================== -// Windows-specific definitions -//====================================================== +//! @def Standard_FALLTHROUGH +//! Should be used in a switch statement immediately before a case label, +//! if code associated with the previous case label may fall through to that +//! next label (i.e. does not end with "break" or "return" etc.). +//! This macro indicates that the fall through is intentional and should not be +//! diagnosed by a compiler that warns on fallthrough. +//! +//! Expands to C++17 attribute statement "[[fallthrough]];" on compilers that +//! declare support of C++17, or to "__attribute__((fallthrough));" on +//! GCC 7+. +#if defined(__cplusplus) && (__cplusplus >= 201703L) + // part of C++17 standard + #define Standard_FALLTHROUGH [[fallthrough]]; +#elif defined(__GNUC__) && (__GNUC__ >= 7) + // gcc 7+ + #define Standard_FALLTHROUGH __attribute__((fallthrough)); +#else + #define Standard_FALLTHROUGH +#endif -// check if WNT macro is not defined but compiler is MSVC -#if defined(_MSC_VER) && !defined(WNT) -#error "Wrong compiler options has been detected. Add /DWNT option for proper compilation!!!!!" +//! @def Standard_UNUSED +//! Macro for marking variables / functions as possibly unused +//! so that compiler will not emit redundant "unused" warnings. +//! +//! Expands to "__attribute__((unused))" on GCC and CLang. +#if defined(__GNUC__) || defined(__clang__) + #define Standard_UNUSED __attribute__((unused)) +#else + #define Standard_UNUSED #endif -# if defined(_WIN32) && !defined(HAVE_NO_DLL) +//! @def Standard_DEPRECATED("message") +//! Can be used in declaration of a method or a class to mark it as deprecated. +//! Use of such method or class will cause compiler warning (if supported by +//! compiler and unless disabled). +//! If macro OCCT_NO_DEPRECATED is defined, Standard_DEPRECATED is defined empty. +#ifdef OCCT_NO_DEPRECATED + #define Standard_DEPRECATED(theMsg) +#else +#if defined(_MSC_VER) + #define Standard_DEPRECATED(theMsg) __declspec(deprecated(theMsg)) +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__)) + #define Standard_DEPRECATED(theMsg) __attribute__((deprecated(theMsg))) +#elif defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) + #define Standard_DEPRECATED(theMsg) __attribute__((deprecated)) +#else + #define Standard_DEPRECATED(theMsg) +#endif +#endif -# ifndef Standard_EXPORT -# define Standard_EXPORT __declspec( dllexport ) -// For global variables : -# define Standard_EXPORTEXTERN __declspec( dllexport ) extern -# define Standard_EXPORTEXTERNC extern "C" __declspec( dllexport ) -# endif /* Standard_EXPORT */ +//! @def Standard_DISABLE_DEPRECATION_WARNINGS +//! Disables warnings on use of deprecated features (see Standard_DEPRECATED), +//! from the current point till appearance of Standard_ENABLE_DEPRECATION_WARNINGS macro. +//! This is useful for sections of code kept for backward compatibility and scheduled for removal. +//! +//! @def Standard_ENABLE_DEPRECATION_WARNINGS +//! Enables warnings on use of deprecated features previously disabled by +//! Standard_DISABLE_DEPRECATION_WARNINGS. +#if defined(__ICL) || defined (__INTEL_COMPILER) + #define Standard_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:1478)) + #define Standard_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop)) +#elif defined(_MSC_VER) + #define Standard_DISABLE_DEPRECATION_WARNINGS __pragma(warning(push)) __pragma(warning(disable:4996)) + #define Standard_ENABLE_DEPRECATION_WARNINGS __pragma(warning(pop)) +#elif (defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__) + // available since at least gcc 4.2 (maybe earlier), however only gcc 4.6+ supports this pragma inside the function body + // CLang also supports this gcc syntax (in addition to "clang diagnostic ignored") + #define Standard_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") + #define Standard_ENABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic warning \"-Wdeprecated-declarations\"") +#else + #define Standard_DISABLE_DEPRECATION_WARNINGS + #define Standard_ENABLE_DEPRECATION_WARNINGS +#endif -# ifndef Standard_IMPORT -# define Standard_IMPORT __declspec( dllimport ) extern -# define Standard_IMPORTC extern "C" __declspec( dllimport ) -# endif /* Standard_IMPORT */ +# ifdef _WIN32 // We must be careful including windows.h: it is really poisonous stuff! // The most annoying are #defines of many identifiers that you could use in @@ -98,10 +155,35 @@ #define NOIME NOIME #endif -# else /* WNT */ +#endif + +//! @def Standard_EXPORT +//! This macro should be used in declarations of public methods +//! to ensure that they are exported from DLL on Windows and thus +//! can be called from other (dependent) libraries or applications. + +# if defined(_WIN32) && !defined(HAVE_NO_DLL) + +//====================================================== +// Windows-specific definitions +//====================================================== + +# ifndef Standard_EXPORT +# define Standard_EXPORT __declspec( dllexport ) +// For global variables : +# define Standard_EXPORTEXTERN __declspec( dllexport ) extern +# define Standard_EXPORTEXTERNC extern "C" __declspec( dllexport ) +# endif /* Standard_EXPORT */ + +# ifndef Standard_IMPORT +# define Standard_IMPORT __declspec( dllimport ) extern +# define Standard_IMPORTC extern "C" __declspec( dllimport ) +# endif /* Standard_IMPORT */ + +# else /* UNIX */ //====================================================== -// UNIX definitions +// UNIX / static library definitions //====================================================== # ifndef Standard_EXPORT @@ -127,14 +209,13 @@ #define _MEMORY_H #endif -# endif /* WNT */ +# endif /* _WIN32 */ //====================================================== // Other //====================================================== # ifndef __Standard_API -//# ifdef WNT # if !defined(_WIN32) || defined(__Standard_DLL) || defined(__FSD_DLL) || defined(__MMgt_DLL) || defined(__OSD_DLL) || defined(__Plugin_DLL) || defined(__Quantity_DLL) || defined(__Resource_DLL) || defined(__SortTools_DLL) || defined(__StdFail_DLL) || defined(__Storage_DLL) || defined(__TColStd_DLL) || defined(__TCollection_DLL) || defined(__TShort_DLL) || defined(__Units_DLL) || defined(__UnitsAPI_DLL) || defined(__Dico_DLL) # define __Standard_API Standard_EXPORT # define __Standard_APIEXTERN Standard_EXPORTEXTERN @@ -142,9 +223,17 @@ # define __Standard_API Standard_IMPORT # define __Standard_APIEXTERN Standard_IMPORT # endif // __Standard_DLL -//# else -//# define __Standard_API -//# endif // WNT # endif // __Standard_API -#endif +//! @def OCCT_UWP +//! This macro is defined on Windows platform in the case if the code +//! is being compiled for UWP (Universal Windows Platform). +#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP + #define OCCT_UWP +#else + #ifdef OCCT_UWP + #undef OCCT_UWP + #endif +#endif + +#endif