KiCad PCB EDA Suite
reporter.cpp
Go to the documentation of this file.
1 
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
8  * Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <macros.h>
29 #include <reporter.h>
30 #include <wx_html_report_panel.h>
31 
32 REPORTER& REPORTER::Report( const char* aText, REPORTER::SEVERITY aSeverity )
33 {
34  Report( FROM_UTF8( aText ) );
35  return *this;
36 }
37 
38 
39 REPORTER& WX_TEXT_CTRL_REPORTER::Report( const wxString& aText, REPORTER::SEVERITY aSeverity )
40 {
41  wxCHECK_MSG( m_textCtrl != NULL, *this,
42  wxT( "No wxTextCtrl object defined in WX_TEXT_CTRL_REPORTER." ) );
43 
44  m_textCtrl->AppendText( aText );
45  return *this;
46 }
47 
49 {
50  return !m_textCtrl->IsEmpty();
51 }
52 
53 REPORTER& WX_STRING_REPORTER::Report( const wxString& aText, REPORTER::SEVERITY aSeverity )
54 {
55  wxCHECK_MSG( m_string != NULL, *this,
56  wxT( "No wxString object defined in WX_STRING_REPORTER." ) );
57 
58  *m_string << aText;
59  return *this;
60 }
61 
63 {
64  return !m_string->IsEmpty();
65 }
66 
67 REPORTER& WX_HTML_PANEL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
68 {
69  wxCHECK_MSG( m_panel != NULL, *this,
70  wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
71 
72  m_panel->Report( aText, aSeverity );
73  return *this;
74 }
75 
77 {
78  return m_panel->Count( REPORTER::RPT_ERROR | REPORTER::RPT_WARNING ) > 0;
79 }
80 
81 REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
82 {
83  return *this;
84 }
85 
87 {
88  static REPORTER* s_nullReporter = NULL;
89 
90  if( !s_nullReporter )
91  {
92  s_nullReporter = new NULL_REPORTER();
93  }
94 
95  return *s_nullReporter;
96 }
97 
98 
99 REPORTER& STDOUT_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
100 {
101  switch( aSeverity )
102  {
103  case RPT_UNDEFINED: std::cout << "RPT_UNDEFINED: "; break;
104  case RPT_INFO: std::cout << "RPT_INFO: "; break;
105  case RPT_WARNING: std::cout << "RPT_WARNING: "; break;
106  case RPT_ERROR: std::cout << "RPT_ERROR: "; break;
107  case RPT_ACTION: std::cout << "RPT_ACTION: "; break;
108  }
109 
110  std::cout << aText << std::endl;
111 
112  return *this;
113 }
114 
115 
117 {
118  static REPORTER* s_stdoutReporter = nullptr;
119 
120  if( !s_stdoutReporter )
121  {
122  s_stdoutReporter = new STDOUT_REPORTER();
123  }
124 
125  return *s_stdoutReporter;
126 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:76
Class STDOUT_REPORTER.
Definition: reporter.h:186
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.cpp:62
This file contains miscellaneous commonly used macros and functions.
Class NULL_REPORTER.
Definition: reporter.h:167
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:81
SEVERITY
Severity of the reported messages.
Definition: reporter.h:65
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:53
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:67
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:99
static REPORTER & GetInstance()
Definition: reporter.cpp:116
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:39
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_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:48
static REPORTER & GetInstance()
Definition: reporter.cpp:86