diff --git a/common/jobs/jobset.cpp b/common/jobs/jobset.cpp index 41d79c26c5..819308ea17 100644 --- a/common/jobs/jobset.cpp +++ b/common/jobs/jobset.cpp @@ -135,15 +135,6 @@ JOBSET_DESTINATION::JOBSET_DESTINATION( const wxString& id, JOBSET_DESTINATION_T } -JOBSET_DESTINATION::~JOBSET_DESTINATION() -{ - for( auto& [name, reporter] : m_lastRunReporters ) - delete reporter; - - m_lastRunReporters.clear(); -} - - void JOBSET_DESTINATION::InitOutputHandler() { if( m_type == JOBSET_DESTINATION_T::FOLDER ) diff --git a/common/jobs/jobset.h b/common/jobs/jobset.h index d0c25a5d5e..8d7771b510 100644 --- a/common/jobs/jobset.h +++ b/common/jobs/jobset.h @@ -21,15 +21,52 @@ #ifndef JOBS_FILE_H #define JOBS_FILE_H +#include #include #include #include #include #include +#include #include #include -class REPORTER; + +class JOBSET_OUTPUT_REPORTER : public WX_STRING_REPORTER +{ +public: + JOBSET_OUTPUT_REPORTER( const wxString& aTempDirPath, PROGRESS_REPORTER* aProgressReporter ) : + m_tempDirPath( aTempDirPath ), + m_progressReporter( aProgressReporter ) + { + } + + REPORTER& Report( const wxString& aText, SEVERITY aSeverity ) override + { + wxString text( aText ); + + if( aSeverity == RPT_SEVERITY_DEBUG && !m_includeDebug ) + return *this; + + if( aSeverity == RPT_SEVERITY_ACTION ) + text.Replace( m_tempDirPath, wxEmptyString ); + + if( m_progressReporter ) + { + m_progressReporter->Report( text ); + m_progressReporter->KeepRefreshing(); + } + + return WX_STRING_REPORTER::Report( text, aSeverity ); + } + +private: + wxString m_tempDirPath; + bool m_includeDebug; + PROGRESS_REPORTER* m_progressReporter; +}; + + struct KICOMMON_API JOBSET_JOB { @@ -79,26 +116,24 @@ struct KICOMMON_API JOBSET_DESTINATION JOBSET_DESTINATION( const wxString& id, JOBSET_DESTINATION_T type ); - ~JOBSET_DESTINATION(); + void InitOutputHandler(); - void InitOutputHandler(); + wxString GetDescription() const; + void SetDescription( const wxString& aDescription ); + bool operator==( const JOBSET_DESTINATION& rhs ) const; + +public: wxString m_id; JOBSET_DESTINATION_T m_type; wxString m_description; std::shared_ptr m_outputHandler; std::vector m_only; - wxString GetDescription() const; - void SetDescription( const wxString& aDescription ); - ///< Transient property, not stored for now - std::optional m_lastRunSuccess; - std::unordered_map> m_lastRunSuccessMap; - std::unordered_map m_lastRunReporters; - - bool operator==( const JOBSET_DESTINATION& rhs ) const; - + std::optional m_lastRunSuccess; + std::unordered_map> m_lastRunSuccessMap; + std::unordered_map> m_lastRunReporters; }; diff --git a/kicad/dialogs/panel_jobset.cpp b/kicad/dialogs/panel_jobset.cpp index 6a381b5b0f..565034b40a 100644 --- a/kicad/dialogs/panel_jobset.cpp +++ b/kicad/dialogs/panel_jobset.cpp @@ -147,17 +147,9 @@ public: wxString jobId = jobs[itemIndex].m_id; if( m_destination->m_lastRunReporters.contains( jobId ) ) - { - WX_STRING_REPORTER* reporter = - static_cast( m_destination->m_lastRunReporters[jobId] ); - - if( reporter ) - m_textCtrlOutput->SetValue( reporter->GetMessages() ); - } + m_textCtrlOutput->SetValue( m_destination->m_lastRunReporters.at( jobId )->GetMessages() ); else - { m_textCtrlOutput->SetValue( _( "No output messages" ) ); - } } } diff --git a/kicad/jobs_runner.cpp b/kicad/jobs_runner.cpp index 2e274976a8..faee60f190 100644 --- a/kicad/jobs_runner.cpp +++ b/kicad/jobs_runner.cpp @@ -134,41 +134,6 @@ int JOBS_RUNNER::runSpecialCopyFiles( const JOBSET_JOB* aJob, PROJECT* aProject } -class JOBSET_OUTPUT_REPORTER : public WX_STRING_REPORTER -{ -public: - JOBSET_OUTPUT_REPORTER( const wxString& aTempDirPath, PROGRESS_REPORTER* aProgressReporter ) : - m_tempDirPath( aTempDirPath ), - m_progressReporter( aProgressReporter ) - { - } - - REPORTER& Report( const wxString& aText, SEVERITY aSeverity ) override - { - wxString text( aText ); - - if( aSeverity == RPT_SEVERITY_DEBUG && !m_includeDebug ) - return *this; - - if( aSeverity == RPT_SEVERITY_ACTION ) - text.Replace( m_tempDirPath, wxEmptyString ); - - if( m_progressReporter ) - { - m_progressReporter->Report( text ); - m_progressReporter->KeepRefreshing(); - } - - return WX_STRING_REPORTER::Report( text, aSeverity ); - } - -private: - wxString m_tempDirPath; - bool m_includeDebug; - PROGRESS_REPORTER* m_progressReporter; -}; - - bool JOBS_RUNNER::RunJobsForDestination( JOBSET_DESTINATION* aDestination, bool aBail ) { bool genOutputs = true; @@ -181,10 +146,6 @@ bool JOBS_RUNNER::RunJobsForDestination( JOBSET_DESTINATION* aDestination, bool tmp.AppendDir( KIID().AsString() ); aDestination->m_lastRunSuccessMap.clear(); - - for( auto& [name, reporter] : aDestination->m_lastRunReporters ) - delete reporter; - aDestination->m_lastRunReporters.clear(); wxString tempDirPath = tmp.GetFullPath(); @@ -269,8 +230,9 @@ bool JOBS_RUNNER::RunJobsForDestination( JOBSET_DESTINATION* aDestination, bool if( reporterToUse == &NULL_REPORTER::GetInstance() ) { - reporterToUse = new JOBSET_OUTPUT_REPORTER( tempDirPath, m_progressReporter ); - aDestination->m_lastRunReporters[job.m_id] = reporterToUse; + aDestination->m_lastRunReporters[job.m_id] = std::make_shared( tempDirPath, + m_progressReporter ); + reporterToUse = aDestination->m_lastRunReporters[job.m_id].get(); } int result = CLI::EXIT_CODES::SUCCESS;