SimpleITK  
sitkMacro.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 #if defined(SITK_HAS_TEMPLATE_DISAMBIGUATOR_DEPENDENT_NAME)
55 # define CLANG_TEMPLATE template
56 #else
57 # define CLANG_TEMPLATE
58 #endif
59 
60 
61 #if !defined(SITK_RETURN_SELF_TYPE_HEADER)
62 # define SITK_RETURN_SELF_TYPE_HEADER Self &
63 #endif
64 
65 namespace itk::simple
66 {
67 
68 class GenericException;
69 
70 #define sitkExceptionMacro(x) \
71  { \
72  std::ostringstream message; \
73  message << "sitk::ERROR: " x; \
74  throw ::itk::simple::GenericException(__FILE__, __LINE__, message.str().c_str()); \
75  }
76 
77 #define sitkWarningMacro(x) \
78  { \
79  std::ostringstream msg; \
80  msg << this->GetName() << " (" << this << "): " x; \
81  itk::OutputWindowDisplayWarningText(msg.str().c_str()); \
82  }
83 
84 
85 #define sitkDebugMacro(x) \
86  { \
87  if (this->GetDebug()) \
88  { \
89  std::ostringstream msg; \
90  msg << "Debug: " << this->GetName() << " (" << this << "): " x << "\n\n"; \
91  ::itk::OutputWindowDisplayDebugText(msg.str().c_str()); \
92  } \
93  }
94 
95 #define sitkMacroJoin(X, Y) sitkDoMacroJoin(X, Y)
96 #define sitkDoMacroJoin(X, Y) sitkDoMacroJoin2(X, Y)
97 #define sitkDoMacroJoin2(X, Y) X##Y
98 
99 } // namespace itk::simple
100 
101 #define sitkPragma(x) _Pragma(#x)
102 
103 #if defined(__clang__) && defined(__has_warning)
104 # define sitkClangDiagnosticPush() sitkPragma(clang diagnostic push)
105 # define sitkClangDiagnosticPop() sitkPragma(clang diagnostic pop)
106 # define sitkClangWarningIgnore_0(x)
107 # define sitkClangWarningIgnore_1(x) sitkPragma(clang diagnostic ignored x)
108 # define sitkClangWarningIgnore(x) sitkMacroJoin(sitkClangWarningIgnore_, __has_warning(x))(x)
109 #else
110 # define sitkClangDiagnosticPush()
111 # define sitkClangDiagnosticPop()
112 # define sitkClangWarningIgnore(x)
113 #endif
114 
115 
116 #endif
sitkConfigure.h
itk::simple
Definition: sitkAdditionalProcedures.h:28