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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 31 by william, Tue Sep 7 03:24:11 2010 UTC revision 62 by william, Tue Sep 7 11:08:22 2010 UTC
# Line 17  Line 17 
17    
18  #include "StringHelpers.h"  #include "StringHelpers.h"
19    
   
20  enum ConsoleColors  enum ConsoleColors
21  {  {
22          Color_Current = -1,          Color_Current = -1,
# Line 72  static const ConsoleColors DefaultConsol Line 71  static const ConsoleColors DefaultConsol
71  //  //
72  struct IConsoleWriter  struct IConsoleWriter
73  {  {
74          // Write implementation for internal use only.          // A direct console write, without tabbing or newlines.  Useful to devs who want to do quick
75          void (__concall *DoWrite)( const wxString& fmt );          // 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.          // WriteLn implementation for internal use only.  Bypasses tabbing, prefixing, and other
79            // formatting.
80          void (__concall *DoWriteLn)( const wxString& fmt );          void (__concall *DoWriteLn)( const wxString& fmt );
81    
82          // SetColor implementation for internal use only.          // SetColor implementation for internal use only.
# Line 83  struct IConsoleWriter Line 84  struct IConsoleWriter
84    
85          // Special implementation of DoWrite that's pretty much for MSVC use only.          // 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.          // 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 );          void (__concall *DoWriteFromStdout)( const wxString& fmt );
89    
90          void (__concall *Newline)();          void (__concall *Newline)();
91          void (__concall *SetTitle)( const wxString& title );          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!          // Public members; call these to print stuff to console!
101          //          //
# Line 101  struct IConsoleWriter Line 109  struct IConsoleWriter
109    
110          IConsoleWriter Indent( int tabcount=1 ) const;          IConsoleWriter Indent( int tabcount=1 ) const;
111    
112          bool Write( ConsoleColors color, const char* fmt, ... ) const;          bool FormatV( const char* fmt, va_list args ) const;
113          bool WriteLn( ConsoleColors color, const char* fmt, ... ) const;          bool WriteLn( ConsoleColors color, const char* fmt, ... ) const;
         bool Write( const char* fmt, ... ) const;  
114          bool WriteLn( const char* fmt, ... ) const;          bool WriteLn( const char* fmt, ... ) const;
115          bool Error( const char* fmt, ... ) const;          bool Error( const char* fmt, ... ) const;
116          bool Warning( const char* fmt, ... ) const;          bool Warning( const char* fmt, ... ) const;
117    
118          bool Write( ConsoleColors color, const wxChar* fmt, ... ) const;          bool FormatV( const wxChar* fmt, va_list args ) const;
119          bool WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const;          bool WriteLn( ConsoleColors color, const wxChar* fmt, ... ) const;
         bool Write( const wxChar* fmt, ... ) const;  
120          bool WriteLn( const wxChar* fmt, ... ) const;          bool WriteLn( const wxChar* fmt, ... ) const;
121          bool Error( const wxChar* fmt, ... ) const;          bool Error( const wxChar* fmt, ... ) const;
122          bool Warning( const wxChar* fmt, ... ) const;          bool Warning( const wxChar* fmt, ... ) const;
   
         bool WriteFromStdout( const char* fmt, ... ) const;  
         bool WriteFromStdout( ConsoleColors color, const char* fmt, ... ) const;  
   
         // internal value for indentation of individual lines.  Use the Indent() member to invoke.  
         int _imm_indentation;  
   
         // For internal use only.  
         wxString _addIndentation( const wxString& src, int glob_indent ) const;  
123  };  };
124    
125  extern IConsoleWriter   Console;  // --------------------------------------------------------------------------------------
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  //  ConsoleIndentScope
# Line 143  class ConsoleIndentScope Line 173  class ConsoleIndentScope
173          DeclareNoncopyableObject( ConsoleIndentScope );          DeclareNoncopyableObject( ConsoleIndentScope );
174    
175  protected:  protected:
176          int m_amount;          int                     m_amount;
177            bool            m_IsScoped;
178    
179  public:  public:
180          // Constructor: The specified number of tabs will be appended to the current indentation          // 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.          // setting.  The tabs will be unrolled when the object leaves scope or is destroyed.
182          ConsoleIndentScope( int tabs=1 )          ConsoleIndentScope( int tabs=1 );
183          {          virtual ~ConsoleIndentScope() throw();  
184                  Console.SetIndent( m_amount = tabs );          void EnterScope();
185          }          void LeaveScope();
   
         virtual ~ConsoleIndentScope() throw()  
         {  
                 if( m_amount != 0 ) Console.SetIndent( -m_amount );  
         }  
           
         void EndScope()  
         {  
                 Console.SetIndent( -m_amount );  
                 m_amount = 0;  
         }  
186  };  };
187    
188  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
# Line 173  class ConsoleColorScope Line 193  class ConsoleColorScope
193          DeclareNoncopyableObject( ConsoleColorScope );          DeclareNoncopyableObject( ConsoleColorScope );
194    
195  protected:  protected:
196          ConsoleColors m_old_color;          ConsoleColors   m_newcolor;
197            ConsoleColors   m_old_color;
198            bool                    m_IsScoped;
199    
200  public:  public:
201          ConsoleColorScope( ConsoleColors newcolor )          ConsoleColorScope( ConsoleColors newcolor );
202          {          virtual ~ConsoleColorScope() throw();
203                  m_old_color = Console.GetColor();          void EnterScope();
204                  Console.SetColor( newcolor );          void LeaveScope();
         }  
   
         virtual ~ConsoleColorScope() throw()  
         {  
                 Console.SetColor( m_old_color );  
         }  
