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 
82  static constexpr int RPT_ALL = RPT_INFO | RPT_ACTION | RPT_WARNING | RPT_ERROR;
83 
90  enum LOCATION {
91  LOC_HEAD = 0,
94  };
95 
105  virtual REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) = 0;
106 
111  virtual REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED )
112  {
113  return Report( aText, aSeverity );
114  }
115 
120  virtual REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED )
121  {
122  return Report( aText, aSeverity );
123  }
124 
125  REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_UNDEFINED );
126 
127  REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
128  REPORTER& operator <<( const wxChar* aText ) { return Report( wxString( aText ) ); }
129  REPORTER& operator <<( wxChar aChar ) { return Report( wxString( aChar ) ); }
130  REPORTER& operator <<( const char* aText ) { return Report( aText ); }
131 
136  virtual bool HasMessage() const = 0;
137 };
138 
139 
145 {
146  wxTextCtrl* m_textCtrl;
147 
148 public:
149  WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
150  REPORTER(),
151  m_textCtrl( aTextCtrl )
152  {
153  }
154 
155  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
156 
157  bool HasMessage() const override;
158 };
159 
160 
166 {
167  wxString* m_string;
168 
169 public:
170  WX_STRING_REPORTER( wxString* aString ) :
171  REPORTER(),
172  m_string( aString )
173  {
174  }
175 
176  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
177 
178  bool HasMessage() const override;
179 };
180 
181 
187 {
189 
190 public:
192  REPORTER(),
193  m_panel( aPanel )
194  {
195  }
196 
197  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
198 
199  REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
200 
201  REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
202 
203  bool HasMessage() const override;
204 };
205 
212 class NULL_REPORTER : public REPORTER
213 {
214 public:
216  {
217  }
218 
219  static REPORTER& GetInstance();
220 
221  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
222 
223  bool HasMessage() const override { return false; }
224 };
225 
231 class STDOUT_REPORTER : public REPORTER
232 {
233 public:
235  {
236  }
237 
238  static REPORTER& GetInstance();
239 
240  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) override;
241 
242  bool HasMessage() const override { return false; }
243 };
244 
245 #endif // _REPORTER_H_
wxTextCtrl * m_textCtrl
Definition: reporter.h:146
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:191
WX_TEXT_CTRL_REPORTER(wxTextCtrl *aTextCtrl)
Definition: reporter.h:149
WX_HTML_REPORT_PANEL * m_panel
Definition: reporter.h:188
Class STDOUT_REPORTER.
Definition: reporter.h:231
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:242
Class WX_TEXT_CTRL_REPORTER is wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:144
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:120
Class NULL_REPORTER.
Definition: reporter.h:212
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:111
Class WX_STRING_REPORTER is a wrapper for reporting to a wxString object.
Definition: reporter.h:165
Class WX_HTML_PANEL_REPORTER is a wrapper for reporting to a wx HTML window.
Definition: reporter.h:186
LOCATION
Location where the message is to be reported.
Definition: reporter.h:90
REPORTER & operator<<(const wxString &aText)
Definition: reporter.h:127
static constexpr int RPT_ALL
Definition: reporter.h:82
WX_STRING_REPORTER(wxString *aString)
Definition: reporter.h:170
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.h:223
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:167
Class WX_HTML_REPORT_PANEL.