Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLUtils/src/ICLUtils/Macros.h ** 00010 ** Module : ICLUtils ** 00011 ** Authors: Christof Elbrechter, Michael Goetting, Robert Haschke ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.GPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 #include <ICLUtils/CompatMacros.h> 00034 #include <iostream> 00035 #include <stdlib.h> 00036 #include <math.h> 00037 00038 namespace icl { 00039 namespace utils{ 00040 00041 /* {{{ Debug Level */ 00042 00043 //---- The following DebugMessage can be activated by defining DEBUGLEVEL_{0..5} 00044 00045 // do not comment out debug level 0 00046 #define DEBUGLEVEL_1 00047 00048 //---- Debug Level 0 ---- 00049 #if (defined(DEBUGLEVEL_0) ||defined(DEBUGLEVEL_1) || defined(DEBUGLEVEL_2) || defined (DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5)) 00050 #define DEBUG_LOG0(x) \ 00051 { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; } 00052 #else 00053 #define DEBUG_LOG0(x) 00054 #endif // DEBUGLEVEL 0 00055 00056 #define DEBUG_LOG(x) DEBUG_LOG0(x) 00057 00058 //---- Debug Level 1 ---- 00059 #if (defined(DEBUGLEVEL_1) || defined(DEBUGLEVEL_2) || defined (DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5)) 00060 #define DEBUG_LOG1(x) \ 00061 { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; } 00062 #else 00063 #define DEBUG_LOG1(x) 00064 #endif // DEBUGLEVEL 1 00065 00066 //---- Debug Level 2 ---- 00067 #if (defined(DEBUGLEVEL_2) || defined(DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5)) 00068 #define DEBUG_LOG2(x) \ 00069 { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; } 00070 #else 00071 #define DEBUG_LOG2(x) 00072 #endif // DEBUGLEVEL 2 00073 00074 //---- Debug Level 3 ---- 00075 #if (defined(DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5)) 00076 #define DEBUG_LOG3(x) \ 00077 { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; } 00078 #else 00079 #define DEBUG_LOG3(x) 00080 #endif // DEBUGLEVEL 3 00081 00082 //---- Debug Level 4 ---- 00083 #if (defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5)) 00084 #define DEBUG_LOG4(x) \ 00085 { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; } 00086 #else 00087 #define DEBUG_LOG4(x) 00088 #endif // DEBUGLEVEL 4 00089 00090 //---- Debug Level 5 ---- 00091 #if (defined(DEBUGLEVEL_5)) 00092 #define DEBUG_LOG5(x) \ 00093 { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; } 00094 #else 00095 #define DEBUG_LOG5(x) 00096 #endif // DEBUGLEVEL 5 00097 00098 /* }}} */ 00099 00101 #define SHOWX(X) \ 00102 { std::cout << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << (#X) << ":\n" << X << std::endl; } 00103 00105 #define SHOW(X) \ 00106 { std::cout << (#X) << ":\n" << X << std::endl; } 00107 00108 00110 #define ERROR_LOG(x) DEBUG_LOG0("ERROR: " << x); 00111 00113 #define TODO_LOG(x) DEBUG_LOG0("TODO: " << x); 00114 00116 #define WARNING_LOG(x) DEBUG_LOG1("WARNING: " << x); 00117 00119 #define INFO_LOG(x) DEBUG_LOG1("INFO: " << x); 00120 00122 #define FUNCTION_LOG(x) DEBUG_LOG2("FUNCTION: " << x); 00123 00125 #define SECTION_LOG(x) DEBUG_LOG3("SECTION: " << x); 00126 00128 #define SUBSECTION_LOG(x) DEBUG_LOG4("SUBSECTION: " << x); 00129 00131 #define LOOP_LOG(x) DEBUG_LOG5("LOOP: " << x); 00132 00134 #define ICLASSERT(X) \ 00135 if(!(X)){ \ 00136 ERROR_LOG("ICL ASSERTION ERROR:" << #X) \ 00137 } 00138 00140 #define ICLASSERT_RETURN(X) \ 00141 if(!(X)){ \ 00142 ERROR_LOG("ICL ASSERTION ERROR:" << #X << "(returning!)"); \ 00143 return; \ 00144 } 00145 00147 #define ICLASSERT_RETURN_VAL(X,VALUE) \ 00148 if(!(X)){ \ 00149 ERROR_LOG("ICL ASSERTION ERROR:" << #X << "(returning!)"); \ 00150 return VALUE; \ 00151 } 00152 00154 #define ICLASSERT_THROW(X,OBJ) \ 00155 if(!(X)){ \ 00156 throw OBJ; \ 00157 } 00158 00159 #if __GNUC__ >= 3 00160 #define ICL_UNLIKELY(expr) __builtin_expect(expr, 0) 00161 #else 00162 #define ICL_UNLIKELY(expr) expr 00163 #endif 00164 00165 #define ICL_INSTANTIATE_ALL_INT_DEPTHS \ 00166 ICL_INSTANTIATE_DEPTH(8u) \ 00167 ICL_INSTANTIATE_DEPTH(16s) \ 00168 ICL_INSTANTIATE_DEPTH(32s) 00169 00170 #define ICL_INSTANTIATE_ALL_FLOAT_DEPTHS \ 00171 ICL_INSTANTIATE_DEPTH(32f) \ 00172 ICL_INSTANTIATE_DEPTH(64f) 00173 00174 #define ICL_INSTANTIATE_ALL_DEPTHS \ 00175 ICL_INSTANTIATE_ALL_INT_DEPTHS \ 00176 ICL_INSTANTIATE_ALL_FLOAT_DEPTHS 00177 00178 00181 // ?? why not as macro? -> no type problems 00182 #ifdef ICL_SYSTEM_LINUX 00183 #define iclMin(A,B) std::min(A,B) 00184 #define iclMax(A,B) std::max(A,B) 00185 #else 00186 #define iclMin(A,B) ((A)<(B)?(A):(B)) 00187 #define iclMax(A,B) ((A)>(B)?(A):(B)) 00188 #endif 00189 00190 #ifndef iclMin 00191 #define iclMin(A,B) ((A)<(B)?(A):(B)) 00192 #endif 00193 #ifndef iclMax 00194 #define iclMax(A,B) ((A)>(B)?(A):(B)) 00195 #endif 00196 00197 00199 template<class T> static inline T sqr(const T &x) { return x*x; } 00200 00202 template<class T,unsigned int N> static inline T power(const T&x){ 00203 switch(N){ 00204 case 0: return 1; 00205 case 1: return x; 00206 case 2: return sqr(x); 00207 case 3: return sqr(x)*x; 00208 case 4: return sqr(sqr(x)); 00209 case 5: return sqr(sqr(x))*x; 00210 default: 00211 return ::pow(x,N); 00212 } 00213 } 00214 } // namespace utils 00215 } 00216 00217 00218 // template <typename T,t> 00219 // inline const T &iclMin(const T &a, const T &b) {if (a < b) return a; return b;} 00220 // template <typename T> 00221 // inline const T &iclMax(const T &a, const T &b) {if (a > b) return a; return b;} 00222 00223 // this will not work because of the unknown return type 00224 // template <typename T,typename U> 00225 // inline const T &iclMin(const T &a, const U &b) {if (a < b) return a; return b;} 00226 // template <typename T> 00227 // inline const T &iclMax(const T &a, const T &b) {if (a > b) return a; return b;} 00228 00229 #define ICL_DELETE(X) if((X)){ delete (X); (X)=0; } 00230 00231 #define ICL_DELETE_ARRAY(X) if((X)){ delete [] (X); (X)=0; } 00232 00233 #define ICL_DEPRECATED __attribute__((deprecated))