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.

158 lines
4.6 KiB

13 years ago
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. /**
  35. * Class REPORTER
  36. * is a pure virtual class used to derive REPORTER objects from.
  37. *
  38. * The purpose of the REPORTER object is to offer a way for a procedural function
  39. * to report multiple errors without having to:
  40. * <ul>
  41. * <li> know too much about the caller's UI, i.e. wx. </li>
  42. * <li> stop after the first error </li>
  43. * </ul>
  44. * the reporter has 3 levels (flags) for filtering:
  45. * no filter
  46. * report warning
  47. * report errors
  48. * They are indicators for the calling code, filtering is not made here
  49. */
  50. class REPORTER
  51. {
  52. bool m_reportAll; // Filter flag: set to true to report all messages
  53. bool m_reportWarnings; // Filter flag: set to true to report warning
  54. bool m_reportErrors; // Filter flag: set to true to report errors
  55. public:
  56. /**
  57. * Function Report
  58. * is a pure virtual function to override in the derived object.
  59. *
  60. * @param aText is the string to report.
  61. */
  62. virtual REPORTER& Report( const wxString& aText ) = 0;
  63. REPORTER& Report( const char* aText );
  64. REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
  65. REPORTER& operator <<( const wxChar* aText ) { return Report( wxString( aText ) ); }
  66. REPORTER& operator <<( wxChar aChar ) { return Report( wxString( aChar ) ); }
  67. REPORTER& operator <<( const char* aText ) { return Report( aText ); }
  68. /**
  69. * Returns true if all messages should be reported
  70. */
  71. bool ReportAll() { return m_reportAll; }
  72. /**
  73. * Returns true if all messages or warning messages should be reported
  74. */
  75. bool ReportWarnings() { return m_reportAll | m_reportWarnings; }
  76. /**
  77. * Returns true if all messages or error messages should be reported
  78. */
  79. bool ReportErrors() { return m_reportAll | m_reportErrors; }
  80. /**
  81. * Set the report filter state, for all messages
  82. * @param aEnable = filter state (true/false)
  83. */
  84. void SetReportAll( bool aEnable) { m_reportAll = aEnable; }
  85. /**
  86. * Set the report filter state, for warning messages
  87. * note: report can be disable only if m_reportAll = false
  88. * @param aEnable = filter state (true/false)
  89. */
  90. void SetReportWarnings( bool aEnable) { m_reportWarnings = aEnable; }
  91. /**
  92. * Set the report filter state, for error messages
  93. * note: report can be disable only if m_reportAll = false
  94. * @param aEnable = filter state (true/false)
  95. */
  96. void SetReportErrors( bool aEnable) { m_reportErrors = aEnable; }
  97. };
  98. /**
  99. * Class WX_TEXT_CTRL_REPORTER
  100. * is wrapper for reporting to a wxTextCtrl object.
  101. */
  102. class WX_TEXT_CTRL_REPORTER : public REPORTER
  103. {
  104. wxTextCtrl* m_textCtrl;
  105. public:
  106. WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
  107. REPORTER(),
  108. m_textCtrl( aTextCtrl )
  109. {
  110. SetReportAll( true );
  111. SetReportWarnings( true );
  112. SetReportErrors( true );
  113. }
  114. REPORTER& Report( const wxString& aText );
  115. };
  116. /**
  117. * Class WX_STRING_REPROTER
  118. * is a wrapper for reporting to a wxString object.
  119. */
  120. class WX_STRING_REPORTER : public REPORTER
  121. {
  122. wxString* m_string;
  123. public:
  124. WX_STRING_REPORTER( wxString* aString ) :
  125. REPORTER(),
  126. m_string( aString )
  127. {
  128. }
  129. REPORTER& Report( const wxString& aText );
  130. };
  131. #endif // _REPORTER_H_