- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

ufo_debug.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/ufo_debug.hpp 00008 begin : Sun Feb 23 2003 00009 $Id: ufo_debug.hpp,v 1.12 2005/09/30 12:57:33 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 #ifndef UFO_DEBUG_HPP 00029 #define UFO_DEBUG_HPP 00030 00031 00032 // 00033 // debug and error functions 00034 // 00035 00036 // 00037 // macro magic 00038 // 00039 00040 #ifndef UFO_ASSERT 00041 #ifdef UFO_CHECK_ASSERT 00042 #define UFO_ASSERT(x) ((x) ? (void)0 : uWarning() << "ASSERT: " << #x << " in " << UFO_LINE_INFO; 00043 #else 00044 #define UFO_ASSERT(x) 00045 #endif // UFO_CHECK_ASSERT 00046 #endif // UFO_ASSERT 00047 00048 00049 // line info 00050 #define UFO_LINE_INFO "[" << __FILE__ << ":" << __LINE__ << "] " 00051 00052 00053 #include <iostream> 00054 #include <vector> 00055 00056 #include "usharedptr.hpp" 00057 00058 namespace ufo { 00059 00066 class UDebugStream { 00067 public: // typedefs 00068 //typedef std::ostream::__ios_type ios_type__; 00069 typedef std::ostream ostream_type; 00070 USharedPtr<ostream_type> m_stream; 00071 public: 00072 UDebugStream(std::streambuf * buf) : m_stream(new ostream_type(buf)) {} 00073 00074 #ifdef UFO_DEBUG 00075 UDebugStream & 00076 operator<<(ostream_type & (*pf)(ostream_type &)) { 00077 *m_stream << (pf); 00078 return *this; 00079 } 00080 #else 00081 UDebugStream & 00082 operator<<(ostream_type & (* /* pf */)(ostream_type &)) { 00083 return *this; 00084 } 00085 #endif 00086 00087 template<typename T> 00088 UDebugStream & 00089 operator<<(const T & t) { 00090 #ifdef UFO_DEBUG 00091 *m_stream << (t); 00092 #endif 00093 return *this; 00094 } 00095 00102 UFO_EXPORT UDebugStream & 00103 printf(const char *format, ...); 00104 }; 00105 00110 class UPrintStream { 00111 public: // typedefs 00112 typedef std::ostream ostream_type; 00113 USharedPtr<ostream_type> m_stream; 00114 public: 00115 UPrintStream(std::streambuf * buf) : m_stream(new ostream_type(buf)) {} 00116 00117 UPrintStream & 00118 operator<<(ostream_type & (*pf)(ostream_type &)) { 00119 *m_stream << (pf); 00120 return *this; 00121 } 00122 00123 template<typename T> 00124 UPrintStream & 00125 operator<<(const T & t) { 00126 *m_stream << (t); 00127 return *this; 00128 } 00129 00130 UFO_EXPORT UPrintStream & 00131 printf(const char *format, ...); 00132 }; 00133 00134 // 00135 // returns debug streams 00136 // 00137 00139 extern UFO_EXPORT UDebugStream uDebug(); 00140 00141 // 00142 // debug streams which appear also in production code 00143 // 00144 extern UFO_EXPORT UPrintStream uError(); 00145 extern UFO_EXPORT UPrintStream uWarning(); 00146 extern UFO_EXPORT UPrintStream uFatal(); 00147 00148 //extern UFO_EXPORT std::vector<std::string> uStackTrace(int maxLevels); 00149 //extern UFO_EXPORT std::vector<std::string> uStackTrace(); 00150 00151 // backwards compatibility 00152 extern UFO_EXPORT std::string uBacktrace(int levels); 00153 extern UFO_EXPORT std::string uBacktrace(); 00154 00155 // 00156 // FIXME ! 00157 // 00158 00162 extern UFO_EXPORT void initUFODebug(std::streambuf * debug, std::streambuf * warning, 00163 std::streambuf * error, std::streambuf * fatal); 00164 00165 00166 } // namespace ufo 00167 00168 00169 #endif // UFO_DEBUG_HPP

The libUFO Project - written by Johannes Schmidt