Messaging subsystem rewrite, step I
[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 inline std::ostream& msg_debug_f(const char* file, int line) {
32   Console::output << "[DEBUG] " << file << " l." << line << ": ";
33   return Console::output;
34 }
35
36 inline std::ostream& msg_info_f(const char* file, int line) {
37   Console::output << "[INFO] " << file << " l." << line << ": ";
38   return Console::output;
39 }
40
41 inline std::ostream& msg_warning_f(const char* file, int line) {
42   Console::output << "[WARNING] " << file << " l." << line << ": ";
43   return Console::output;
44 }
45
46 inline std::ostream& msg_fatal_f(const char* file, int line) {
47   Console::output << "[FATAL] " << file << " l." << line << ": ";
48   return Console::output;
49 }
50
51 #define msg_debug msg_debug_f(__FILE__, __LINE__)
52 #define msg_info msg_info_f(__FILE__, __LINE__)
53 #define msg_warning msg_warning_f(__FILE__, __LINE__)
54 #define msg_fatal msg_fatal_f(__FILE__, __LINE__)
55
56 #else
57
58 inline std::ostream& msg_debug_f(const char* file, int line) {
59   return Console::output;
60 }
61
62 inline std::ostream& msg_info_f(const char* file, int line) {
63   return Console::output;
64 }
65
66 inline std::ostream& msg_warning_f(const char* file, int line) {
67   Console::output << "Warning: ";
68   return Console::output;
69 }
70
71 inline std::ostream& msg_fatal_f(const char* file, int line) {
72   Console::output << "Fatal: ";
73   return Console::output;
74 }
75
76 #define msg_debug if (0) msg_debug_f(__FILE__, __LINE__)
77 #define msg_info msg_info_f(__FILE__, __LINE__)
78 #define msg_warning msg_warning_f(__FILE__, __LINE__)
79 #define msg_fatal msg_fatal_f(__FILE__, __LINE__)
80
81 #endif
82
83 #endif
84