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 #include <widgets/ui_common.h>
30 
38 class wxTextCtrl;
39 class wxHtmlListbox;
41 
42 
62 class REPORTER {
63 
64 public:
71  enum LOCATION {
72  LOC_HEAD = 0,
75  };
76 
86  virtual REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) = 0;
87 
92  virtual REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
93  {
94  return Report( aText, aSeverity );
95  }
96 
101  virtual REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
102  {
103  return Report( aText, aSeverity );
104  }
105 
106  REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED );
107 
108  REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
109  REPORTER& operator <<( const wxChar* aText ) { return Report( wxString( aText ) ); }
110  REPORTER& operator <<( wxChar aChar ) { return Report( wxString( aChar ) ); }
111  REPORTER& operator <<( const char* aText ) { return Report( aText ); }
112 
117  virtual bool HasMessage() const = 0;
118 
119  virtual ~REPORTER()
120  {
121  }
122 };
123 
124 
130 {
131  wxTextCtrl* m_textCtrl;
132 
133 public:
134  WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
135  REPORTER(),
136  m_textCtrl( aTextCtrl )
137  {
138  }
139 
141  {
142  }
143 
144  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
145 
146  bool HasMessage() const override;
147 };
148 
149 
155 {
156  wxString* m_string;
157 
158 public:
159  WX_STRING_REPORTER( wxString* aString ) :
160  REPORTER(),
161  m_string( aString )
162  {
163  }
164 
166  {
167  }
168 
169  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
170 
171  bool HasMessage() const override;
172 };
173 
174 
180 {
182 
183 public:
185  REPORTER(),
186  m_panel( aPanel )
187  {
188  }
189 
191  {
192  }
193 
194  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
195 
196  REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
197 
198  REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
199 
200  bool HasMessage() const override;
201 };
202 
209 class NULL_REPORTER : public REPORTER
210 {
211 public:
213  {
214  }
215 
216  virtual ~NULL_REPORTER()
217  {
218  }
219 
220  static REPORTER& GetInstance();
221 
222  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
223 
224  bool HasMessage() const override { return false; }
225 };
226 
232 class STDOUT_REPORTER : public REPORTER
233 {
234 public:
236  {
237  }
238 
240  {
241  }
242 
243  static REPORTER& GetInstance();
244 
245  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
246 
247  bool HasMessage() const override { return false; }
248 };
249 
250 #endif // _REPORTER_H_
wxTextCtrl * m_textCtrl
Definition: reporter.h:131
virtual bool HasMessage() const =0
Function HasMessage Returns true if the reporter client is non-empty.
REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.cpp:76
SEVERITY
Definition: ui_common.h:45
virtual ~WX_TEXT_CTRL_REPORTER()
Definition: reporter.h:140
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.h:92
REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function ReportHead Places the report at the beginning of the list for objects that support ordering.
Definition: reporter.cpp:85
virtual ~WX_STRING_REPORTER()
Definition: reporter.h:165
WX_HTML_PANEL_REPORTER(WX_HTML_REPORT_PANEL *aPanel)
Definition: reporter.h:184
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:94
WX_TEXT_CTRL_REPORTER(wxTextCtrl *aTextCtrl)
Definition: reporter.h:134
WX_HTML_REPORT_PANEL * m_panel
Definition: reporter.h:181
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:67
virtual ~STDOUT_REPORTER()
Definition: reporter.h:239
STDOUT_REPORTER.
Definition: reporter.h:232
REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:62
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:62
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.h:247
virtual ~NULL_REPORTER()
Definition: reporter.h:216
WX_TEXT_CTRL_REPORTER is wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:129
NULL_REPORTER.
Definition: reporter.h:209
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:115
virtual ~REPORTER()
Definition: reporter.h:119
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:39
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:99
Functions to provide common constants and other functions to assist in making a consistent UI.
WX_STRING_REPORTER is a wrapper for reporting to a wxString object.
Definition: reporter.h:154
WX_HTML_PANEL_REPORTER is a wrapper for reporting to a wx HTML window.
Definition: reporter.h:179
LOCATION
Location where the message is to be reported.
Definition: reporter.h:71
virtual REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Function ReportHead Places the report at the beginning of the list for objects that support ordering.
Definition: reporter.h:101
static REPORTER & GetInstance()
Definition: reporter.cpp:134
REPORTER & operator<<(const wxString &aText)
Definition: reporter.h:108
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:53
WX_STRING_REPORTER(wxString *aString)
Definition: reporter.h:159
virtual ~WX_HTML_PANEL_REPORTER()
Definition: reporter.h:190
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.h:224
wxString * m_string
Definition: reporter.h:156
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:48
static REPORTER & GetInstance()
Definition: reporter.cpp:104
WX_HTML_REPORT_PANEL.