/[pcsx2_0.9.7]/trunk/common/include/Utilities/Console.h
ViewVC logotype

Contents of /trunk/common/include/Utilities/Console.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 9428 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./trunk
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #pragma once
17
18 #include "StringHelpers.h"
19
20 enum ConsoleColors
21 {
22 Color_Current = -1,
23
24 Color_Black = 0,
25 Color_Green,
26 Color_Red,
27 Color_Blue,
28 Color_Magenta,
29 Color_Orange,
30 Color_Gray,
31
32 Color_Cyan, // faint visibility, intended for logging PS2/IOP output
33 Color_Yellow, // faint visibility, intended for logging PS2/IOP output
34 Color_White, // faint visibility, intended for logging PS2/IOP output
35
36 // Strong text *may* result in mis-aligned text in the console, depending on the
37 // font and the platform, so use these with caution.
38 Color_StrongBlack,
39 Color_StrongRed, // intended for errors
40 Color_StrongGreen, // intended for infrequent state information
41 Color_StrongBlue, // intended for block headings
42 Color_StrongMagenta,
43 Color_StrongOrange, // intended for warnings
44 Color_StrongGray,
45
46 Color_StrongCyan,
47 Color_StrongYellow,
48 Color_StrongWhite,
49
50 Color_Default,
51
52 ConsoleColors_Count
53 };
54
55 static const ConsoleColors DefaultConsoleColor = Color_Default;
56
57
58 // Use fastcall for the console; should be helpful in most cases
59 #define __concall __fastcall
60
61 // ----------------------------------------------------------------------------------------
62 // IConsoleWriter -- For printing messages to the console.
63 // ----------------------------------------------------------------------------------------
64 // General ConsoleWrite Threading Guideline:
65 // PCSX2 is a threaded environment and multiple threads can write to the console asynchronously.
66 // Individual calls to ConsoleWriter APIs will be written in atomic fashion, however "partial"
67 // logs may end up interrupted by logs on other threads. This is usually not a problem for
68 // WriteLn, but may be undesirable for typical uses of Write. In cases where you want to
69 // print multi-line blocks of uninterrupted logs, compound the entire log into a single large
70 // string and issue that to WriteLn.
71 //
72 struct IConsoleWriter
73 {
74 // A direct console write, without tabbing or newlines. Useful to devs who want to do quick
75 // logging of various junk; but should *not* be used in production code due.
76 void (__concall *WriteRaw)( const wxString& fmt );
77
78 // WriteLn implementation for internal use only. Bypasses tabbing, prefixing, and other
79 // formatting.
80 void (__concall *DoWriteLn)( const wxString& fmt );
81
82 // SetColor implementation for internal use only.
83 void (__concall *DoSetColor)( ConsoleColors color );
84
85 // Special implementation of DoWrite that's pretty much for MSVC use only.
86 // All implementations should map to DoWrite, except Stdio which should map to Null.
87 // (This avoids circular/recursive stdio output)
88 void (__concall *DoWriteFromStdout)( const wxString& fmt );
89
90 void (__concall *Newline)();
91 void (__concall *SetTitle)( const wxString& title );
92
93 // internal value for indentation of individual lines. Use the Indent() member to invoke.
94 int _imm_indentation;
95
96 // For internal use only.
97 wxString _addIndentation( const wxString& src, int glob_indent ) const;
98
99 // ----------------------------------------------------------------------------
100 // Public members; call these to print stuff to console!
101 //
102 // All functions always return false. Return value is provided only so that we can easily
103 // disable logs at compile time using the "0&&action" macro trick.
104
105 ConsoleColors GetColor() const;
106 const IConsoleWriter& SetColor( ConsoleColors color ) const;
107 const IConsoleWriter& ClearColor() const;
108 const IConsoleWriter& SetIndent( int tabcount=1 ) const;
109
110 IConsoleWriter Indent( int tabcount=1 ) const;
111
112 bool FormatV( const char* fmt, va_list args ) const;
113 bool WriteLn( ConsoleColors color, const char* fmt, ... ) const;
114 bool WriteLn( const char* fmt, ... ) const;
115 bool Error( const char* fmt, ... ) const;
116 bool Warning( const char* fmt, ... ) const;
117
118 bool FormatV( const wxChar* fmt, va_list args ) const;
119 bool WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const;
120 bool WriteLn( const wxChar* fmt, ... ) const;
121 bool Error( const wxChar* fmt, ... ) const;
122 bool Warning( const wxChar* fmt, ... ) const;
123 };
124
125 // --------------------------------------------------------------------------------------
126 // NullConsoleWriter
127 // --------------------------------------------------------------------------------------
128 // Used by Release builds for Debug and Devel writes (DbgCon / DevCon). Inlines to NOPs. :)
129 //
130 struct NullConsoleWriter
131 {
132 void WriteRaw( const wxString& fmt ) {}
133 void DoWriteLn( const wxString& fmt ) {}
134 void DoSetColor( ConsoleColors color ) {}
135 void DoWriteFromStdout( const wxString& fmt ) {}
136 void Newline() {}
137 void SetTitle( const wxString& title ) {}
138
139
140 ConsoleColors GetColor() const { return Color_Current; }
141 const NullConsoleWriter& SetColor( ConsoleColors color ) const { return *this; }
142 const NullConsoleWriter& ClearColor() const { return *this; }
143 const NullConsoleWriter& SetIndent( int tabcount=1 ) const { return *this; }
144
145 NullConsoleWriter Indent( int tabcount=1 ) const { return NullConsoleWriter(); }
146
147 bool FormatV( const char* fmt, va_list args ) const { return false; }
148 bool WriteLn( ConsoleColors color, const char* fmt, ... ) const { return false; }
149 bool WriteLn( const char* fmt, ... ) const { return false; }
150 bool Error( const char* fmt, ... ) const { return false; }
151 bool Warning( const char* fmt, ... ) const { return false; }
152
153 bool FormatV( const wxChar* fmt, va_list args ) const { return false; }
154 bool WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const { return false; }
155 bool WriteLn( const wxChar* fmt, ... ) const { return false; }
156 bool Error( const wxChar* fmt, ... ) const { return false; }
157 bool Warning( const wxChar* fmt, ... ) const { return false; }
158 };
159
160 // --------------------------------------------------------------------------------------
161 // ConsoleIndentScope
162 // --------------------------------------------------------------------------------------
163 // Provides a scoped indentation of the IConsoleWriter interface for the current thread.
164 // Any console writes performed from this scope will be indented by the specified number
165 // of tab characters.
166 //
167 // Scoped Object Notes: Like most scoped objects, this is intended to be used as a stack
168 // or temporary object only. Using it in a situation where the object's lifespan out-lives
169 // a scope will almost certainly result in unintended /undefined side effects.
170 //
171 class ConsoleIndentScope
172 {
173 DeclareNoncopyableObject( ConsoleIndentScope );
174
175 protected:
176 int m_amount;
177 bool m_IsScoped;
178
179 public:
180 // Constructor: The specified number of tabs will be appended to the current indentation
181 // setting. The tabs will be unrolled when the object leaves scope or is destroyed.
182 ConsoleIndentScope( int tabs=1 );
183 virtual ~ConsoleIndentScope() throw();
184 void EnterScope();
185 void LeaveScope();
186 };
187
188 // --------------------------------------------------------------------------------------
189 // ConsoleColorScope
190 // --------------------------------------------------------------------------------------
191 class ConsoleColorScope
192 {
193 DeclareNoncopyableObject( ConsoleColorScope );
194
195 protected:
196 ConsoleColors m_newcolor;
197 ConsoleColors m_old_color;
198 bool m_IsScoped;
199
200 public:
201 ConsoleColorScope( ConsoleColors newcolor );
202 virtual ~ConsoleColorScope() throw();
203 void EnterScope();
204 void LeaveScope();
205 };
206
207 // --------------------------------------------------------------------------------------
208 // ConsoleAttrScope
209 // --------------------------------------------------------------------------------------
210 // Applies both color and tab attributes in a single object constructor.
211 //
212 class ConsoleAttrScope
213 {
214 DeclareNoncopyableObject( ConsoleAttrScope );
215
216 protected:
217 ConsoleColors m_old_color;
218 int m_tabsize;
219
220 public:
221 ConsoleAttrScope( ConsoleColors newcolor, int indent=0 );
222 virtual ~ConsoleAttrScope() throw();
223 };
224
225 extern const IConsoleWriter Console;
226
227 extern void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp=NULL );
228 extern const wxString& ConsoleBuffer_Get();
229 extern void ConsoleBuffer_Clear();
230 extern void ConsoleBuffer_FlushToFile( FILE *fp );
231
232 extern const IConsoleWriter ConsoleWriter_Null;
233 extern const IConsoleWriter ConsoleWriter_Stdout;
234 extern const IConsoleWriter ConsoleWriter_Assert;
235 extern const IConsoleWriter ConsoleWriter_Buffered;
236 extern const IConsoleWriter ConsoleWriter_wxError;
237
238 extern const NullConsoleWriter NullCon;
239
240 extern const IConsoleWriter DevConWriter;
241 extern bool DevConWriterEnabled;
242
243 #ifdef PCSX2_DEVBUILD
244 # define DevCon DevConWriter
245 #else
246 # define DevCon DevConWriterEnabled && DevConWriter
247 #endif
248
249 #ifdef PCSX2_DEBUG
250 extern const IConsoleWriter DbgConWriter;
251 # define DbgCon DbgConWriter
252 #else
253 # define DbgCon 0&&NullCon
254 #endif

  ViewVC Help
Powered by ViewVC 1.1.22