205  };  };
206    
207  // --------------------------------------------------------------------------------------  // --------------------------------------------------------------------------------------
# Line 202  protected: Line 218  protected:
218          int                             m_tabsize;          int                             m_tabsize;
219    
220  public:  public:
221          ConsoleAttrScope( ConsoleColors newcolor, int indent=0 )          ConsoleAttrScope( ConsoleColors newcolor, int indent=0 );
222          {          virtual ~ConsoleAttrScope() throw();
                 m_old_color = Console.GetColor();  
                 Console.SetIndent( m_tabsize = indent );  
                 Console.SetColor( newcolor );  
         }  
   
         virtual ~ConsoleAttrScope() throw()  
         {  
                 Console.SetColor( m_old_color );  
                 Console.SetIndent( -m_tabsize );  
         }  
223  };  };
224    
225    extern const IConsoleWriter     Console;
226    
227  extern void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp=NULL );  extern void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp=NULL );
228  extern const wxString& ConsoleBuffer_Get();  extern const wxString& ConsoleBuffer_Get();
229  extern void ConsoleBuffer_Clear();  extern void ConsoleBuffer_Clear();
# Line 227  extern const IConsoleWriter            ConsoleWrit Line 235  extern const IConsoleWriter            ConsoleWrit
235  extern const IConsoleWriter             ConsoleWriter_Buffered;  extern const IConsoleWriter             ConsoleWriter_Buffered;
236  extern const IConsoleWriter             ConsoleWriter_wxError;  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  #ifdef PCSX2_DEVBUILD
244          extern IConsoleWriter   DevConWriter;  #       define DevCon DevConWriter
 #       define DevCon                   DevConWriter  
245  #else  #else
246  #       define DevCon                   0&&ConsoleWriter_Null  #       define DevCon DevConWriterEnabled && DevConWriter
247  #endif  #endif
248    
249  #ifdef PCSX2_DEBUG  #ifdef PCSX2_DEBUG
250          extern IConsoleWriter   DbgConWriter;  extern const IConsoleWriter             DbgConWriter;
251  #       define DbgCon                   DbgConWriter  #       define DbgCon                           DbgConWriter
252  #else  #else
253  #       define DbgCon                   0&&ConsoleWriter_Null  #       define DbgCon                           0&&NullCon
254  #endif  #endif
   

Legend:
Removed from v.31  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.22