You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
4.4 KiB

13 years ago
13 years ago
13 years ago
  1. #ifndef _REPORTER_H_
  2. #define _REPORTER_H_
  3. /**
  4. * @file reporter.h
  5. * @author Wayne Stambaugh
  6. * @note A special thanks to Dick Hollenbeck who came up with the idea that inspired
  7. * me to write this.
  8. */
  9. /*
  10. * This program source code file is part of KiCad, a free EDA CAD application.
  11. *
  12. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
  13. * Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version 2
  18. * of the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, you may find one here:
  27. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  28. * or you may search the http://www.gnu.org website for the version 2 license,
  29. * or you may write to the Free Software Foundation, Inc.,
  30. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  31. */
  32. class wxString;
  33. class wxTextCtrl;
  34. class wxHtmlListbox;
  35. class WX_HTML_REPORT_PANEL;
  36. /**
  37. * Class REPORTER
  38. * is a pure virtual class used to derive REPORTER objects from.
  39. *
  40. * The purpose of the REPORTER object is to offer a way for a procedural function
  41. * to report multiple errors without having to:
  42. * <ul>
  43. * <li> know too much about the caller's UI, i.e. wx. </li>
  44. * <li> stop after the first error </li>
  45. * </ul>
  46. * the reporter has 4 severity levels (flags) tagging the messages:
  47. * - information
  48. * - warning
  49. * - error
  50. * - action (i.e. indication of changes - add component, change footprint, etc. )
  51. * They are indicators for the message formatting and displaying code,
  52. * filtering is not made here.
  53. */
  54. class REPORTER {
  55. public:
  56. ///> Severity of the reported messages.
  57. enum SEVERITY {
  58. RPT_UNDEFINED = 0x0,
  59. RPT_INFO = 0x1,
  60. RPT_WARNING = 0x2,
  61. RPT_ERROR = 0x4,
  62. RPT_ACTION = 0x8
  63. };
  64. /**
  65. * Function Report
  66. * is a pure virtual function to override in the derived object.
  67. *
  68. * @param aText is the string to report.
  69. */
  70. virtual REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED ) = 0;
  71. REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_UNDEFINED );
  72. REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
  73. REPORTER& operator <<( const wxChar* aText ) { return Report( wxString( aText ) ); }
  74. REPORTER& operator <<( wxChar aChar ) { return Report( wxString( aChar ) ); }
  75. REPORTER& operator <<( const char* aText ) { return Report( aText ); }
  76. };
  77. /**
  78. * Class WX_TEXT_CTRL_REPORTER
  79. * is wrapper for reporting to a wxTextCtrl object.
  80. */
  81. class WX_TEXT_CTRL_REPORTER : public REPORTER
  82. {
  83. wxTextCtrl* m_textCtrl;
  84. public:
  85. WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
  86. REPORTER(),
  87. m_textCtrl( aTextCtrl )
  88. {
  89. }
  90. REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED );
  91. };
  92. /**
  93. * Class WX_STRING_REPORTER
  94. * is a wrapper for reporting to a wxString object.
  95. */
  96. class WX_STRING_REPORTER : public REPORTER
  97. {
  98. wxString* m_string;
  99. public:
  100. WX_STRING_REPORTER( wxString* aString ) :
  101. REPORTER(),
  102. m_string( aString )
  103. {
  104. }
  105. REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED );
  106. };
  107. /**
  108. * Class WX_HTML_PANEL_REPORTER
  109. * is a wrapper for reporting to a wx HTML window
  110. */
  111. class WX_HTML_PANEL_REPORTER : public REPORTER
  112. {
  113. WX_HTML_REPORT_PANEL* m_panel;
  114. public:
  115. WX_HTML_PANEL_REPORTER( WX_HTML_REPORT_PANEL* aPanel ) :
  116. REPORTER(),
  117. m_panel( aPanel )
  118. {
  119. }
  120. REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED );
  121. };
  122. /**
  123. * Class NULL_REPORTER
  124. *
  125. * A singleton reporter that reports to nowhere. Used as to simplify code by
  126. * avoiding the reportee to check for a non-NULL reporter object.
  127. */
  128. class NULL_REPORTER : public REPORTER
  129. {
  130. public:
  131. NULL_REPORTER()
  132. {
  133. };
  134. static REPORTER& GetInstance();
  135. REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_UNDEFINED );
  136. };
  137. #endif // _REPORTER_H_