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>
30#include <kicommon.h>
31
42
43class wxString;
44class wxStatusBar;
45class wxTextCtrl;
47class WX_INFOBAR;
48class KISTATUSBAR;
50
51
70
72{
73public:
76 { }
77
78 virtual ~REPORTER()
79 { }
80
92
100
101 virtual REPORTER& Report( const wxString& aText,
102 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
103 {
104 m_reportedSeverityMask |= aSeverity;
105 return *this;
106 }
107
111 virtual REPORTER& ReportTail( const wxString& aText,
112 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
113 {
114 return Report( aText, aSeverity );
115 }
116
120 virtual REPORTER& ReportHead( const wxString& aText,
121 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
122 {
123 return Report( aText, aSeverity );
124 }
125
126 REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED );
127
128 REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
129
133 virtual bool HasMessage() const
134 {
135 return m_reportedSeverityMask != 0;
136 }
137
142 virtual bool HasMessageOfSeverity( int aSeverityMask ) const
143 {
144 return ( m_reportedSeverityMask & aSeverityMask ) != 0;
145 }
146
147 virtual EDA_UNITS GetUnits() const
148 {
149 return EDA_UNITS::MM;
150 }
151
152 virtual void Clear()
153 {
155 }
156
157private:
159};
160
161
171{
172public:
173 SYNC_REPORTER( REPORTER& aReporter ) :
174 m_reporter( aReporter )
175 { }
176
177 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
178
179 REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
180
181 REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
182
183 bool HasMessage() const override;
184
185 bool HasMessageOfSeverity( int aSeverityMask ) const override;
186
187 EDA_UNITS GetUnits() const override;
188
189 void Clear() override;
190
191protected:
193 mutable std::mutex m_mutex;
194};
195
196
201{
202public:
203 WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
204 REPORTER(),
205 m_textCtrl( aTextCtrl )
206 {
207 }
208
210 {
211 }
212
213 REPORTER& Report( const wxString& aText,
214 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
215
216private:
217 wxTextCtrl* m_textCtrl;
218};
219
220
225{
226public:
228 REPORTER()
229 { }
230
232 { }
233
234 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
235
236 const wxString& GetMessages() const;
237 void Clear() override;
238
239private:
240 wxString m_string;
241};
242
243
250{
251public:
253 { }
254
256 { }
257
258 static REPORTER& GetInstance();
259
260 REPORTER& Report( const wxString& aText,
261 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
262};
263
264
270{
271public:
273 m_verbose( false )
274 { }
275
277 { }
278
279 static CLI_REPORTER& GetInstance();
280
284 void SetVerbose( bool aVerbose ) { m_verbose = aVerbose; }
285
286 bool GetVerbose() const { return m_verbose; }
287
288 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
289
290private:
292};
293
294
299{
300public:
303
305 { }
306
307 static REPORTER& GetInstance();
308
309 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
310};
311
312
314{
315public:
317 { }
318
320 { }
321
322 static REPORTER& GetInstance();
323
324 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
325};
326
327
329{
330public:
333
335 { }
336
337 static LOAD_INFO_REPORTER& GetInstance();
338
339 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
340
341 void SetRedirectTarget( REPORTER* aReporter );
342 REPORTER* GetRedirectTarget() const;
343
344private:
346};
347
348
359
360
368{
369public:
370 explicit FONTCONFIG_REPORTER_SCOPE( REPORTER* aReporter );
372
373private:
375};
376
377
379{
380public:
381 REDIRECT_REPORTER( REPORTER* aRedirectTarget ) : m_redirectTarget( aRedirectTarget ) {}
382
383 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
384
386};
387
388
393{
394public:
395 STATUSBAR_REPORTER( wxStatusBar* aStatusBar, int aPosition = 0 )
396 : REPORTER(),
397 m_statusBar( aStatusBar ),
398 m_position( aPosition )
399 { }
400
401 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
402
403private:
404 wxStatusBar* m_statusBar;
406};
407
408
410{
411public:
412 STATUSBAR_WARNING_REPORTER( KISTATUSBAR* aStatusBar, const wxString& aSource );
414
415 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
416
417private:
418 std::shared_ptr<STATUSBAR_WARNING_REPORTER_IMPL> m_impl;
419};
420
421#endif // _REPORTER_H_
Reporter forwarding messages to stdout or stderr as appropriate.
Definition reporter.h:270
void SetVerbose(bool aVerbose)
Enable or disable verbose mode.
Definition reporter.h:284
virtual ~CLI_REPORTER()
Definition reporter.h:276
bool m_verbose
Definition reporter.h:291
bool GetVerbose() const
Definition reporter.h:286
FONTCONFIG_REPORTER_SCOPE(REPORTER *aReporter)
Definition reporter.cpp:343
REPORTER * m_previousReporter
Definition reporter.h:374
LOAD_INFO_REPORTER_SCOPE(REPORTER *aReporter)
Definition reporter.cpp:329
LOAD_INFO_REPORTER & m_reporter
Definition reporter.h:356
REPORTER * m_previousReporter
Definition reporter.h:357
REPORTER * m_redirectTarget
Definition reporter.h:345
virtual ~LOAD_INFO_REPORTER()
Definition reporter.h:334
virtual ~NULL_REPORTER()
Definition reporter.h:255
REPORTER * m_redirectTarget
Definition reporter.h:385
REDIRECT_REPORTER(REPORTER *aRedirectTarget)
Definition reporter.h:381
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:72
virtual EDA_UNITS GetUnits() const
Definition reporter.h:147
int m_reportedSeverityMask
Definition reporter.h:158
LOCATION
Location where the message is to be reported.
Definition reporter.h:87
@ LOC_BODY
Definition reporter.h:89
@ LOC_TAIL
Definition reporter.h:90
@ LOC_HEAD
Definition reporter.h:88
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:120
virtual void Clear()
Definition reporter.h:152
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:101
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:111
virtual bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
Definition reporter.h:142
virtual ~REPORTER()
Definition reporter.h:78
REPORTER()
Definition reporter.h:74
virtual bool HasMessage() const
Returns true if any messages were reported.
Definition reporter.h:133
STATUSBAR_REPORTER(wxStatusBar *aStatusBar, int aPosition=0)
Definition reporter.h:395
wxStatusBar * m_statusBar
Definition reporter.h:404
STATUSBAR_WARNING_REPORTER(KISTATUSBAR *aStatusBar, const wxString &aSource)
Definition reporter.cpp:382
~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:392
std::shared_ptr< STATUSBAR_WARNING_REPORTER_IMPL > m_impl
Definition reporter.h:418
virtual ~STDOUT_REPORTER()
Definition reporter.h:304
SYNC_REPORTER(REPORTER &aReporter)
Definition reporter.h:173
std::mutex m_mutex
Definition reporter.h:193
REPORTER & m_reporter
Definition reporter.h:192
virtual ~WXLOG_REPORTER()
Definition reporter.h:319
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:77
wxString m_string
Definition reporter.h:240
virtual ~WX_STRING_REPORTER()
Definition reporter.h:231
virtual ~WX_TEXT_CTRL_REPORTER()
Definition reporter.h:209
wxTextCtrl * m_textCtrl
Definition reporter.h:217
WX_TEXT_CTRL_REPORTER(wxTextCtrl *aTextCtrl)
Definition reporter.h:203
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