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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 8019 byte(s)
committing r3113 initial commit again...
1 william 31 /* 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    
21     enum ConsoleColors
22     {
23     Color_Current = -1,
24    
25     Color_Black = 0,
26     Color_Green,
27     Color_Red,
28     Color_Blue,
29     Color_Magenta,
30     Color_Orange,
31     Color_Gray,
32    
33     Color_Cyan, // faint visibility, intended for logging PS2/IOP output
34     Color_Yellow, // faint visibility, intended for logging PS2/IOP output
35     Color_White, // faint visibility, intended for logging PS2/IOP output
36    
37     // Strong text *may* result in mis-aligned text in the console, depending on the
38     // font and the platform, so use these with caution.
39     Color_StrongBlack,
40     Color_StrongRed, // intended for errors
41     Color_StrongGreen, // intended for infrequent state information
42     Color_StrongBlue, // intended for block headings
43     Color_StrongMagenta,
44     Color_StrongOrange, // intended for warnings
45     Color_StrongGray,
46    
47     Color_StrongCyan,
48     Color_StrongYellow,
49     Color_StrongWhite,
50    
51     Color_Default,
52    
53     ConsoleColors_Count
54     };
55    
56     static const ConsoleColors DefaultConsoleColor = Color_Default;
57    
58    
59     // Use fastcall for the console; should be helpful in most cases
60     #define __concall __fastcall
61    
62     // ----------------------------------------------------------------------------------------
63     // IConsoleWriter -- For printing messages to the console.
64     // ----------------------------------------------------------------------------------------
65     // General ConsoleWrite Threading Guideline:
66     // PCSX2 is a threaded environment and multiple threads can write to the console asynchronously.
67     // Individual calls to ConsoleWriter APIs will be written in atomic fashion, however "partial"
68     // logs may end up interrupted by logs on other threads. This is usually not a problem for
69     // WriteLn, but may be undesirable for typical uses of Write. In cases where you want to
70     // print multi-line blocks of uninterrupted logs, compound the entire log into a single large
71     // string and issue that to WriteLn.
72     //
73     struct IConsoleWriter
74     {
75     // Write implementation for internal use only.
76     void (__concall *DoWrite)( const wxString& fmt );
77    
78     // WriteLn implementation for internal use only.
79     void (__concall *DoWriteLn)( const wxString& fmt );
80    
81     // SetColor implementation for internal use only.
82     void (__concall *DoSetColor)( ConsoleColors color );
83    
84     // Special implementation of DoWrite that's pretty much for MSVC use only.
85     // All implementations should map to DoWrite, except Stdio which should map to Null.
86     void (__concall *DoWriteFromStdout)( const wxString& fmt );
87    
88     void (__concall *Newline)();
89     void (__concall *SetTitle)( const wxString& title );
90    
91     // ----------------------------------------------------------------------------
92     // Public members; call these to print stuff to console!
93     //
94     // All functions always return false. Return value is provided only so that we can easily
95     // disable logs at compile time using the "0&&action" macro trick.
96    
97     ConsoleColors GetColor() const;
98     const IConsoleWriter& SetColor( ConsoleColors color ) const;
99     const IConsoleWriter& ClearColor() const;
100     const IConsoleWriter& SetIndent( int tabcount=1 ) const;
101    
102     IConsoleWriter Indent( int tabcount=1 ) const;
103    
104     bool Write( ConsoleColors color, const char* fmt, ... ) const;
105     bool WriteLn( ConsoleColors color, const char* fmt, ... ) const;
106     bool Write( const char* fmt, ... ) const;
107     bool WriteLn( const char* fmt, ... ) const;
108     bool Error( const char* fmt, ... ) const;
109     bool Warning( const char* fmt, ... ) const;
110    
111     bool Write( ConsoleColors color, const wxChar* fmt, ... ) const;
112     bool WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const;
113     bool Write( const wxChar* fmt, ... ) const;
114     bool WriteLn( const wxChar* fmt, ... ) const;
115     bool Error( const wxChar* fmt, ... ) const;
116     bool Warning( const wxChar* fmt, ... ) const;
117    
118     bool WriteFromStdout( const char* fmt, ... ) const;
119     bool WriteFromStdout( ConsoleColors color, const char* fmt, ... ) const;
120    
121     // internal value for indentation of individual lines. Use the Indent() member to invoke.
122     int _imm_indentation;
123    
124     // For internal use only.
125     wxString _addIndentation( const wxString& src, int glob_indent ) const;
126     };
127    
128     extern IConsoleWriter Console;
129    
130     // --------------------------------------------------------------------------------------
131     // ConsoleIndentScope
132     // --------------------------------------------------------------------------------------
133     // Provides a scoped indentation of the IConsoleWriter interface for the current thread.
134     // Any console writes performed from this scope will be indented by the specified number
135     // of tab characters.
136     //
137     // Scoped Object Notes: Like most scoped objects, this is intended to be used as a stack
138     // or temporary object only. Using it in a situation where the object's lifespan out-lives
139     // a scope will almost certainly result in unintended /undefined side effects.
140     //
141     class ConsoleIndentScope
142     {
143     DeclareNoncopyableObject( ConsoleIndentScope );
144    
145     protected:
146     int m_amount;
147    
148     public:
149     // Constructor: The specified number of tabs will be appended to the current indentation
150     // setting. The tabs will be unrolled when the object leaves scope or is destroyed.
151     ConsoleIndentScope( int tabs=1 )
152     {
153     Console.SetIndent( m_amount = tabs );
154     }
155    
156     virtual ~ConsoleIndentScope() throw()
157     {
158     if( m_amount != 0 ) Console.SetIndent( -m_amount );
159     }
160    
161     void EndScope()
162     {
163     Console.SetIndent( -m_amount );
164     m_amount = 0;
165     }
166     };
167    
168     // --------------------------------------------------------------------------------------
169     // ConsoleColorScope
170     // --------------------------------------------------------------------------------------
171     class ConsoleColorScope
172     {
173     DeclareNoncopyableObject( ConsoleColorScope );
174    
175     protected:
176     ConsoleColors m_old_color;
177    
178     public:
179     ConsoleColorScope( ConsoleColors newcolor )
180     {
181     m_old_color = Console.GetColor();
182     Console.SetColor( newcolor );
183     }
184    
185     virtual ~ConsoleColorScope() throw()
186     {
187     Console.SetColor( m_old_color );
188     }
189     };
190    
191     // --------------------------------------------------------------------------------------
192     // ConsoleAttrScope
193     // --------------------------------------------------------------------------------------
194     // Applies both color and tab attributes in a single object constructor.
195     //
196     class ConsoleAttrScope
197     {
198     DeclareNoncopyableObject( ConsoleAttrScope );
199    
200     protected:
201     ConsoleColors m_old_color;
202     int m_tabsize;
203    
204     public:
205     ConsoleAttrScope( ConsoleColors newcolor, int indent=0 )
206     {
207     m_old_color = Console.GetColor();
208     Console.SetIndent( m_tabsize = indent );
209     Console.SetColor( newcolor );
210     }
211    
212     virtual ~ConsoleAttrScope() throw()
213     {
214     Console.SetColor( m_old_color );
215     Console.SetIndent( -m_tabsize );
216     }
217     };
218    
219     extern void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp=NULL );
220     extern const wxString& ConsoleBuffer_Get();
221     extern void ConsoleBuffer_Clear();
222     extern void ConsoleBuffer_FlushToFile( FILE *fp );
223    
224     extern const IConsoleWriter ConsoleWriter_Null;
225     extern const IConsoleWriter ConsoleWriter_Stdout;
226     extern const IConsoleWriter ConsoleWriter_Assert;
227     extern const IConsoleWriter ConsoleWriter_Buffered;
228     extern const IConsoleWriter ConsoleWriter_wxError;
229    
230     #ifdef PCSX2_DEVBUILD
231     extern IConsoleWriter DevConWriter;
232     # define DevCon DevConWriter
233     #else
234     # define DevCon 0&&ConsoleWriter_Null
235     #endif
236    
237     #ifdef PCSX2_DEBUG
238     extern IConsoleWriter DbgConWriter;
239     # define DbgCon DbgConWriter
240     #else
241     # define DbgCon 0&&ConsoleWriter_Null
242     #endif
243    

  ViewVC Help
Powered by ViewVC 1.1.22