KiCad PCB EDA Suite
reporter.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
5  * Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef _REPORTER_H_
26 #define _REPORTER_H_
27 
28 #include <wx/string.h>
29 
37 class wxTextCtrl;
38 class wxHtmlListbox;
40 
41 
61 class REPORTER {
62 
63 public:
73  //
74  enum SEVERITY {
76  RPT_INFO = 0x1,
77  RPT_ACTION = 0x2,
78  RPT_WARNING = 0x4,
79  RPT_ERROR = 0x8
80  };
81 
88  enum LOCATION {
89  LOC_HEAD = 0,
92  };
93 
103  virtual REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) = 0;
104 
109  virtual REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED )
110  {
111  return Report( aText, aSeverity );
112  }
113 
118  virtual REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED )
119  {
120  return Report( aText, aSeverity );
121  }
122 
123  REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_UNDEFINED );
124 
125  REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
126  REPORTER& operator <<( const wxChar* aText ) { return Report( wxString( aText ) ); }
127  REPORTER& operator <<( wxChar aChar ) { return Report( wxString( aChar ) ); }
128  REPORTER& operator <<( const char* aText ) { return Report( aText ); }
129 
134  virtual bool HasMessage() const = 0;
135 };
136 
137 
143 {
144  wxTextCtrl* m_textCtrl;
145 
146 public:
147  WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
148  REPORTER(),
149  m_textCtrl( aTextCtrl )
150  {
151  }
152 
153  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
154 
155  bool HasMessage() const override;
156 };
157 
158 
164 {
165  wxString* m_string;
166 
167 public:
168  WX_STRING_REPORTER( wxString* aString ) :
169  REPORTER(),
170  m_string( aString )
171  {
172  }
173 
174  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
175 
176  bool HasMessage() const override;
177 };
178 
179 
185 {
187 
188 public:
190  REPORTER(),
191  m_panel( aPanel )
192  {
193  }
194 
195  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
196 
197  REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
198 
199  REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
200 
201  bool HasMessage() const override;
202 };
203 
210 class NULL_REPORTER : public REPORTER
211 {
212 public:
214  {
215  }
216 
217  static REPORTER& GetInstance();
218 
219  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
220 
221  bool HasMessage() const override { return false; }
222 };
223 
229 class STDOUT_REPORTER : public REPORTER
230 {
231 public:
233  {
234  }
235 
236  static REPORTER& GetInstance();
237 
238  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
239 
240  bool HasMessage() const override { return false; }
241 };
242 
243 #endif // _REPORTER_H_
wxTextCtrl * m_textCtrl
Definition: reporter.h:144
virtual bool HasMessage() const =0
Function HasMessage Returns true if the reporter client is non-empty.
WX_HTML_PANEL_REPORTER(WX_HTML_REPORT_PANEL *aPanel)
Definition: reporter.h:189
WX_TEXT_CTRL_REPORTER(wxTextCtrl *aTextCtrl)
Definition: reporter.h:147
WX_HTML_REPORT_PANEL * m_panel
Definition: reporter.h:186
Class STDOUT_REPORTER.
Definition: reporter.h:229
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.h:240
Class WX_TEXT_CTRL_REPORTER is wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:142
virtual REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)
Function ReportHead Places the report at the beginning of the list for objects that support ordering...
Definition: reporter.h:118
Class NULL_REPORTER.
Definition: reporter.h:210
SEVERITY
Severity of the reported messages.
Definition: reporter.h:74
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.h:109
Class WX_STRING_REPORTER is a wrapper for reporting to a wxString object.
Definition: reporter.h:163
Class WX_HTML_PANEL_REPORTER is a wrapper for reporting to a wx HTML window.
Definition: reporter.h:184
LOCATION
Location where the message is to be reported.
Definition: reporter.h:88
REPORTER & operator<<(const wxString &aText)
Definition: reporter.h:125
WX_STRING_REPORTER(wxString *aString)
Definition: reporter.h:168
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.h:221
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
wxString * m_string
Definition: reporter.h:165
Class WX_HTML_REPORT_PANEL.