Moved some console commands' implementations nearer to target classes
[supertux.git] / src / msg.hpp
1 //  $Id: debug.cpp 2650 2005-06-28 12:42:08Z sommer $
2 // 
3 //  SuperTux Debug Helper Functions
4 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program 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
14 //  GNU General Public License for more details.
15 // 
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 //  02111-1307, USA.
20
21 #ifndef __SUPERTUX_MSG_H__
22 #define __SUPERTUX_MSG_H__
23
24 #include <iostream>
25 #include <stdio.h>
26
27 #include "console.hpp"
28
29 #ifdef DEBUG
30
31 namespace {
32
33 inline std::ostream& msg_debug_f(const char* file, int line) {
34   Console::output << "[DEBUG] " << file << " l." << line << ": ";
35   return Console::output;
36 }
37
38 inline std::ostream& msg_info_f(const char* file, int line) {
39   Console::output << "[INFO] " << file << " l." << line << ": ";
40   return Console::output;
41 }
42
43 inline std::ostream& msg_warning_f(const char* file, int line) {
44   Console::output << "[WARNING] " << file << " l." << line << ": ";
45   return Console::output;
46 }
47
48 inline std::ostream& msg_fatal_f(const char* file, int line) {
49   Console::output << "[FATAL] " << file << " l." << line << ": ";
50   return Console::output;
51 }
52
53 }
54
55 #define msg_debug msg_debug_f(__FILE__, __LINE__)
56 #define msg_info msg_info_f(__FILE__, __LINE__)
57 #define msg_warning msg_warning_f(__FILE__, __LINE__)
58 #define msg_fatal msg_fatal_f(__FILE__, __LINE__)
59
60 #else
61
62 namespace {
63
64 inline std::ostream& msg_warning_f() {
65   Console::output << "Warning: ";
66   return Console::output;
67 }
68
69 inline std::ostream& msg_fatal_f() {
70   Console::output << "Fatal: ";
71   return Console::output;
72 }
73
74 }
75
76 #define msg_debug if (0) std::cerr
77 #define msg_info Console::output
78 #define msg_warning msg_warning_f()
79 #define msg_fatal msg_fatal_f()
80
81 #endif
82
83 #endif
84