Geogram  Version 1.8.9-rc
A programming library of geometric algorithms
common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2022 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the ALICE Project-Team nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Contact: Bruno Levy
30  *
31  * https://www.inria.fr/fr/bruno-levy
32  *
33  * Inria,
34  * Domaine de Voluceau,
35  * 78150 Le Chesnay - Rocquencourt
36  * FRANCE
37  *
38  */
39 
40 #ifndef GEOGRAM_BASIC_COMMON
41 #define GEOGRAM_BASIC_COMMON
42 
43 #include <geogram/api/defs.h>
44 
45 // iostream should be included before anything else,
46 // otherwise 'cin', 'cout' and 'cerr' will be uninitialized.
47 #include <iostream>
48 
61 namespace GEO {
62 
66  enum {
67  GEOGRAM_NO_HANDLER = 0,
68  GEOGRAM_INSTALL_HANDLERS = 1
69  };
70 
85  void GEOGRAM_API initialize(int flags = GEOGRAM_INSTALL_HANDLERS);
86 
94  void GEOGRAM_API terminate();
95 }
96 
174 #if (defined(NDEBUG) || defined(GEOGRAM_PSM)) && !defined(GEOGRAM_PSM_DEBUG)
175 #undef GEO_DEBUG
176 #undef GEO_PARANOID
177 #else
178 #define GEO_DEBUG
179 #define GEO_PARANOID
180 #endif
181 
182 // =============================== LINUX defines ===========================
183 
184 #if defined(__ANDROID__)
185 #define GEO_OS_ANDROID
186 #endif
187 
188 #if defined(__linux__)
189 
190 #define GEO_OS_LINUX
191 #define GEO_OS_UNIX
192 
193 #ifndef GEO_OS_ANDROID
194 #define GEO_OS_X11
195 #endif
196 
197 #if defined(_OPENMP)
198 # define GEO_OPENMP
199 #endif
200 
201 #if defined(__INTEL_COMPILER)
202 # define GEO_COMPILER_INTEL
203 #elif defined(__clang__)
204 # define GEO_COMPILER_CLANG
205 #elif defined(__GNUC__)
206 # define GEO_COMPILER_GCC
207 #else
208 # error "Unsupported compiler"
209 #endif
210 
211 // The following works on GCC and ICC
212 #if defined(__x86_64)
213 # define GEO_ARCH_64
214 # define GEO_PROCESSOR_X86
215 #else
216 # define GEO_ARCH_32
217 #endif
218 
219 // =============================== WINDOWS defines =========================
220 
221 #elif defined(_WIN32) || defined(_WIN64)
222 
223 #define GEO_OS_WINDOWS
224 #define GEO_PROCESSOR_X86
225 
226 #if defined(_OPENMP)
227 # define GEO_OPENMP
228 #endif
229 
230 #if defined(_MSC_VER)
231 # define GEO_COMPILER_MSVC
232 #elif defined(__MINGW32__) || defined(__MINGW64__)
233 # define GEO_COMPILER_MINGW
234 #endif
235 
236 #if defined(_WIN64)
237 # define GEO_ARCH_64
238 #else
239 # define GEO_ARCH_32
240 #endif
241 
242 // =============================== APPLE defines ===========================
243 
244 #elif defined(__APPLE__)
245 
246 #define GEO_OS_APPLE
247 #define GEO_OS_UNIX
248 
249 #if defined(_OPENMP)
250 # define GEO_OPENMP
251 #endif
252 
253 #if defined(__clang__)
254 # define GEO_COMPILER_CLANG
255 #elif defined(__GNUC__)
256 # define GEO_COMPILER_GCC
257 #else
258 # error "Unsupported compiler"
259 #endif
260 
261 #if defined(__x86_64) || defined(__ppc64__) || defined(__arm64__) || defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64)
262 # define GEO_ARCH_64
263 #else
264 # define GEO_ARCH_32
265 #endif
266 
267 // =============================== Emscripten defines ======================
268 
269 #elif defined(__EMSCRIPTEN__)
270 
271 #define GEO_OS_UNIX
272 #define GEO_OS_LINUX
273 #define GEO_OS_EMSCRIPTEN
274 #define GEO_ARCH_64
275 #define GEO_COMPILER_EMSCRIPTEN
276 
277 // =============================== Unsupported =============================
278 #else
279 #error "Unsupported operating system"
280 #endif
281 
282 #if defined(GEO_COMPILER_GCC) || \
283  defined(GEO_COMPILER_CLANG) || \
284  defined(GEO_COMPILER_MINGW) || \
285  defined(GEO_COMPILER_EMSCRIPTEN)
286 #define GEO_COMPILER_GCC_FAMILY
287 #endif
288 
289 #ifdef DOXYGEN_ONLY
290 // Keep doxygen happy
291 #define GEO_OS_WINDOWS
292 #define GEO_OS_APPLE
293 #define GEO_OS_ANDROID
294 #define GEO_ARCH_32
295 #define GEO_COMPILER_INTEL
296 #define GEO_COMPILER_MSVC
297 #endif
298 
303 #define CPP_CONCAT_(A, B) A ## B
304 
309 #define CPP_CONCAT(A, B) CPP_CONCAT_(A, B)
310 
311 #if defined(GOMGEN)
312 #define GEO_NORETURN
313 #elif defined(GEO_COMPILER_GCC_FAMILY) || \
314  defined(GEO_COMPILER_INTEL)
315 #define GEO_NORETURN __attribute__((noreturn))
316 #else
317 #define GEO_NORETURN
318 #endif
319 
320 #if defined(GOMGEN)
321 #define GEO_NORETURN_DECL
322 #elif defined(GEO_COMPILER_MSVC)
323 #define GEO_NORETURN_DECL __declspec(noreturn)
324 #else
325 #define GEO_NORETURN_DECL
326 #endif
327 
328 #if defined(GEO_COMPILER_CLANG) || defined(GEO_COMPILER_EMSCRIPTEN)
329 #if __has_feature(cxx_noexcept)
330 #define GEO_NOEXCEPT noexcept
331 #endif
332 #endif
333 
334 // For Graphite GOM generator (swig is confused by throw() specifier)
335 #ifdef GOMGEN
336 #define GEO_NOEXCEPT
337 #endif
338 
339 #ifndef GEO_NOEXCEPT
340 #define GEO_NOEXCEPT throw()
341 #endif
342 
343 #define FOR(I,UPPERBND) for(index_t I = 0; I<index_t(UPPERBND); ++I)
344 
345 // Silence warnings for alloca()
346 // We use it at different places to allocate objects on the stack
347 // (for instance, in multi-precision predicates).
348 #ifdef GEO_COMPILER_CLANG
349 #pragma GCC diagnostic ignored "-Walloca"
350 #endif
351 
352 #endif
353 
Basic definitions for the Geogram C API.
Global Vorpaline namespace.
Definition: basic.h:55
void terminate()
Cleans up Geogram.
void initialize(int flags=GEOGRAM_INSTALL_HANDLERS)
Initialize Geogram.