Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
nl_private.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 OPENNL_PRIVATE_H
41 #define OPENNL_PRIVATE_H
42 
43 #include "nl.h"
44 #include <stdlib.h>
45 #include <string.h>
46 #include <stdio.h>
47 #include <math.h>
48 
49 #ifndef NDEBUG
50 #define NL_DEBUG
51 #endif
52 
58 #if defined(__APPLE__) && defined(__MACH__)
62 #define NL_OS_APPLE
63 #endif
64 
65 #if defined(__linux__) || defined(__ANDROID__) || defined(NL_OS_APPLE)
69 #define NL_OS_UNIX
70 #endif
71 
72 
73 #if defined(WIN32) || defined(_WIN64)
77 #define NL_OS_WINDOWS
78 #endif
79 
86 #define nl_arg_used(x) (void)x
87 
93 #if defined(__clang__) || defined(__GNUC__)
94 #define NL_NORETURN __attribute__((noreturn))
95 #else
96 #define NL_NORETURN
97 #endif
98 
99 #if defined(_MSC_VER)
100 #define NL_NORETURN_DECL __declspec(noreturn)
101 #else
102 #define NL_NORETURN_DECL
103 #endif
104 
113 NL_NORETURN_DECL void nl_assertion_failed(
114  const char* cond, const char* file, int line
115 ) NL_NORETURN;
116 
127 NL_NORETURN_DECL void nl_range_assertion_failed(
128  double x, double min_val, double max_val, const char* file, int line
129 ) NL_NORETURN;
130 
139 NL_NORETURN_DECL void nl_should_not_have_reached(
140  const char* file, int line
141 ) NL_NORETURN;
142 
147 #define nl_assert(x) { \
148  if(!(x)) { \
149  nl_assertion_failed(#x,__FILE__, __LINE__) ; \
150  } \
151  }
152 
159 #define nl_range_assert(x,min_val,max_val) { \
160  if(((int)(x) < (int)(min_val)) || ((int)(x) > (int)(max_val))) { \
161  nl_range_assertion_failed(x, min_val, max_val, \
162  __FILE__, __LINE__ \
163  ) ; \
164  } \
165  }
166 
171 #define nl_assert_not_reached { \
172  nl_should_not_have_reached(__FILE__, __LINE__) ; \
173  }
174 
175 #ifdef NL_DEBUG
176 #define nl_debug_assert(x) nl_assert(x)
177 #define nl_debug_range_assert(x,min_val,max_val) \
178  nl_range_assert(x,min_val,max_val)
179 #else
180 #define nl_debug_assert(x)
181 #define nl_debug_range_assert(x,min_val,max_val)
182 #endif
183 
184 #ifdef NL_PARANOID
185 #define nl_parano_assert(x) nl_assert(x)
186 #define nl_parano_range_assert(x,min_val,max_val) \
187  nl_range_assert(x,min_val,max_val)
188 #else
189 #define nl_parano_assert(x)
190 #define nl_parano_range_assert(x,min_val,max_val)
191 #endif
192 
204 void nlError(const char* function, const char* message) ;
205 
211 void nlWarning(const char* function, const char* message) ;
212 
224 
225 
231 
237 
243 void nlSetNumThreads(NLuint nb_threads);
244 
248 typedef void* NLdll;
249 
250 
255 #define NL_LINK_NOW 1
256 
261 #define NL_LINK_LAZY 2
262 
266 #define NL_LINK_GLOBAL 4
267 
271 #define NL_LINK_QUIET 8
272 
277 #define NL_LINK_USE_FALLBACK 16
278 
287 NLdll nlOpenDLL(const char* filename, NLenum flags);
288 
294 void nlCloseDLL(NLdll handle);
295 
303 NLfunc nlFindFunction(NLdll handle, const char* funcname);
304 
305 /******************************************************************************/
306 /* classic macros */
307 
308 #ifndef MIN
309 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
310 #endif
311 
312 #ifndef MAX
313 #define MAX(x,y) (((x) > (y)) ? (x) : (y))
314 #endif
315 
316 
328 #define NL_NEW(T) (T*)(calloc(1, sizeof(T)))
329 
336 #define NL_NEW_ARRAY(T,NB) (T*)(calloc((size_t)(NB),sizeof(T)))
337 
345 #define NL_RENEW_ARRAY(T,x,NB) (T*)(realloc(x,(size_t)(NB)*sizeof(T)))
346 
351 #define NL_DELETE(x) free(x); x = NULL
352 
358 #define NL_DELETE_ARRAY(x) free(x); x = NULL
359 
365 #define NL_CLEAR(T, x) memset(x, 0, sizeof(T))
366 
373 #define NL_CLEAR_ARRAY(T,x,NB) memset(x, 0, (size_t)(NB)*sizeof(T))
374 
384 #define NL_UINT_MAX 0xffffffff
385 
389 #define NL_USHORT_MAX 0xffff
390 
397 extern NLprintfFunc nl_printf;
398 
399 extern NLfprintfFunc nl_fprintf;
400 
405 #endif
The public API of the OpenNL linear solver library. Click the "More..." link below for simple example...
uint32_t NLuint
A 4-bytes unsigned integer.
Definition: nl.h:263
int(* NLprintfFunc)(const char *format,...)
Function pointer type for user printf function.
Definition: nl.h:1434
double NLdouble
A double-precision floating-point number.
Definition: nl.h:288
void(* NLfunc)(void)
A function pointer.
Definition: nl.h:297
unsigned int NLenum
A symbolic constant.
Definition: nl.h:215
int(* NLfprintfFunc)(FILE *out, const char *format,...)
Function pointer type for user fprintf function.
Definition: nl.h:1439
void nlCloseDLL(NLdll handle)
Closes a DLL/shared object/dylib.
NLdouble nlCurrentTime(void)
Gets the current time in seconds.
void nlWarning(const char *function, const char *message)
Displays a warning message.
NLuint nlGetNumThreads(void)
Gets the number of threads.
NL_NORETURN_DECL void nl_assertion_failed(const char *cond, const char *file, int line) NL_NORETURN
Displays an error message and aborts the program when an assertion failed.
NLuint nlGetNumCores(void)
Gets the number of cores.
NL_NORETURN_DECL void nl_range_assertion_failed(double x, double min_val, double max_val, const char *file, int line) NL_NORETURN
Displays an error message and aborts the program when a range assertion failed.
void nlError(const char *function, const char *message)
Displays an error message.
NLfunc nlFindFunction(NLdll handle, const char *funcname)
Finds a function in a DLL/shared object/dylib.
NLdll nlOpenDLL(const char *filename, NLenum flags)
Dynamically links a DLL/shared object/dylib to the current process.
NL_NORETURN_DECL void nl_should_not_have_reached(const char *file, int line) NL_NORETURN
Displays an error message and aborts the program when the execution flow reached a point it should no...
void nlSetNumThreads(NLuint nb_threads)
Sets the number of threads.
void * NLdll
Type for manipulating DLL/shared object/dylib handles.
Definition: nl_private.h:248
Functions for string manipulation.