Moved Printer class into Out class
[openstranded.git] / src / output.hh
blob766f4712e604474ef0be4c1a3ee165929d74ee59
1 /*
2 * This file includes definitions for OpenStranded output mapping
4 * Copyright (C) 2009 David Kolossa
6 * This file is part of OpenStranded.
8 * OpenStranded is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * OpenStranded is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with OpenStranded. If not, see <http://www.gnu.org/licenses/>.
22 #include <iostream>
23 #include <string>
24 #include <cstdarg>
26 /**
27 * This is the class for OpenStranded output to either cout or cerr.
29 class Out
31 private:
32 class Printer
34 private:
35 void (*printer)(std::string);
37 public:
38 Printer(void (*printer)(std::string));
43 // Texts
46 Printer&
47 operator<<(std::string msg);
49 Printer&
50 operator<<(const char *msg);
52 Printer&
53 operator<<(char msg);
58 // Signed integers
61 Printer&
62 operator<<(int msg);
64 Printer&
65 operator<<(short msg);
67 Printer&
68 operator<<(long msg);
70 Printer&
71 operator<<(long long msg);
76 // Unsigned integers
79 Printer&
80 operator<<(unsigned int msg);
82 Printer&
83 operator<<(unsigned short msg);
85 Printer&
86 operator<<(unsigned long msg);
88 Printer&
89 operator<<(unsigned long long msg);
94 // Decimals
97 Printer&
98 operator<<(float msg);
100 Printer&
101 operator<<(double msg);
106 // Format strings
110 vprintf(const char *format, va_list args);
113 printf(const char *format, ...);
116 public:
118 * The mode flags.
119 * These flags determine which messages are displayed and which
120 * not.
122 static int flags;
125 * These flags indicate whether a printer has not finished its
126 * line.
128 static int isWriting;
131 * Print fatal error message to stderr.
132 * @param The message
134 static void
135 fatalPrinter(std::string msg);
138 * Print common error message to stderr.
139 * @param The message
141 static void
142 errorPrinter(std::string msg);
145 * Print warning message to stderr.
146 * @param The message
148 static void
149 warningPrinter(std::string msg);
152 * Print a common message to stdout.
153 * Note that these messages can't be shut off.
154 * @param The message
156 static void
157 msgPrinter(std::string msg);
160 * Print a debug message.
161 * @param The message
163 static void
164 debugPrinter(std::string msg);
168 * The fatal stream.
170 static Printer fatal;
173 * The error stream.
175 static Printer error;
178 * The warning stream.
180 static Printer warning;
183 * The msg stream.
185 static Printer msg;
188 * The debug stream.
190 static Printer debug;
192 static const int FATAL = 1;
193 static const int ERROR = 2;
194 static const int WARNING = 4;
195 static const int DEBUG = 8;
196 static const int MSG = 16; // only used internally
198 static const char endl = '\n';
200 Out();
203 * Get mode flags.
204 * @return The current mode flags.
206 static int
207 getFlags();
210 * Set mode flags.
211 * @param newflags The new mode flags.
213 static void
214 setFlags(int newflags);