$search
00001 /* 00002 * OpenNL: Numerical Library 00003 * Copyright (C) 2004 Bruno Levy 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 * 00019 * If you modify this software, you should include a notice giving the 00020 * name of the person performing the modification, the date of modification, 00021 * and the reason for such modification. 00022 * 00023 * Contact: Bruno Levy 00024 * 00025 * levy@loria.fr 00026 * 00027 * ISA Project 00028 * LORIA, INRIA Lorraine, 00029 * Campus Scientifique, BP 239 00030 * 54506 VANDOEUVRE LES NANCY CEDEX 00031 * FRANCE 00032 * 00033 * Note that the GNU General Public License does not permit incorporating 00034 * the Software into proprietary programs. 00035 */ 00036 00037 #ifndef __NL_PRIVATE__ 00038 #define __NL_PRIVATE__ 00039 00040 #include <NL/nl.h> 00041 #include <stdlib.h> 00042 #include <string.h> 00043 #include <stdio.h> 00044 #include <math.h> 00045 00046 00047 /*******************************************************************************************************/ 00048 /*** Assertion checks ***/ 00049 /*******************************************************************************************************/ 00050 void nl_assertion_failed(char* cond, char* file, int line) ; 00051 void nl_range_assertion_failed( 00052 double x, double min_val, double max_val, char* file, int line 00053 ) ; 00054 void nl_should_not_have_reached(char* file, int line) ; 00055 00056 #define nl_assert(x) { \ 00057 if(!(x)) { \ 00058 nl_assertion_failed(#x,__FILE__, __LINE__) ; \ 00059 } \ 00060 } 00061 00062 #define nl_range_assert(x,min_val,max_val) { \ 00063 if(((x) < (min_val)) || ((x) > (max_val))) { \ 00064 nl_range_assertion_failed(x, min_val, max_val, \ 00065 __FILE__, __LINE__ \ 00066 ) ; \ 00067 } \ 00068 } 00069 00070 #define nl_assert_not_reached { \ 00071 nl_should_not_have_reached(__FILE__, __LINE__) ; \ 00072 } 00073 00074 #ifdef NL_DEBUG 00075 #define nl_debug_assert(x) nl_assert(x) 00076 #define nl_debug_range_assert(x,min_val,max_val) nl_range_assert(x,min_val,max_val) 00077 #else 00078 #define nl_debug_assert(x) 00079 #define nl_debug_range_assert(x,min_val,max_val) 00080 #endif 00081 00082 #ifdef NL_PARANOID 00083 #define nl_parano_assert(x) nl_assert(x) 00084 #define nl_parano_range_assert(x,min_val,max_val) nl_range_assert(x,min_val,max_val) 00085 #else 00086 #define nl_parano_assert(x) 00087 #define nl_parano_range_assert(x,min_val,max_val) 00088 #endif 00089 00090 /*******************************************************************************************************/ 00091 /*** Error reporting ***/ 00092 /*******************************************************************************************************/ 00093 00094 void nlError(char* function, char* message) ; 00095 void nlWarning(char* function, char* message) ; 00096 00097 /*******************************************************************************************************/ 00098 /*** OS ***/ 00099 /*******************************************************************************************************/ 00100 00101 NLdouble nlCurrentTime() ; 00102 00103 /************************************************************************************/ 00104 /* classic macros */ 00105 00106 #ifndef MIN 00107 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) 00108 #endif 00109 00110 #ifndef MAX 00111 #define MAX(x,y) (((x) > (y)) ? (x) : (y)) 00112 #endif 00113 00114 /************************************************************************************/ 00115 /* Memory management */ 00116 /************************************************************************************/ 00117 00118 #define NL_NEW(T) (T*)(calloc(1, sizeof(T))) 00119 #define NL_NEW_ARRAY(T,NB) (T*)(calloc((NB),sizeof(T))) 00120 #define NL_RENEW_ARRAY(T,x,NB) (T*)(realloc(x,(NB)*sizeof(T))) 00121 #define NL_DELETE(x) free(x); x = NULL 00122 #define NL_DELETE_ARRAY(x) free(x); x = NULL 00123 00124 #define NL_CLEAR(T, x) memset(x, 0, sizeof(T)) 00125 #define NL_CLEAR_ARRAY(T,x,NB) memset(x, 0, (NB)*sizeof(T)) 00126 00127 #endif