~ubuntu-branches/ubuntu/oneiric/nux/oneiric

« back to all changes in this revision

Viewing changes to NuxCore/NuxCore.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-11-18 19:17:32 UTC
  • Revision ID: james.westby@ubuntu.com-20101118191732-rn35790vekj6o4my
Tags: upstream-0.9.4
ImportĀ upstreamĀ versionĀ 0.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3, as
 
6
 * published by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 
12
 * License for more details.
 
13
 *
 
14
 * You should have received a copy of both the GNU Lesser General Public
 
15
 * License version 3 along with this program.  If not, see
 
16
 * <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#include "NuxCore.h"
 
24
 
 
25
namespace nux
 
26
{
 
27
 
 
28
//  MessageBox resolves to:
 
29
//      MessageBoxA, if UNICODE is not defined
 
30
//      MessageBoxW, if UNICODE is defined
 
31
 
 
32
//  In all cases in the code, it is assumed that we have UNICODE and _UNICODE defined or not.
 
33
//  We have no support for cases of  (UNICODE, !_UNICODE) or (!UNICODE, _UNICODE)
 
34
//  TCHAR  resolves:
 
35
//      char, if _UNICODE is not defined
 
36
//      wchar_t, if _UNICODE is defined
 
37
 
 
38
 
 
39
// Set to true to disable the popping of dialog box. The message will go to the log.
 
40
  const t_bool GNoDialog          = false;
 
41
 
 
42
  /*-----------------------------------------------------------------------------
 
43
  Formatted printing and messages.
 
44
  -----------------------------------------------------------------------------*/
 
45
 
 
46
  t_u32 GetVariableArgs ( TCHAR *Dest, t_u32 Size, t_u32 Count, const TCHAR*& Fmt, va_list ArgPtr )
 
47
  {
 
48
    t_u32 Result = VSNTPRINTF_S (Dest, Size, Count, Fmt, ArgPtr);
 
49
    va_end (ArgPtr);
 
50
    return Result;
 
51
  }
 
52
  t_u32 GetVariableArgsAnsi ( ANSICHAR *Dest, t_u32 Size, t_u32 Count, const ANSICHAR*& Fmt, va_list ArgPtr)
 
53
  {
 
54
    t_u32 Result = VSNPRINTF_S (Dest, Size, Count, Fmt, ArgPtr);
 
55
    va_end (ArgPtr);
 
56
    return Result;
 
57
  }
 
58
 
 
59
// This function can be used to print anything before the other output are initialized.
 
60
  void PrintOutputDebugString (const TCHAR *Format, ... )
 
61
  {
 
62
    TCHAR TempStr[4096];
 
63
    GET_VARARGS ( TempStr, 4096, NUX_ARRAY_COUNT (TempStr) - 1, Format );
 
64
 
 
65
#ifdef _WIN32
 
66
    OutputDebugString ( TempStr );
 
67
#else
 
68
    printf ("%s\n", TCHAR_TO_ANSI (TempStr) );
 
69
#endif
 
70
  }
 
71
 
 
72
  void LogOutputAssertMessage (const ANSICHAR *File, int Line, const TCHAR *Format/*=TEXT("")*/, ... )
 
73
  {
 
74
    TCHAR TempStr[4096];
 
75
    GET_VARARGS ( TempStr, NUX_ARRAY_COUNT (TempStr), NUX_ARRAY_COUNT (TempStr) - 1, Format );
 
76
 
 
77
    // Logged to a file... Put "\r\n" at the end of each line.
 
78
    if (LogOutputRedirector::Ready() )
 
79
      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);
 
80
  }
 
81
 
 
82
  void LogOutputErrorMessage (const ANSICHAR *File, int Line, const TCHAR *Format/*=TEXT("")*/, ... )
 
83
  {
 
84
    TCHAR TempStr[4096];
 
85
    GET_VARARGS ( TempStr, NUX_ARRAY_COUNT (TempStr), NUX_ARRAY_COUNT (TempStr) - 1, Format );
 
86
 
 
87
    if (LogOutputRedirector::Ready() )
 
88
      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);
 
89
  }
 
90
 
 
91
  void LogOutputDebugMessage (const TCHAR *Format/*=TEXT("")*/, ... )
 
92
  {
 
93
    TCHAR TempStr[4096];
 
94
    GET_VARARGS ( TempStr, NUX_ARRAY_COUNT (TempStr), NUX_ARRAY_COUNT (TempStr) - 1, Format );
 
95
 
 
96
    if (LogOutputRedirector::Ready() )
 
97
      GLogDevice.LogFunction (NUX_MSG_SEVERITY_NONE, TempStr);
 
98
  }
 
99
 
 
100
  void LogOutputSeverityMessage (int Severity, const TCHAR *Format/*=TEXT("")*/, ... )
 
101
  {
 
102
    TCHAR TempStr[4096];
 
103
    GET_VARARGS ( TempStr, NUX_ARRAY_COUNT (TempStr), NUX_ARRAY_COUNT (TempStr) - 1, Format );
 
104
 
 
105
    if (LogOutputRedirector::Ready() )
 
106
      GLogDevice.LogFunction (Severity, TempStr);
 
107
  }
 
108
 
 
109
  bool OutputRedirectorReady()
 
110
  {
 
111
    return LogOutputRedirector::Ready();
 
112
  }
 
113
 
 
114
}