SimpleITK  1.2.4
sitkMacro.h
Go to the documentation of this file.
1 /*=========================================================================
2 *
3 * Copyright Insight Software Consortium
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18 #ifndef sitkMacro_h
19 #define sitkMacro_h
20 
21 #include <stdint.h>
22 #include <stddef.h>
23 #include <cassert>
24 #include <sstream>
25 #include <limits>
26 
27 #include "sitkConfigure.h"
28 
29 
30 // Setup symbol exports
31 //
32 #if defined _WIN32 || defined __CYGWIN__
33  #ifdef __GNUC__
34  #define SITK_ABI_EXPORT __attribute__ ((dllexport))
35  #define SITK_ABI_IMPORT __attribute__ ((dllimport))
36  #define SITK_ABI_HIDDEN
37  #else
38  #define SITK_ABI_EXPORT __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
39  #define SITK_ABI_IMPORT __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
40  #define SITK_ABI_HIDDEN
41  #endif
42 #else
43  #if __GNUC__ >= 4
44  #define SITK_ABI_EXPORT __attribute__ ((visibility ("default")))
45  #define SITK_ABI_IMPORT __attribute__ ((visibility ("default")))
46  #define SITK_ABI_HIDDEN __attribute__ ((visibility ("hidden")))
47  #else
48  #define SITK_ABI_EXPORT
49  #define SITK_ABI_IMPORT
50  #define SITK_ABI_HIDDEN
51  #endif
52 #endif
53 
54 
55 #if __cplusplus >= 201103L
56 // In c++11 the override keyword allows you to explicitly define that a function
57 // is intended to override the base-class version. This makes the code more
58 // manageable and fixes a set of common hard-to-find bugs.
59 #define SITK_OVERRIDE override
60 // In C++11 the throw-list specification has been deprecated,
61 // replaced with the noexcept specifier. Using this function
62 // specification adds the run-time check that the method does not
63 // throw. If it does throw then std::terminate will be called.
64 // Use cautiously.
65 #define SITK_NOEXCEPT noexcept
66 #else
67 #define SITK_OVERRIDE
68 #define SITK_NOEXCEPT throw()
69 #endif
70 
71 #if defined(SITK_HAS_TEMPLATE_DISAMBIGUATOR_DEPENDENT_NAME)
72 #define CLANG_TEMPLATE template
73 #else
74 #define CLANG_TEMPLATE
75 #endif
76 
77 
78 #if !defined(SITK_RETURN_SELF_TYPE_HEADER)
79 #define SITK_RETURN_SELF_TYPE_HEADER Self &
80 #endif
81 
82 namespace itk {
83 
84 namespace simple {
85 
86 class GenericException;
87 
88 #define sitkExceptionMacro(x) \
89  { \
90  std::ostringstream message; \
91  message << "sitk::ERROR: " x; \
92  throw ::itk::simple::GenericException(__FILE__, __LINE__, message.str().c_str()); \
93  }
94 
95 
96 #define sitkDebugMacro(x) \
97  {\
98  if (this->GetDebug()) \
99  { \
100  std::ostringstream msg; \
101  msg << "Debug: " << this->GetName() << " (" << this << "): " x \
102  << "\n\n"; \
103  ::itk::OutputWindowDisplayDebugText( msg.str().c_str() ); \
104  } \
105  }
106 
107 #if defined(SITK_HAS_CXX11_NULLPTR)
108 #define SITK_NULLPTR nullptr
109 #else
110 #define SITK_NULLPTR NULL
111 #endif
112 
113 
114 #define sitkMacroJoin( X, Y ) sitkDoMacroJoin( X, Y )
115 #define sitkDoMacroJoin( X, Y ) sitkDoMacroJoin2(X,Y)
116 #define sitkDoMacroJoin2( X, Y ) X##Y
117 
118 #ifdef SITK_HAS_CXX11_STATIC_ASSERT
119 // utilize the c++11 static_assert if available
120 #define sitkStaticAssert( expr, str) static_assert( expr, str )
121 #else
122 
123 template<bool> struct StaticAssertFailure;
124 template<> struct StaticAssertFailure<true>{ enum { Value = 1 }; };
125 
126 #define sitkStaticAssert( expr, str ) enum { sitkMacroJoin( static_assert_typedef, __LINE__) = sizeof( itk::simple::StaticAssertFailure<((expr) == 0 ? false : true )> ) };
127 
128 
129 #endif
130 }
131 }
132 
133 #define sitkPragma(x) _Pragma (#x)
134 
135 #if defined(__clang__) && defined(__has_warning)
136 #define sitkClangDiagnosticPush() sitkPragma( clang diagnostic push )
137 #define sitkClangDiagnosticPop() sitkPragma( clang diagnostic pop )
138 #define sitkClangWarningIgnore_0(x)
139 #define sitkClangWarningIgnore_1(x) sitkPragma( clang diagnostic ignored x)
140 #define sitkClangWarningIgnore(x) sitkMacroJoin( sitkClangWarningIgnore_, __has_warning(x) )(x)
141 #else
142 #define sitkClangDiagnosticPush()
143 #define sitkClangDiagnosticPop()
144 #define sitkClangWarningIgnore(x)
145 #endif
146 
147 
148 #endif