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 
76 REPORTER& WX_HTML_PANEL_REPORTER::ReportTail( const wxString& aText, SEVERITY aSeverity )
77 {
78  wxCHECK_MSG( m_panel != NULL, *this,
79  wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
80 
81  m_panel->Report( aText, aSeverity, LOC_TAIL );
82  return *this;
83 }
84 
85 REPORTER& WX_HTML_PANEL_REPORTER::ReportHead( const wxString& aText, SEVERITY aSeverity )
86 {
87  wxCHECK_MSG( m_panel != NULL, *this,
88  wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
89 
90  m_panel->Report( aText, aSeverity, LOC_HEAD );
91  return *this;
92 }
93 
95 {
96  return m_panel->Count( REPORTER::RPT_ERROR | REPORTER::RPT_WARNING ) > 0;
97 }
98 
99 REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
100 {
101  return *this;
102 }
103 
105 {
106  static REPORTER* s_nullReporter = NULL;
107 
108  if( !s_nullReporter )
109  {
110  s_nullReporter = new NULL_REPORTER();
111  }
112 
113  return *s_nullReporter;
114 }
115 
116 
117 REPORTER& STDOUT_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
118 {
119  switch( aSeverity )
120  {
121  case RPT_UNDEFINED: std::cout << "RPT_UNDEFINED: "; break;
122  case RPT_INFO: std::cout << "RPT_INFO: "; break;
123  case RPT_WARNING: std::cout << "RPT_WARNING: "; break;
124  case RPT_ERROR: std::cout << "RPT_ERROR: "; break;
125  case RPT_ACTION: std::cout << "RPT_ACTION: "; break;
126  }
127 
128  std::cout << aText << std::endl;
129 
130  return *this;
131 }
132 
133 
135 {
136  static REPORTER* s_stdoutReporter = nullptr;
137 
138  if( !s_stdoutReporter )
139  {
140  s_stdoutReporter = new STDOUT_REPORTER();
141  }
142 
143  return *s_stdoutReporter;
144 }
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
REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED) override
Function ReportHead Places the report at the beginning of the list for objects that support ordering...
Definition: reporter.cpp:85
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:94
Class STDOUT_REPORTER.
Definition: reporter.h:229
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:210
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
REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED) override
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.cpp:76
SEVERITY
Severity of the reported messages.
Definition: reporter.h:74
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:117
static REPORTER & GetInstance()
Definition: reporter.cpp:134
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:104