nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #include "NuxCore.h" 00024 00025 namespace nux 00026 { 00027 00028 // MessageBox resolves to: 00029 // MessageBoxA, if UNICODE is not defined 00030 // MessageBoxW, if UNICODE is defined 00031 00032 // In all cases in the code, it is assumed that we have UNICODE and _UNICODE defined or not. 00033 // We have no support for cases of (UNICODE, !_UNICODE) or (!UNICODE, _UNICODE) 00034 // TCHAR resolves: 00035 // char, if _UNICODE is not defined 00036 // wchar_t, if _UNICODE is defined 00037 00038 00039 // Set to true to disable the popping of dialog box. The message will go to the log. 00040 const t_bool GNoDialog = false; 00041 00042 /*----------------------------------------------------------------------------- 00043 Formatted printing and messages. 00044 -----------------------------------------------------------------------------*/ 00045 00046 t_u32 GetVariableArgs ( TCHAR *Dest, t_u32 Size, t_u32 Count, const TCHAR*& Fmt, va_list ArgPtr ) 00047 { 00048 t_u32 Result = VSNTPRINTF_S (Dest, Size, Count, Fmt, ArgPtr); 00049 va_end (ArgPtr); 00050 return Result; 00051 } 00052 t_u32 GetVariableArgsAnsi ( ANSICHAR *Dest, t_u32 Size, t_u32 Count, const ANSICHAR*& Fmt, va_list ArgPtr) 00053 { 00054 t_u32 Result = VSNPRINTF_S (Dest, Size, Count, Fmt, ArgPtr); 00055 va_end (ArgPtr); 00056 return Result; 00057 } 00058 00059 // This function can be used to print anything before the other output are initialized. 00060 void PrintOutputDebugString (const TCHAR *Format, ... ) 00061 { 00062 TCHAR TempStr[4096]; 00063 GET_VARARGS ( TempStr, 4096, NUX_ARRAY_COUNT (TempStr) - 1, Format ); 00064 00065 #ifdef _WIN32 00066 OutputDebugString ( TempStr ); 00067 #else 00068 printf ("%s\n", TCHAR_TO_ANSI (TempStr) ); 00069 #endif 00070 } 00071 00072 void LogOutputAssertMessage (const ANSICHAR *File, int Line, const TCHAR *Format/*=TEXT("")*/, ... ) 00073 { 00074 TCHAR TempStr[4096]; 00075 GET_VARARGS ( TempStr, NUX_ARRAY_COUNT (TempStr), NUX_ARRAY_COUNT (TempStr) - 1, Format ); 00076 00077 // Logged to a file... Put "\r\n" at the end of each line. 00078 if (LogOutputRedirector::Ready() ) 00079 GLogDevice.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("Assertion failed: %s\r\n [File:%s]\r\n [Line: %i]\r\n"), (const TCHAR *) TempStr, ANSI_TO_TCHAR (File), Line); 00080 } 00081 00082 void LogOutputErrorMessage (const ANSICHAR *File, int Line, const TCHAR *Format/*=TEXT("")*/, ... ) 00083 { 00084 TCHAR TempStr[4096]; 00085 GET_VARARGS ( TempStr, NUX_ARRAY_COUNT (TempStr), NUX_ARRAY_COUNT (TempStr) - 1, Format ); 00086 00087 if (LogOutputRedirector::Ready() ) 00088 GLogDevice.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("Error: %s\r\n [File:%s]\r\n [Line: %d]\r\n"), (const TCHAR *) TempStr, ANSI_TO_TCHAR (File), Line); 00089 } 00090 00091 void LogOutputDebugMessage (const TCHAR *Format/*=TEXT("")*/, ... ) 00092 { 00093 TCHAR TempStr[4096]; 00094 GET_VARARGS ( TempStr, NUX_ARRAY_COUNT (TempStr), NUX_ARRAY_COUNT (TempStr) - 1, Format ); 00095 00096 if (LogOutputRedirector::Ready() ) 00097 GLogDevice.LogFunction (NUX_MSG_SEVERITY_NONE, TempStr); 00098 } 00099 00100 void LogOutputSeverityMessage (int Severity, const TCHAR *Format/*=TEXT("")*/, ... ) 00101 { 00102 TCHAR TempStr[4096]; 00103 GET_VARARGS ( TempStr, NUX_ARRAY_COUNT (TempStr), NUX_ARRAY_COUNT (TempStr) - 1, Format ); 00104 00105 if (LogOutputRedirector::Ready() ) 00106 GLogDevice.LogFunction (Severity, TempStr); 00107 } 00108 00109 bool OutputRedirectorReady() 00110 { 00111 return LogOutputRedirector::Ready(); 00112 } 00113 00114 }