Image Component Library (ICL)
Macros.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLUtils/src/ICLUtils/Macros.h **
10 ** Module : ICLUtils **
11 ** Authors: Christof Elbrechter, Michael Goetting, Robert Haschke **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/BasicTypes.h>
35 #include <iostream>
36 #include <stdlib.h>
37 #include <cmath>
38 
39 namespace icl {
40  namespace utils{
41 
42  /* {{{ Debug Level */
43 
44  //---- The following DebugMessage can be activated by defining DEBUGLEVEL_{0..5}
45 
46  // do not comment out debug level 0
47  #define DEBUGLEVEL_1
48 
49  //---- Debug Level 0 ----
50  #if (defined(DEBUGLEVEL_0) ||defined(DEBUGLEVEL_1) || defined(DEBUGLEVEL_2) || defined (DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5))
51  #define DEBUG_LOG0(x) \
52  { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; }
53  #else
54  #define DEBUG_LOG0(x)
55  #endif // DEBUGLEVEL 0
56 
57  #define DEBUG_LOG(x) DEBUG_LOG0(x)
58 
59  //---- Debug Level 1 ----
60  #if (defined(DEBUGLEVEL_1) || defined(DEBUGLEVEL_2) || defined (DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5))
61  #define DEBUG_LOG1(x) \
62  { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; }
63  #else
64  #define DEBUG_LOG1(x)
65  #endif // DEBUGLEVEL 1
66 
67  //---- Debug Level 2 ----
68  #if (defined(DEBUGLEVEL_2) || defined(DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5))
69  #define DEBUG_LOG2(x) \
70  { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; }
71  #else
72  #define DEBUG_LOG2(x)
73  #endif // DEBUGLEVEL 2
74 
75  //---- Debug Level 3 ----
76  #if (defined(DEBUGLEVEL_3) || defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5))
77  #define DEBUG_LOG3(x) \
78  { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; }
79  #else
80  #define DEBUG_LOG3(x)
81  #endif // DEBUGLEVEL 3
82 
83  //---- Debug Level 4 ----
84  #if (defined(DEBUGLEVEL_4) || defined(DEBUGLEVEL_5))
85  #define DEBUG_LOG4(x) \
86  { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; }
87  #else
88  #define DEBUG_LOG4(x)
89  #endif // DEBUGLEVEL 4
90 
91  //---- Debug Level 5 ----
92  #if (defined(DEBUGLEVEL_5))
93  #define DEBUG_LOG5(x) \
94  { std::cerr << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << x << std::endl; }
95  #else
96  #define DEBUG_LOG5(x)
97  #endif // DEBUGLEVEL 5
98 
99  /* }}} */
100 
102  #define SHOWX(X) \
103  { std::cout << "[" __FILE__ ":" << __FUNCTION__ << ",line: " << __LINE__ << "] " << (#X) << ":\n" << X << std::endl; }
104 
106  #define SHOW(X) \
107  { std::cout << (#X) << ":\n" << X << std::endl; }
108 
109 
111  #define ERROR_LOG(x) DEBUG_LOG0("ERROR: " << x);
112 
114  #define TODO_LOG(x) DEBUG_LOG0("TODO: " << x);
115 
117  #define WARNING_LOG(x) DEBUG_LOG1("WARNING: " << x);
118 
120  #define INFO_LOG(x) DEBUG_LOG1("INFO: " << x);
121 
123  #define FUNCTION_LOG(x) DEBUG_LOG2("FUNCTION: " << x);
124 
126  #define SECTION_LOG(x) DEBUG_LOG3("SECTION: " << x);
127 
129  #define SUBSECTION_LOG(x) DEBUG_LOG4("SUBSECTION: " << x);
130 
132  #define LOOP_LOG(x) DEBUG_LOG5("LOOP: " << x);
133 
135  #define ICLASSERT(X) \
136  if(!(X)){ \
137  ERROR_LOG("ICL ASSERTION ERROR:" << #X) \
138  }
139 
141  #define ICLASSERT_RETURN(X) \
142  if(!(X)){ \
143  ERROR_LOG("ICL ASSERTION ERROR:" << #X << "(returning!)"); \
144  return; \
145  }
146 
148  #define ICLASSERT_RETURN_VAL(X,VALUE) \
149  if(!(X)){ \
150  ERROR_LOG("ICL ASSERTION ERROR:" << #X << "(returning!)"); \
151  return VALUE; \
152  }
153 
155  #define ICLASSERT_THROW(X,OBJ) \
156  if(!(X)){ \
157  throw OBJ; \
158  }
159 
160  #if (defined __GNUC__ && __GNUC__ >= 3)
161  #define ICL_UNLIKELY(expr) __builtin_expect(expr, 0)
162  #else
163  #define ICL_UNLIKELY(expr) expr
164  #endif
165 
166  #define ICL_INSTANTIATE_ALL_INT_DEPTHS \
167  ICL_INSTANTIATE_DEPTH(8u) \
168  ICL_INSTANTIATE_DEPTH(16s) \
169  ICL_INSTANTIATE_DEPTH(32s)
170 
171  #define ICL_INSTANTIATE_ALL_FLOAT_DEPTHS \
172  ICL_INSTANTIATE_DEPTH(32f) \
173  ICL_INSTANTIATE_DEPTH(64f)
174 
175  #define ICL_INSTANTIATE_ALL_DEPTHS \
176  ICL_INSTANTIATE_ALL_INT_DEPTHS \
177  ICL_INSTANTIATE_ALL_FLOAT_DEPTHS
178 
179 
180  #define ICL_INSTANTIATE_ALL_SECOND_DEPTHS(D) \
181  ICL_INSTANTIATE_DEPTH(D, 8u) \
182  ICL_INSTANTIATE_DEPTH(D, 16s) \
183  ICL_INSTANTIATE_DEPTH(D, 32s) \
184  ICL_INSTANTIATE_DEPTH(D, 32f) \
185  ICL_INSTANTIATE_DEPTH(D, 64f)
186 
187  #define ICL_INSTANTIATE_ALL_DEPTHS_2 \
188  ICL_INSTANTIATE_ALL_SECOND_DEPTHS(8u) \
189  ICL_INSTANTIATE_ALL_SECOND_DEPTHS(16s) \
190  ICL_INSTANTIATE_ALL_SECOND_DEPTHS(32s) \
191  ICL_INSTANTIATE_ALL_SECOND_DEPTHS(32f) \
192  ICL_INSTANTIATE_ALL_SECOND_DEPTHS(64f)
193 
194 
197  // ?? why not as macro? -> no type problems
198 #ifdef UNIX
199 #define iclMin(A,B) std::min(A,B)
200 #define iclMax(A,B) std::max(A,B)
201 #endif
202 
203 #ifndef iclMin
204 #define iclMin(A,B) ((A)<(B)?(A):(B))
205 #endif
206 #ifndef iclMax
207 #define iclMax(A,B) ((A)>(B)?(A):(B))
208 #endif
209 
210 
212  template<class T> static inline T sqr(const T &x) { return x*x; }
213 
215  template<class T,unsigned int N> static inline T power(const T&x){
216  switch(N){
217  case 0: return 1;
218  case 1: return x;
219  case 2: return sqr(x);
220  case 3: return sqr(x)*x;
221  case 4: return sqr(sqr(x));
222  case 5: return sqr(sqr(x))*x;
223  default:
224  return ::pow(x,(int)N);
225  }
226  }
227  } // namespace utils
228 }
229 
230 
231 // template <typename T,t>
232 // inline const T &iclMin(const T &a, const T &b) {if (a < b) return a; return b;}
233 // template <typename T>
234 // inline const T &iclMax(const T &a, const T &b) {if (a > b) return a; return b;}
235 
236 // this will not work because of the unknown return type
237 // template <typename T,typename U>
238 // inline const T &iclMin(const T &a, const U &b) {if (a < b) return a; return b;}
239 // template <typename T>
240 // inline const T &iclMax(const T &a, const T &b) {if (a > b) return a; return b;}
241 
242 #define ICL_DELETE(X) if((X)){ delete (X); (X)=0; }
243 
244 #define ICL_DELETE_ARRAY(X) if((X)){ delete [] (X); (X)=0; }
245 
246 #ifdef WIN32
247  #define ICL_DEPRECATED __declspec(deprecated)
248 #else
249  #define ICL_DEPRECATED __attribute__((deprecated))
250 #endif
undocument this line if you encounter any issues!
Definition: Any.h:37
static T power(const T &x)
power template
Definition: Macros.h:215
static T sqr(const T &x)
square template (faster than pow(x,2)
Definition: Macros.h:212