Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Macros.h
Go to the documentation of this file.
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.LGPL **
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 <ICLUtils/BasicTypes.h>
00035 #include <iostream>
00036 #include <stdlib.h>
00037 #include <cmath>
00038 
00039 namespace icl {
00040   namespace utils{
00041   
00042   /* {{{ Debug Level */
00043   
00044   //---- The following DebugMessage can be activated by defining DEBUGLEVEL_{0..5}
00045   
00046   // do not comment out debug level 0
00047   #define DEBUGLEVEL_1
00048   
00049   //---- Debug Level 0 ----
00050   #if (defined(DEBUGLEVEL_0) ||defined(DEBUGLEVEL_1) || defined(DEBUGLEVEL_2) || defined (DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5)) 
00051   #define DEBUG_LOG0(x) \
00052   { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; } 
00053   #else
00054   #define DEBUG_LOG0(x)
00055   #endif // DEBUGLEVEL 0
00056   
00057   #define DEBUG_LOG(x) DEBUG_LOG0(x)
00058   
00059   //---- Debug Level 1 ----
00060   #if (defined(DEBUGLEVEL_1) || defined(DEBUGLEVEL_2) || defined (DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5)) 
00061   #define DEBUG_LOG1(x) \
00062   { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; } 
00063   #else
00064   #define DEBUG_LOG1(x)
00065   #endif // DEBUGLEVEL 1
00066   
00067   //---- Debug Level 2 ----
00068   #if (defined(DEBUGLEVEL_2) || defined(DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5))
00069   #define DEBUG_LOG2(x) \
00070   { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; } 
00071   #else
00072   #define DEBUG_LOG2(x)
00073   #endif // DEBUGLEVEL 2
00074   
00075   //---- Debug Level 3 ----
00076   #if (defined(DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5))
00077   #define DEBUG_LOG3(x) \
00078   { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; }
00079   #else
00080   #define DEBUG_LOG3(x)
00081   #endif // DEBUGLEVEL 3
00082   
00083   //---- Debug Level 4 ----
00084   #if (defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5))
00085   #define DEBUG_LOG4(x) \
00086   { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; }
00087   #else
00088   #define DEBUG_LOG4(x)
00089   #endif // DEBUGLEVEL 4
00090   
00091   //---- Debug Level 5 ----
00092   #if (defined(DEBUGLEVEL_5))
00093   #define DEBUG_LOG5(x) \
00094   { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; }
00095   #else
00096   #define DEBUG_LOG5(x)
00097   #endif // DEBUGLEVEL 5
00098   
00099   /* }}} */
00100   
00102   #define SHOWX(X) \
00103     { std::cout << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << (#X) << ":\n" << X << std::endl; }
00104   
00106   #define SHOW(X) \
00107     { std::cout << (#X) << ":\n" << X << std::endl; }
00108   
00109   
00111   #define ERROR_LOG(x) DEBUG_LOG0("ERROR: " << x);
00112   
00114   #define TODO_LOG(x) DEBUG_LOG0("TODO: " << x);
00115   
00117   #define WARNING_LOG(x) DEBUG_LOG1("WARNING: " << x);
00118   
00120   #define INFO_LOG(x) DEBUG_LOG1("INFO: " << x);
00121   
00123   #define FUNCTION_LOG(x) DEBUG_LOG2("FUNCTION: " << x);
00124   
00126   #define SECTION_LOG(x) DEBUG_LOG3("SECTION: " << x);
00127   
00129   #define SUBSECTION_LOG(x) DEBUG_LOG4("SUBSECTION: " << x);
00130   
00132   #define LOOP_LOG(x) DEBUG_LOG5("LOOP: " << x);
00133   
00135   #define ICLASSERT(X)                        \
00136     if(!(X)){                                 \
00137       ERROR_LOG("ICL ASSERTION ERROR:" << #X) \
00138     }
00139   
00141   #define ICLASSERT_RETURN(X)                                    \
00142     if(!(X)){                                                    \
00143       ERROR_LOG("ICL ASSERTION ERROR:" << #X << "(returning!)"); \
00144       return;                                                    \
00145     }
00146   
00148   #define ICLASSERT_RETURN_VAL(X,VALUE)                          \
00149     if(!(X)){                                                    \
00150       ERROR_LOG("ICL ASSERTION ERROR:" << #X << "(returning!)"); \
00151       return VALUE;                                              \
00152     }
00153   
00155   #define ICLASSERT_THROW(X,OBJ)      \
00156     if(!(X)){                         \
00157       throw OBJ;                      \
00158     }
00159   
00160   #if (defined __GNUC__ && __GNUC__ >= 3)
00161   #define ICL_UNLIKELY(expr) __builtin_expect(expr, 0)
00162   #else
00163   #define ICL_UNLIKELY(expr) expr
00164   #endif
00165   
00166   #define ICL_INSTANTIATE_ALL_INT_DEPTHS \
00167     ICL_INSTANTIATE_DEPTH(8u)  \
00168     ICL_INSTANTIATE_DEPTH(16s) \
00169     ICL_INSTANTIATE_DEPTH(32s)
00170   
00171   #define ICL_INSTANTIATE_ALL_FLOAT_DEPTHS \
00172     ICL_INSTANTIATE_DEPTH(32f) \
00173     ICL_INSTANTIATE_DEPTH(64f)
00174   
00175   #define ICL_INSTANTIATE_ALL_DEPTHS \
00176     ICL_INSTANTIATE_ALL_INT_DEPTHS \
00177     ICL_INSTANTIATE_ALL_FLOAT_DEPTHS
00178 
00179 
00180   #define ICL_INSTANTIATE_ALL_SECOND_DEPTHS(D) \
00181     ICL_INSTANTIATE_DEPTH(D, 8u)  \
00182     ICL_INSTANTIATE_DEPTH(D, 16s) \
00183     ICL_INSTANTIATE_DEPTH(D, 32s) \
00184     ICL_INSTANTIATE_DEPTH(D, 32f) \
00185     ICL_INSTANTIATE_DEPTH(D, 64f)
00186 
00187   #define ICL_INSTANTIATE_ALL_DEPTHS_2 \
00188     ICL_INSTANTIATE_ALL_SECOND_DEPTHS(8u) \
00189     ICL_INSTANTIATE_ALL_SECOND_DEPTHS(16s) \
00190     ICL_INSTANTIATE_ALL_SECOND_DEPTHS(32s) \
00191     ICL_INSTANTIATE_ALL_SECOND_DEPTHS(32f) \
00192     ICL_INSTANTIATE_ALL_SECOND_DEPTHS(64f)
00193 
00194 
00197     // ?? why not as macro? -> no type problems
00198 #ifdef UNIX
00199 #define iclMin(A,B) std::min(A,B)
00200 #define iclMax(A,B) std::max(A,B)
00201 #endif
00202     
00203 #ifndef iclMin
00204 #define iclMin(A,B) ((A)<(B)?(A):(B))
00205 #endif
00206 #ifndef iclMax
00207 #define iclMax(A,B) ((A)>(B)?(A):(B))
00208 #endif
00209     
00210     
00212     template<class T> static inline T sqr(const T &x) { return x*x; }
00213     
00215     template<class T,unsigned int N> static inline T power(const T&x){
00216       switch(N){
00217         case 0: return 1;
00218         case 1: return x;
00219         case 2: return sqr(x);
00220         case 3: return sqr(x)*x;
00221         case 4: return sqr(sqr(x));
00222         case 5: return sqr(sqr(x))*x;
00223         default:
00224           return ::pow(x,(int)N);
00225       }
00226     }
00227   } // namespace utils
00228 }
00229 
00230 
00231 // template <typename T,t>
00232 // inline const T &iclMin(const T &a, const T &b) {if (a < b) return a; return b;}
00233 // template <typename T>
00234 // inline const T &iclMax(const T &a, const T &b) {if (a > b) return a; return b;}
00235 
00236 // this will not work because of the unknown return type
00237 // template <typename T,typename U>
00238 // inline const T &iclMin(const T &a, const U &b) {if (a < b) return a; return b;}
00239 // template <typename T>
00240 // inline const T &iclMax(const T &a, const T &b) {if (a > b) return a; return b;}
00241 
00242 #define ICL_DELETE(X) if((X)){ delete (X); (X)=0; }
00243 
00244 #define ICL_DELETE_ARRAY(X) if((X)){ delete [] (X); (X)=0; }
00245 
00246 #ifdef WIN32
00247   #define ICL_DEPRECATED __declspec(deprecated)
00248 #else
00249   #define ICL_DEPRECATED __attribute__((deprecated))
00250 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines