[PATCH rtems-tools v1] ReportsBase: Change raw pointer to unique_ptr

Chris Johns chrisj at rtems.org
Mon Dec 20 23:03:12 UTC 2021



On 21/12/21 7:24 am, Ryan Long wrote:
> Replaced raw pointer used with ReportsBase-derived classes to make code
> cleaner and make it to where pointers do not have to be manually
> deleted.
> 
> Closes #4376
> ---
>  tester/covoar/ReportsBase.cc | 21 ++++++---------------
>  1 file changed, 6 insertions(+), 15 deletions(-)
> 
> diff --git a/tester/covoar/ReportsBase.cc b/tester/covoar/ReportsBase.cc
> index 219e5af..8ec65c0 100644
> --- a/tester/covoar/ReportsBase.cc
> +++ b/tester/covoar/ReportsBase.cc
> @@ -591,17 +591,16 @@ void GenerateReports(
>    bool                            branchInfoAvailable
>  )
>  {
> -  typedef std::list<ReportsBase *> reportList_t;
> +  typedef std::vector<std::unique_ptr<ReportsBase>> reportList_t;

Are we OK to use `*_t` in types?

Plus I have moved to ...

using reportList = std::vector<std::unique_ptr<ReportsBase>>

so I would use the following to avoid '>>':

using reportList_ptr = std::unique_ptr<ReportsBase>;
using reportLists = std::vector<reportList_ptr>;

The vector is a container of report lists and not a container of report list
singular.

A minor point, I do not embed the container type into the type alias because
someone may decide to change this to `std::deque` or `std::forward_list` and the
name becomes misleading.

>    reportList_t           reportList;

Then make this `reports`.

>    reportList_t::iterator ritr;
>    std::string            reportName;
> -  ReportsBase*           reports;
>    time_t                 timestamp;
>  
>  
>    timestamp = time( NULL ); /* get current cal time */
> -  reports = new ReportsText(
> +  reportList.emplace_back(new ReportsText(

Should `std::make_unique<ReportsText>(...)` be used?

Thanks
Chris

>      timestamp,
>      symbolSetName,
>      allExplanations,
> @@ -609,9 +608,8 @@ void GenerateReports(
>      outputDirectory,
>      symbolsToAnalyze,
>      branchInfoAvailable
> -  );
> -  reportList.push_back( reports );
> -  reports = new ReportsHtml(
> +  ));
> +  reportList.emplace_back(new ReportsHtml(
>      timestamp,
>      symbolSetName,
>      allExplanations,
> @@ -619,11 +617,9 @@ void GenerateReports(
>      outputDirectory,
>      symbolsToAnalyze,
>      branchInfoAvailable
> -  );
> -  reportList.push_back( reports );
> +  ));
>  
> -  for ( ritr = reportList.begin(); ritr != reportList.end(); ritr++ ) {
> -    reports = *ritr;
> +  for ( auto& reports: reportList ) {
>  
>      reportName = "index" + reports->ReportExtension();
>      if ( verbose ) {
> @@ -662,11 +658,6 @@ void GenerateReports(
>      reports->WriteSymbolSummaryReport( reportName, symbolsToAnalyze );
>    }
>  
> -  for ( ritr = reportList.begin(); ritr != reportList.end(); ritr++ ) {
> -    reports = *ritr;
> -    delete reports;
> -  }
> -
>    ReportsBase::WriteSummaryReport(
>      "summary.txt",
>      symbolSetName,


More information about the devel mailing list