UCL / UCL/STIR

Returning shared_ptr<T> for methods marked const

Open
#484 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
160
Forks
113
Avg merge
12d 15h
Merged PRs (30d)
1

Description

Some methods are marked const, implying you can't modify the object. However, in a few places we return a non-const shared_ptr, which means the returned object can then be modified, and the original const object, too. If returning a class member (e.g., get_scanner_sptr), we should be returning shared_ptr<const T> if the method is marked const.

Follows from #480, #481 and #487. (KT edited after #481 updates)

List of problematic methods:

src/include/stir/ProjDataInfo.h:  inline shared_ptr<Scanner> get_scanner_sptr() const;
src/include/stir/RelatedViewgrams.h:  inline shared_ptr<DataSymmetriesForViewSegmentNumbers> get_symmetries_sptr() const;
src/include/stir/recon_buildblock/ProjMatrixByBin.h:  inline const shared_ptr<DataSymmetriesForBins> get_symmetries_sptr() const;
 
src/include/stir_experimental/recon_buildblock/ParametricQuadraticPrior.h:  shared_ptr<TargetT > get_kappa_sptr() const;
 
src/include/stir/recon_buildblock/BinNormalisation.h:             shared_ptr<DataSymmetriesForViewSegmentNumbers> = shared_ptr<DataSymmetriesForViewSegmentNumbers>()) const;
src/include/stir/recon_buildblock/BinNormalisation.h:            shared_ptr<DataSymmetriesForViewSegmentNumbers> = shared_ptr<DataSymmetriesForViewSegmentNumbers>()) const; 
src/include/stir/recon_buildblock/ProjectorByBinPairUsingProjMatrixByBin.h:  shared_ptr<ProjMatrixByBin> get_proj_matrix_sptr() const;
 
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData.h:  const shared_ptr<DynamicProjData>& get_dyn_proj_data_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData.h:  const shared_ptr<DynamicProjData>& get_additive_dyn_proj_data_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData.h:  const shared_ptr<ProjectorByBinPair>& get_projector_pair_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearKineticModelAndDynamicProjectionData.h:  const shared_ptr<BinNormalisation>& get_normalisation_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:  const shared_ptr<ProjData>& get_proj_data_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:  const shared_ptr<ProjData>& get_additive_proj_data_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:  const shared_ptr<ProjectorByBinPair>& get_projector_pair_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMeanAndProjData.h:  const shared_ptr<BinNormalisation>& get_normalisation_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion.h:  const shared_ptr<GatedProjData>& get_gated_proj_data_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion.h:  const shared_ptr<GatedProjData>& get_additive_gated_proj_data_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion.h:  const shared_ptr<GatedProjData>& get_normalisation_gated_proj_data_sptr() const;
src/include/stir/recon_buildblock/PoissonLogLikelihoodWithLinearModelForMeanAndGatedProjDataWithMotion.h:  const shared_ptr<ProjectorByBinPair>& get_projector_pair_sptr() const;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the listed declarations in the src/include/stir and src/include/stir_experimental headers, along with the related changes in issues #480, #481, and #487. Check each const accessor and complete the work when the listed methods no longer expose mutable shared objects through const instances, with the project still compiling successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.