Lightmetrica  0.0.1.50dbee3 (yosakoi)
 All Classes Functions Variables Typedefs Enumerations Enumerator
common.h
1 /*
2  Lightmetrica : A research-oriented renderer
3 
4  Copyright (c) 2014 Hisanari Otsu
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 #ifndef LIB_LIGHTMETRICA_COMMON_H
22 #define LIB_LIGHTMETRICA_COMMON_H
23 
24 // C++ compiler is required
25 #ifndef __cplusplus
26  #error "C++ compiler is required"
27 #endif
28 
29 // Debug mode flag
30 #ifndef NDEBUG
31  #define LM_DEBUG_MODE 1
32 #else
33  #define LM_DEBUG_MODE 0
34 #endif
35 
36 // Experimental mode flag
37 #ifdef LM_ENABLE_EXPERIMENTAL_MODE
38  #define LM_EXPERIMENTAL_MODE 1
39 #else
40  #define LM_EXPERIMENTAL_MODE 0
41 #endif
42 
43 // Strict floating-point mode flag
44 #ifdef LM_ENABLE_STRICT_FP
45  #define LM_STRICT_FP 1
46 #else
47  #define LM_STRICT_FP 0
48 #endif
49 
50 // MPI flag
51 #ifdef LM_USE_MPI
52  #define LM_MPI 1
53 #else
54  #define LM_MPI 0
55 #endif
56 
57 // --------------------------------------------------------------------------------
58 
59 // Platform
60 
61 // Windows
62 #ifdef _WIN32
63  #define LM_PLATFORM_WINDOWS 1
64 #else
65  #define LM_PLATFORM_WINDOWS 0
66 #endif
67 
68 // Linux
69 #ifdef __linux
70  #define LM_PLATFORM_LINUX 1
71 #else
72  #define LM_PLATFORM_LINUX 0
73 #endif
74 
75 #if LM_PLATFORM_WINDOWS == LM_PLATFORM_LINUX
76  #error "Unsupportted platform"
77 #endif
78 
79 #if LM_PLATFORM_WINDOWS
80  #define NOMINMAX
81  #define WIN32_LEAN_AND_MEAN
82  #pragma warning(disable:4819) // Level 1. Character that cannot be represented
83  #pragma warning(disable:4996) // Level 3. _SCL_SECURE_NO_WARNINGS
84  #pragma warning(disable:4290) // Level 3. Exception specification ignored
85  #pragma warning(disable:4201) // Level 4. Nonstandard extension used : nameless struct/union
86  #pragma warning(disable:4512) // Level 4. Cannot generate an assignment operator for the given class
87  #pragma warning(disable:4127) // Level 4. Conditional expression is constant
88  #pragma warning(disable:4510) // Level 4. Default constructor could not be generated
89  #pragma warning(disable:4610) // Level 4. User-defined constructor required
90  #pragma warning(disable:4100) // Level 4. Unreferenced formal parameter
91  #pragma warning(disable:4505) // Level 4. Unreferenced local function has been removed
92  #pragma warning(disable:4324) // Level 4. Structure was padded due to __declspec(align())
93 #endif
94 
95 // --------------------------------------------------------------------------------
96 
97 // Compiler
98 
99 // Microsoft Visual C++
100 #ifdef _MSC_VER
101  #define LM_COMPILER_MSVC 1
102 #else
103  #define LM_COMPILER_MSVC 0
104 #endif
105 
106 // GNU GCC
107 #if defined(__GNUC__) || defined(__MINGW32__)
108  #define LM_COMPILER_GCC 1
109 #else
110  #define LM_COMPILER_GCC 0
111 #endif
112 
113 #if LM_COMPILER_MSVC == LM_COMPILER_GCC
114  #error "Unsupportted compiler"
115 #endif
116 
117 // --------------------------------------------------------------------------------
118 
119 // Architecture
120 #if LM_COMPILER_MSVC
121  #ifdef _M_IX86
122  #define LM_ARCH_X86 1
123  #else
124  #define LM_ARCH_X86 0
125  #endif
126  #ifdef _M_X64
127  #define LM_ARCH_X64 1
128  #else
129  #define LM_ARCH_X64 0
130  #endif
131 #elif LM_COMPILER_GCC
132  #ifdef __i386__
133  #define LM_ARCH_X86 1
134  #else
135  #define LM_ARCH_X86 0
136  #endif
137  #ifdef __x86_64__
138  #define LM_ARCH_X64 1
139  #else
140  #define LM_ARCH_X64 0
141  #endif
142 #endif
143 
144 #if LM_ARCH_X86 == LM_ARCH_X64
145  #error "Unsupportted architecture"
146 #endif
147 
148 // --------------------------------------------------------------------------------
149 
150 // Library import or export
151 #if LM_COMPILER_MSVC
152  #ifdef LM_EXPORTS
153  #define LM_PUBLIC_API __declspec(dllexport)
154  #else
155  #define LM_PUBLIC_API __declspec(dllimport)
156  #endif
157  #define LM_HIDDEN_API
158 #elif LM_COMPILER_GCC
159  #ifdef LM_EXPORTS
160  #define LM_PUBLIC_API __attribute__ ((visibility("default")))
161  #define LM_HIDDEN_API __attribute__ ((visibility("hidden")))
162  #else
163  #define LM_PUBLIC_API
164  #define LM_HIDDEN_API
165  #endif
166 #else
167  #define LM_PUBLIC_API
168  #define LM_HIDDEN_API
169 #endif
170 
171 #if LM_COMPILER_MSVC
172  #ifdef LM_PLUGIN_EXPORTS
173  #define LM_PLUGIN_PUBLIC_API __declspec(dllexport)
174  #else
175  #define LM_PLUGIN_PUBLIC_API __declspec(dllimport)
176  #endif
177  #define LM_PLUGIN_HIDDEN_API
178 #elif LM_COMPILER_GCC
179  #ifdef LM_PLUGIN_EXPORTS
180  #define LM_PLUGIN_PUBLIC_API __attribute__ ((visibility("default")))
181  #define LM_PLUGIN_HIDDEN_API __attribute__ ((visibility("hidden")))
182  #else
183  #define LM_PLUGIN_PUBLIC_API
184  #define LM_PLUGIN_HIDDEN_API
185  #endif
186 #else
187  #define LM_PLUGIN_PUBLIC_API
188  #define LM_PLUGIN_HIDDEN_API
189 #endif
190 
191 // In the debug mode, the hidden API is exposed
192 #if LM_DEBUG_MODE
193  #undef LM_HIDDEN_API
194  #define LM_HIDDEN_API LM_PUBLIC_API
195 #endif
196 
197 // Plugin export
198 #if LM_COMPILER_MSVC
199  #define LM_PLUGIN_API __declspec(dllexport)
200 #elif LM_COMPILER_GCC
201  #define LM_PLUGIN_API __attribute__ ((visibility("default")))
202 #else
203  #define LM_PLUGIN_API
204 #endif
205 
206 // --------------------------------------------------------------------------------
207 
208 // Force inline
209 #if LM_COMPILER_MSVC
210  #define LM_FORCE_INLINE __forceinline
211 #elif LM_COMPILER_GCC
212  #define LM_FORCE_INLINE inline __attribute__((always_inline))
213 #endif
214 
215 // Alignment
216 #if LM_COMPILER_MSVC
217  #define LM_ALIGN(x) __declspec(align(x))
218 #elif LM_COMPILER_GCC
219  #define LM_ALIGN(x) __attribute__((aligned(x)))
220 #endif
221 #define LM_ALIGN_16 LM_ALIGN(16)
222 #define LM_ALIGN_32 LM_ALIGN(32)
223 
224 // --------------------------------------------------------------------------------
225 
226 // Namespaces
227 #define LM_NAMESPACE_BEGIN namespace lightmetrica {
228 #define LM_NAMESPACE_END }
229 
230 //#define LM_DETAIL_NAMESPACE_BEGIN namespace detail {
231 //#define LM_DETAIL_NAMESPACE_END }
232 
233 // --------------------------------------------------------------------------------
234 
235 #define LM_SAFE_DELETE(val) if ((val) != NULL ) { delete (val); (val) = NULL; }
236 #define LM_SAFE_DELETE_ARRAY(val) if ((val) != NULL ) { delete[] (val); (val) = NULL; }
237 
238 #define LM_DISABLE_COPY_AND_MOVE(TypeName) \
239  TypeName(const TypeName &); \
240  TypeName(TypeName&&); \
241  void operator=(const TypeName&); \
242  void operator=(TypeName&&)
243 
244 #endif // LIB_LIGHTMETRICA_COMMON_H