2 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 /** @file console/console.hpp
23 * Headers for Console class
31 /// Really this does DebugOut's job
32 class DebugStream
: public std::streambuf
35 DebugStream(const std::string
& message
);
37 * Set's the actual file, line, and function
38 * @warning Don't use it directly, leave this job for debug, warning and error macros!
39 * @param file The current file (__FILE__)
40 * @param line The current line (__LINE__)
41 * @param func The current function (__PRETTY_FUNCTION__)
43 void SetPos(const std::string
& file
, unsigned short line
, const std::string
& func
)
44 { sync(); this->file
= file
; this->line
= line
; this->func
= func
; };
47 /// If true, it will display the current function true (only in DEBUG mode)
48 static bool show_func
;
51 virtual int overflow(int c
);
58 std::string message
, file
, func
;
60 static unsigned short file_maxw
, line_maxw
, func_maxw
;
65 * DebugOut is a class that displays debug messages on the screen, but
66 * with printing a message; the file and line if compiled in debug mode,
67 * and also the function if it enabled by <tt>--show-func</tt> argument.
69 class DebugOut
: public std::ostream
73 * Creates a new DebugOut.
74 * @param message The message displayed between []
76 DebugOut(const std::string
& message
) : std::ostream(stream
= new DebugStream(message
)) {};
78 /// Poniter to the stream object
82 DebugOut(const DebugOut
&) : stream(NULL
) {};
83 /// Really! Don't copy it. It's just stupid
84 DebugOut
& operator=(const DebugOut
&) { return *this; }
91 /// Class to manage debug levels
92 class DebugLevelManager
95 static void ParseOpts(const std::string
& opts
);
96 static bool IsToPrint(const std::string
& module
, unsigned char level
);
99 static unsigned char global_level
;
100 static std::map
<std::string
, unsigned char> level_map
;
103 extern DebugOut debug_out
, warning_out
, error_out
;
104 #define debug(module, level) if (DebugLevelManager::IsToPrint((module), (level))) debug_out.stream->SetPos(__FILE__ + 7, __LINE__, __PRETTY_FUNCTION__), debug_out
105 #define warning warning_out.stream->SetPos(__FILE__ + 7, __LINE__, __PRETTY_FUNCTION__), warning_out
106 #define error error_out.stream->SetPos(__FILE__ + 7, __LINE__, __PRETTY_FUNCTION__), error_out
110 extern DebugOut warning_out
, error_out
;
111 #define debug if (false) std::cout
112 #define warning warning_out
113 #define error error_out
115 #endif //ifndef DEBUG