libopenraw
|
00001 /* 00002 * libopenraw - trace.h 00003 * 00004 * Copyright (C) 2006-2007 Hubert Figuiere 00005 * 00006 * This library is free software: you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * as published by the Free Software Foundation, either version 3 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library. If not, see 00018 * <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 00022 #ifndef _OPENRAWPP_DEBUG_H_ 00023 #define _OPENRAWPP_DEBUG_H_ 00024 00025 #include <string> 00026 #include <vector> 00027 #include <iostream> 00028 #include <algorithm> 00029 #include <boost/bind.hpp> 00030 00031 #include <libopenraw/debug.h> 00032 00033 namespace Debug { 00034 00035 00037 class Trace 00038 { 00039 public: 00040 00041 Trace(debug_level level) 00042 : m_level(level) 00043 { 00044 } 00045 Trace & operator<<(int i); 00046 Trace & operator<<(const char * s); 00047 Trace & operator<<(void *); 00048 Trace & operator<<(const std::string & s); 00049 00050 template <class T> 00051 Trace & operator<<(const std::vector<T> & v); 00052 00053 static void setDebugLevel(debug_level lvl); 00054 private: 00055 static void print(int i); 00056 static int debugLevel; // global debug level 00057 int m_level; 00058 }; 00059 00060 00061 template <class T> 00062 Trace & Trace::operator<<(const std::vector<T> & v) 00063 { 00064 if (m_level <= debugLevel) { 00065 std::for_each(v.begin(), v.end(), boost::bind(&print, _1)); 00066 } 00067 return *this; 00068 } 00069 00070 00071 } 00072 00073 #endif