console.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2009 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Kenneth Gangstoe
00028 */
00029 
00032 
00033 #pragma once
00034 
00035 // 'kbhit' was declared deprecated
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                         Do not replace WriteConsole with the commented WriteFile code unless you
00064                         really know what you are doing and understand when ANSI code pages are used and
00065                         when OEM code pages are used.  -- mbn 29. jan 2008
00066 
00067                 CL_TempString8 t = CL_StringHelp::text_to_local8(text);
00068                 DWORD written = 0;
00069                 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), t.data(), t.length(), &written, 0);
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();       // Required, else the next call to wait_for_key would fail
00362         #endif
00363 /*
00364                 write_line("Press any key");
00365         #ifdef WIN32
00366                 TCHAR buffer[1];
00367                 DWORD written = 0;
00368                 BOOL result = ReadConsole(GetStdHandle(STD_INPUT_HANDLE), buffer, 1, &written, 0);
00369         #else
00370                 char buffer[1];
00371                 read(0, buffer, 1);
00372         #endif
00373 */      }
00375 };
00376 

Generated on Thu Dec 3 02:39:28 2009 for ClanLib by  doxygen 1.4.6