Introduced FileSystem and Out classes
[openstranded.git] / src / output.hh
blobe391ff5f1f7bc013bf64a98246265a30940281f0
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 and/or log
28 * files.
30 class Out
32 private:
33 class Printer
35 private:
36 void (*printer)(std::string);
38 public:
39 Printer(void (*printer)(std::string));
44 // Texts
47 Printer&
48 operator<<(std::string msg);
50 Printer&
51 operator<<(const char *msg);
53 Printer&
54 operator<<(char msg);
59 // Signed integers
62 Printer&
63 operator<<(int msg);
65 Printer&
66 operator<<(short msg);
68 Printer&
69 operator<<(long msg);
71 Printer&
72 operator<<(long long msg);
77 // Unsigned integers
80 Printer&
81 operator<<(unsigned int msg);
83 Printer&
84 operator<<(unsigned short msg);
86 Printer&
87 operator<<(unsigned long msg);
89 Printer&
90 operator<<(unsigned long long msg);
95 // Decimals
98 Printer&
99 operator<<(float msg);
101 Printer&
102 operator<<(double msg);
107 // Format strings
111 vprintf(const char *format, va_list args);
114 printf(const char *format, ...);
117 public:
119 * The console mode flags.
120 * These flags determine which messages are displayed on the
121 * console and which aren't.
123 static int consoleFlags;
126 * The logging mode flags.
127 * These flags determine which messages are written to log files
128 * and which aren't
130 static int loggingFlags;
133 * These flags indicate whether a printer has not finished its
134 * line.
136 static int isWriting;
139 * Print fatal error message to stderr.
140 * @param The message
142 static void
143 fatalPrinter(std::string msg);
146 * Print common error message to stderr.
147 * @param The message
149 static void
150 errorPrinter(std::string msg);
153 * Print warning message to stderr.
154 * @param The message
156 static void
157 warningPrinter(std::string msg);
160 * Print a common message to stdout.
161 * Note that these messages can't be shut off.
162 * @param The message
164 static void
165 msgPrinter(std::string msg);
168 * Print a debug message.
169 * @param The message
171 static void
172 debugPrinter(std::string msg);
176 * The fatal stream.
178 static Printer fatal;
181 * The error console stream.
183 static Printer error;
186 * The warning stream.
188 static Printer warning;
191 * The msg stream.
193 static Printer msg;
196 * The debug stream.
198 static Printer debug;
201 * The log file.
203 static FILE *logFile;
205 static const int NONE = 0;
206 static const int FATAL = 1;
207 static const int ERROR = 2;
208 static const int WARNING = 4;
209 static const int DEBUG = 8;
210 static const int MSG = 16; // only used internally
212 static const char endl = '\n';
214 Out();
217 * Set the log file name and open the file.
218 * This needs to be called at least once to allow log file
219 * generation.
220 * @param fileName The new log file name
222 static void
223 setLogFile(std::string fileName);
227 * Get console mode flags.
228 * These flags indicate which messages should be written to the
229 * console (cout, cerr).
230 * @return The current console mode flags.
232 static int
233 getConsoleFlags();
236 * Set console mode flags.
237 * These flags indicate which messages should be written to the
238 * console (cout, cerr).
239 * @param newflags The new console mode flags.
241 static void
242 setConsoleFlags(int newflags);
245 * Get logging mode flags.
246 * These flags indicate which messages should be written to
247 * log files.
248 * @return The current logging mode flags.
250 static int
251 getLoggingFlags();
254 * Set logging mode flags.
255 * These flags indicate which messages should be written to
256 * log files.
257 * @param newflags The new logging mode flags.
259 static void
260 setLoggingFlags(int newflags);