libopenraw
trace.h
1 /*
2  * libopenraw - trace.h
3  *
4  * Copyright (C) 2006-2007 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #ifndef _OPENRAWPP_DEBUG_H_
23 #define _OPENRAWPP_DEBUG_H_
24 
25 #include <string>
26 #include <vector>
27 #include <iostream>
28 #include <algorithm>
29 #include <boost/bind.hpp>
30 
31 #include <libopenraw/debug.h>
32 
33 namespace Debug {
34 
35 
37  class Trace
38  {
39  public:
40 
41  Trace(debug_level level)
42  : m_level(level)
43  {
44  }
45  Trace & operator<<(int i);
46  Trace & operator<<(const char * s);
47  Trace & operator<<(void *);
48  Trace & operator<<(const std::string & s);
49 
50  template <class T>
51  Trace & operator<<(const std::vector<T> & v);
52 
53  static void setDebugLevel(debug_level lvl);
54  private:
55  static void print(int i);
56  static int debugLevel; // global debug level
57  int m_level;
58  };
59 
60 
61  template <class T>
62  Trace & Trace::operator<<(const std::vector<T> & v)
63  {
64  if (m_level <= debugLevel) {
65  std::for_each(v.begin(), v.end(), boost::bind(&print, _1));
66  }
67  return *this;
68  }
69 
70 
71 }
72 
73 #endif
Definition: trace.cpp:28