00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00032
00033 #pragma once
00034
00035
00036 #ifdef WIN32
00037 #pragma warning(disable: 4996)
00038 #endif
00039
00040 #include "../api_core.h"
00041 #include "string_format.h"
00042 #include "string_help.h"
00043 #ifdef WIN32
00044 #include <conio.h>
00045 #else
00046 #include <unistd.h>
00047 #endif
00048
00052 class CL_Console
00053 {
00056
00057 public:
00059 static void write(const CL_StringRef &text)
00060 {
00061 #ifdef WIN32
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 DWORD written = 0;
00073 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), text.data(), text.length(), &written, 0);
00074 #else
00075 ::write(1, text.data(), text.length());
00076 #endif
00077 }
00078
00079 template <class Arg1>
00080
00085 static void write(const CL_StringRef &format, Arg1 arg1)
00086 {
00087 CL_TempStringFormat f(format);
00088 f.set_arg(1, arg1);
00089 write(f.get_result());
00090 }
00091
00092 template <class Arg1, class Arg2>
00093
00099 static void write(const CL_StringRef &format, Arg1 arg1, Arg2 arg2)
00100 {
00101 CL_TempStringFormat f(format);
00102 f.set_arg(1, arg1);
00103 f.set_arg(2, arg2);
00104 write(f.get_result());
00105 }
00106
00107 template <class Arg1, class Arg2, class Arg3>
00108
00115 static void write(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
00116 {
00117 CL_TempStringFormat f(format);
00118 f.set_arg(1, arg1);
00119 f.set_arg(2, arg2);
00120 f.set_arg(3, arg3);
00121 write(f.get_result());
00122 }
00123
00124 template <class Arg1, class Arg2, class Arg3, class Arg4>
00125
00133 static void write(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
00134 {
00135 CL_TempStringFormat f(format);
00136 f.set_arg(1, arg1);
00137 f.set_arg(2, arg2);
00138 f.set_arg(3, arg3);
00139 f.set_arg(4, arg4);
00140 write(f.get_result());
00141 }
00142
00143 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
00144
00153 static void write(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
00154 {
00155 CL_TempStringFormat f(format);
00156 f.set_arg(1, arg1);
00157 f.set_arg(2, arg2);
00158 f.set_arg(3, arg3);
00159 f.set_arg(4, arg4);
00160 f.set_arg(arg5);
00161 write(f.get_result());
00162 }
00163
00164 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
00165
00175 static void write(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
00176 {
00177 CL_TempStringFormat f(format);
00178 f.set_arg(1, arg1);
00179 f.set_arg(2, arg2);
00180 f.set_arg(3, arg3);
00181 f.set_arg(4, arg4);
00182 f.set_arg(arg5);
00183 f.set_arg(arg6);
00184 write(f.get_result());
00185 }
00186
00187 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
00188
00199 static void write(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
00200 {
00201 CL_TempStringFormat f(format);
00202 f.set_arg(1, arg1);
00203 f.set_arg(2, arg2);
00204 f.set_arg(3, arg3);
00205 f.set_arg(4, arg4);
00206 f.set_arg(arg5);
00207 f.set_arg(arg6);
00208 f.set_arg(arg7);
00209 write(f.get_result());
00210 }
00211
00213 static void write_line(const CL_StringRef &text)
00214 {
00215 write(text);
00216 #ifdef WIN32
00217 write(cl_text("\r\n"));
00218 #else
00219 write(cl_text("\n"));
00220 #endif
00221 }
00222
00223 template <class Arg1>
00224
00229 static void write_line(const CL_StringRef &format, Arg1 arg1)
00230 {
00231 CL_TempStringFormat f(format);
00232 f.set_arg(1, arg1);
00233 write_line(f.get_result());
00234 }
00235
00236 template <class Arg1, class Arg2>
00237
00243 static void write_line(const CL_StringRef &format, Arg1 arg1, Arg2 arg2)
00244 {
00245 CL_TempStringFormat f(format);
00246 f.set_arg(1, arg1);
00247 f.set_arg(2, arg2);
00248 write_line(f.get_result());
00249 }
00250
00251 template <class Arg1, class Arg2, class Arg3>
00252
00259 static void write_line(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3)
00260 {
00261 CL_TempStringFormat f(format);
00262 f.set_arg(1, arg1);
00263 f.set_arg(2, arg2);
00264 f.set_arg(3, arg3);
00265 write_line(f.get_result());
00266 }
00267
00268 template <class Arg1, class Arg2, class Arg3, class Arg4>
00269
00277 static void write_line(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
00278 {
00279 CL_TempStringFormat f(format);
00280 f.set_arg(1, arg1);
00281 f.set_arg(2, arg2);
00282 f.set_arg(3, arg3);
00283 f.set_arg(4, arg4);
00284 write_line(f.get_result());
00285 }
00286
00287 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
00288
00297 static void write_line(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5)
00298 {
00299 CL_TempStringFormat f(format);
00300 f.set_arg(1, arg1);
00301 f.set_arg(2, arg2);
00302 f.set_arg(3, arg3);
00303 f.set_arg(4, arg4);
00304 f.set_arg(5, arg5);
00305 write_line(f.get_result());
00306 }
00307
00308 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
00309
00319 static void write_line(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6)
00320 {
00321 CL_TempStringFormat f(format);
00322 f.set_arg(1, arg1);
00323 f.set_arg(2, arg2);
00324 f.set_arg(3, arg3);
00325 f.set_arg(4, arg4);
00326 f.set_arg(5, arg5);
00327 f.set_arg(6, arg6);
00328 write_line(f.get_result());
00329 }
00330
00331 template <class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
00332
00343 static void write_line(const CL_StringRef &format, Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7)
00344 {
00345 CL_TempStringFormat f(format);
00346 f.set_arg(1, arg1);
00347 f.set_arg(2, arg2);
00348 f.set_arg(3, arg3);
00349 f.set_arg(4, arg4);
00350 f.set_arg(5, arg5);
00351 f.set_arg(6, arg6);
00352 f.set_arg(7, arg7);
00353 write_line(f.get_result());
00354 }
00355
00357 static void wait_for_key()
00358 {
00359 #ifdef WIN32
00360 while (!_kbhit()) Sleep(250);
00361 _getch();
00362 #endif
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373 }
00375 };
00376