KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef _REPORTER_H_
22#define _REPORTER_H_
23
24#include <memory>
25#include <map>
26#include <mutex>
27
28#include <eda_units.h>
29#include <ki_error.h>
31#include <kicommon.h>
32
43
44class wxString;
45class wxStatusBar;
46class wxTextCtrl;
48class WX_INFOBAR;
49class KISTATUSBAR;
51
52
71
73{
74public:
77 { }
78
79 virtual ~REPORTER()
80 { }
81
93
101
102 virtual REPORTER& Report( const wxString& aText,
103 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
104 {
105 m_reportedSeverityMask |= aSeverity;
106 return *this;
107 }
108
116 virtual REPORTER& Report( const KI_ERROR& aError );
117
121 virtual REPORTER& ReportTail( const wxString& aText,
122 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
123 {
124 return Report( aText, aSeverity );
125 }
126
130 virtual REPORTER& ReportHead( const wxString& aText,
131 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
132 {
133 return Report( aText, aSeverity );
134 }
135
136 REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED );
137
138 REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
139
143 virtual bool HasMessage() const
144 {
145 return m_reportedSeverityMask != 0;
146 }
147
152 virtual bool HasMessageOfSeverity( int aSeverityMask ) const
153 {
154 return ( m_reportedSeverityMask & aSeverityMask ) != 0;
155 }
156
157 virtual EDA_UNITS GetUnits() const
158 {
159 return EDA_UNITS::MM;
160 }
161
162 virtual void Clear()
163 {
165 }
166
167 virtual void Finalize() {};
168
169private:
171};
172
173
184{
185public:
186 SYNC_REPORTER( REPORTER& aReporter ) :
187 m_reporter( &aReporter )
188 { }
189
190 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
191
192 REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
193
194 REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
195
196 bool HasMessage() const override;
197
198 bool HasMessageOfSeverity( int aSeverityMask ) const override;
199
200 EDA_UNITS GetUnits() const override;
201
202 void Clear() override;
203
204 void Finalize() override;
205
206 void SetNullReporter();
207
208protected:
210 mutable std::mutex m_mutex;
211};
212
213
218{
219public:
220 WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
221 REPORTER(),
222 m_textCtrl( aTextCtrl )
223 {
224 }
225
227 {
228 }
229
230 REPORTER& Report( const wxString& aText,
231 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
232
233private:
234 wxTextCtrl* m_textCtrl;
235};
236
237
242{
243public:
245 REPORTER()
246 { }
247
249 { }
250
251 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
252
253 const wxString& GetMessages() const;
254 void Clear() override;
255
256private:
257 wxString m_string;
258};
259
260
267{
268public:
270 { }
271
273 { }
274
275 static REPORTER& GetInstance();
276
277 REPORTER& Report( const wxString& aText,
278 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
279};
280
281
287{
288public:
290 m_verbose( false )
291 { }
292
294 { }
295
296 static CLI_REPORTER& GetInstance();
297
301 void SetVerbose( bool aVerbose ) { m_verbose = aVerbose; }
302
303 bool GetVerbose() const { return m_verbose; }
304
305 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
306
307private:
309};
310
311
316{
317public:
320
322 { }
323
324 static REPORTER& GetInstance();
325
326 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
327};
328
329
331{
332public:
334 { }
335
337 { }
338
339 static REPORTER& GetInstance();
340
341 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
342};
343
344
346{
347public:
350
352 { }
353
354 static LOAD_INFO_REPORTER& GetInstance();
355
356 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
357
358 void SetRedirectTarget( REPORTER* aReporter );
359 REPORTER* GetRedirectTarget() const;
360
361private:
363};
364
365
376
377
385{
386public:
387 explicit FONTCONFIG_REPORTER_SCOPE( REPORTER* aReporter );
389
390private:
392};
393
394
396{
397public:
398 REDIRECT_REPORTER( REPORTER* aRedirectTarget ) : m_redirectTarget( aRedirectTarget ) {}
399
400 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
401
403};
404
405
410{
411public:
412 STATUSBAR_REPORTER( wxStatusBar* aStatusBar, int aPosition = 0 )
413 : REPORTER(),
414 m_statusBar( aStatusBar ),
415 m_position( aPosition )
416 { }
417
418 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
419
420private:
421 wxStatusBar* m_statusBar;
423};
424
425
427{
428public:
429 STATUSBAR_WARNING_REPORTER( KISTATUSBAR* aStatusBar, const wxString& aSource );
431
432 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
433 REPORTER& Report( const KI_ERROR& aError ) override;
434
435private:
436 std::shared_ptr<STATUSBAR_WARNING_REPORTER_IMPL> m_impl;
437};
438
439#endif // _REPORTER_H_
Reporter forwarding messages to stdout or stderr as appropriate.
Definition reporter.h:287
void SetVerbose(bool aVerbose)
Enable or disable verbose mode.
Definition reporter.h:301
virtual ~CLI_REPORTER()
Definition reporter.h:293
bool m_verbose
Definition reporter.h:308
bool GetVerbose() const
Definition reporter.h:303
FONTCONFIG_REPORTER_SCOPE(REPORTER *aReporter)
Definition reporter.cpp:388
REPORTER * m_previousReporter
Definition reporter.h:391
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
Definition kistatusbar.h:50
Holds a structured error message.
Definition ki_error.h:38
LOAD_INFO_REPORTER_SCOPE(REPORTER *aReporter)
Definition reporter.cpp:374
LOAD_INFO_REPORTER & m_reporter
Definition reporter.h:373
REPORTER * m_previousReporter
Definition reporter.h:374
REPORTER * m_redirectTarget
Definition reporter.h:362
virtual ~LOAD_INFO_REPORTER()
Definition reporter.h:351
virtual ~NULL_REPORTER()
Definition reporter.h:272
REPORTER * m_redirectTarget
Definition reporter.h:402
REDIRECT_REPORTER(REPORTER *aRedirectTarget)
Definition reporter.h:398
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual EDA_UNITS GetUnits() const
Definition reporter.h:157
int m_reportedSeverityMask
Definition reporter.h:170
LOCATION
Location where the message is to be reported.
Definition reporter.h:88
@ LOC_BODY
Definition reporter.h:90
@ LOC_TAIL
Definition reporter.h:91
@ LOC_HEAD
Definition reporter.h:89
virtual REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the beginning of the list for objects that support ordering.
Definition reporter.h:130
virtual void Clear()
Definition reporter.h:162
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the end of the list, for objects that support report ordering.
Definition reporter.h:121
virtual void Finalize()
Definition reporter.h:167
virtual bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
Definition reporter.h:152
virtual ~REPORTER()
Definition reporter.h:79
REPORTER()
Definition reporter.h:75
virtual bool HasMessage() const
Returns true if any messages were reported.
Definition reporter.h:143
STATUSBAR_REPORTER(wxStatusBar *aStatusBar, int aPosition=0)
Definition reporter.h:412
wxStatusBar * m_statusBar
Definition reporter.h:421
STATUSBAR_WARNING_REPORTER(KISTATUSBAR *aStatusBar, const wxString &aSource)
Definition reporter.cpp:440
~STATUSBAR_WARNING_REPORTER() override
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:450
std::shared_ptr< STATUSBAR_WARNING_REPORTER_IMPL > m_impl
Definition reporter.h:436
virtual ~STDOUT_REPORTER()
Definition reporter.h:321
REPORTER * m_reporter
Definition reporter.h:209
SYNC_REPORTER(REPORTER &aReporter)
Definition reporter.h:186
std::mutex m_mutex
Definition reporter.h:210
virtual ~WXLOG_REPORTER()
Definition reporter.h:336
A widget for browsing a rich text error/status report.
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:76
wxString m_string
Definition reporter.h:257
virtual ~WX_STRING_REPORTER()
Definition reporter.h:248
virtual ~WX_TEXT_CTRL_REPORTER()
Definition reporter.h:226
wxTextCtrl * m_textCtrl
Definition reporter.h:234
WX_TEXT_CTRL_REPORTER(wxTextCtrl *aTextCtrl)
Definition reporter.h:220
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
EDA_UNITS
Definition eda_units.h:44
#define KICOMMON_API
Definition kicommon.h:27
SEVERITY
@ RPT_SEVERITY_UNDEFINED