console.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Kenneth Gangstoe
28 ** Mark Page
29 */
30
31
32 #pragma once
33
34 // 'kbhit' was declared deprecated
35 #ifdef WIN32
36 #pragma warning(disable: 4996)
37 #endif
38
39 #include "string_format.h"
40 #include "string_help.h"
41 #ifdef WIN32
42 #include <conio.h>
43 #else
44 #include <unistd.h>
45 #endif
46
47 namespace clan
48 {
51
53 class Console
54 {
57
58 public:
60 static void write(const std::string &text);
61
62 template <class Arg1>
63
68 static void write(const std::string &format, Arg1 arg1)
69 {
70 StringFormat f(format);
71 f.set_arg(1, arg1);
72 write(f.get_result());
73 }
74
75 template <class Arg1, class Arg2>
76
82 static void write(const std::string &format, Arg1 arg1, Arg2 arg2)
83 {
84 StringFormat f(format);
85 f.set_arg(1, arg1);
86 f.set_arg(2, arg2);
87 write(f.get_result());
88 }
89
90 template <class Arg1, class Arg2, class Arg3>
91
98 static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
99 {
100 StringFormat f(format);
101 f.set_arg(1, arg1);
102 f.set_arg(2, arg2);
103 f.set_arg(3, arg3);
104 write(f.get_result());
105 }
106
107 template <class Arg1, class Arg2, class Arg3, class Arg4>
108
116 static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
117 {
118 StringFormat f(format);
119 f.set_arg(1, arg1);
120 f.set_arg(2, arg2);
121 f.set_arg(3, arg3);
122 f.set_arg(4, arg4);
123 write(f.get_result());
124 }
125
126 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
127
136 static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
137 {
138 StringFormat f(format);
139 f.set_arg(1, arg1);
140 f.set_arg(2, arg2);
141 f.set_arg(3, arg3);
142 f.set_arg(4, arg4);
143 f.set_arg(arg5);
144 write(f.get_result());
145 }
146
147 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
148
158 static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
159 {
160 StringFormat f(format);
161 f.set_arg(1, arg1);
162 f.set_arg(2, arg2);
163 f.set_arg(3, arg3);
164 f.set_arg(4, arg4);
165 f.set_arg(arg5);
166 f.set_arg(arg6);
167 write(f.get_result());
168 }
169
170 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
171
182 static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
183 {
184 StringFormat f(format);
185 f.set_arg(1, arg1);
186 f.set_arg(2, arg2);
187 f.set_arg(3, arg3);
188 f.set_arg(4, arg4);
189 f.set_arg(arg5);
190 f.set_arg(arg6);
191 f.set_arg(arg7);
192 write(f.get_result());
193 }
194
196 static void write_line(const std::string &text)
197 {
198 write(text);
199 #ifdef WIN32
200 write("\r\n");
201 #else
202 write("\n");
203 #endif
204 }
205
206 template <class Arg1>
207
212 static void write_line(const std::string &format, Arg1 arg1)
213 {
214 StringFormat f(format);
215 f.set_arg(1, arg1);
216 write_line(f.get_result());
217 }
218
219 template <class Arg1, class Arg2>
220
226 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2)
227 {
228 StringFormat f(format);
229 f.set_arg(1, arg1);
230 f.set_arg(2, arg2);
231 write_line(f.get_result());
232 }
233
234 template <class Arg1, class Arg2, class Arg3>
235
242 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
243 {
244 StringFormat f(format);
245 f.set_arg(1, arg1);
246 f.set_arg(2, arg2);
247 f.set_arg(3, arg3);
248 write_line(f.get_result());
249 }
250
251 template <class Arg1, class Arg2, class Arg3, class Arg4>
252
260 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
261 {
262 StringFormat f(format);
263 f.set_arg(1, arg1);
264 f.set_arg(2, arg2);
265 f.set_arg(3, arg3);
266 f.set_arg(4, arg4);
267 write_line(f.get_result());
268 }
269
270 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
271
280 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
281 {
282 StringFormat f(format);
283 f.set_arg(1, arg1);
284 f.set_arg(2, arg2);
285 f.set_arg(3, arg3);
286 f.set_arg(4, arg4);
287 f.set_arg(5, arg5);
288 write_line(f.get_result());
289 }
290
291 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
292
302 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
303 {
304 StringFormat f(format);
305 f.set_arg(1, arg1);
306 f.set_arg(2, arg2);
307 f.set_arg(3, arg3);
308 f.set_arg(4, arg4);
309 f.set_arg(5, arg5);
310 f.set_arg(6, arg6);
311 write_line(f.get_result());
312 }
313
314 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
315
326 static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
327 {
328 StringFormat f(format);
329 f.set_arg(1, arg1);
330 f.set_arg(2, arg2);
331 f.set_arg(3, arg3);
332 f.set_arg(4, arg4);
333 f.set_arg(5, arg5);
334 f.set_arg(6, arg6);
335 f.set_arg(7, arg7);
336 write_line(f.get_result());
337 }
338
342 static void wait_for_key();
343
345 };
346
347 }
348
clan
Definition: clanapp.h:35
clan::Console::write
static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
Write.
Definition: console.h:136
clan::Console::write_line
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2)
Write line.
Definition: console.h:226
clan::Console::write_line
static void write_line(const std::string &format, Arg1 arg1)
Write line.
Definition: console.h:212
clan::Console::write
static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
Write.
Definition: console.h:182
clan::Console::write
static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
Write.
Definition: console.h:116
clan::StringFormat::set_arg
void set_arg(int index, const std::string &text)
Sets an argument (string version)
clan::Console::write_line
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
Write line.
Definition: console.h:280
clan::StyleTokenType::string
@ keyword
clan::Console::write_line
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
Write line.
Definition: console.h:302
clan::Console::write
static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
Write.
Definition: console.h:98
clan::Console::write_line
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
Write line.
Definition: console.h:242
clan::Key::f
clan::Console::write_line
static void write_line(const std::string &text)
Writes text to the console window and then advances to a new line.
Definition: console.h:196
clan::Console::write
static void write(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
Write.
Definition: console.h:158
clan::Console::wait_for_key
static void wait_for_key()
Block until a key is pressed in the console window.
clan::Console::write
static void write(const std::string &format, Arg1 arg1, Arg2 arg2)
Write.
Definition: console.h:82
clan::Console
Console access helper class.
Definition: console.h:53
clan::Console::write
static void write(const std::string &text)
Writes text to the console window.
clan::Console::write_line
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
Write line.
Definition: console.h:260
clan::Console::write
static void write(const std::string &format, Arg1 arg1)
Write.
Definition: console.h:68
clan::Console::write_line
static void write_line(const std::string &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
Write line.
Definition: console.h:326
clan::StringFormat
String formatting class.
Definition: string_format.h:70
clan::StringFormat::get_result
const std::string & get_result() const
Retrieves the formatted string with all argument replacements.