STYLE: can add compile-time deprecated message for autoPtr::set()

- deprecated Feb-2018, but not marked as such.

  The set() method originally enforce an additional run-time check
  (Fatal if pointer was already set), but this was rarely used.
  In fact, the set() method was invariably used in constructors
  where the pointer by definition was unset.

  Can now mark as deprecated to catch the last of these.
  We prefer reset() for similarity with std::unique_ptr

  Eg,
  FOAM_EXTRA_CXXFLAGS="-DFoam_autoPtr_deprecate_setMethod"  wmake
This commit is contained in:
Mark Olesen 2020-11-19 12:40:47 +01:00
parent 07bbae0c55
commit 6e3bc1f7d0
13 changed files with 61 additions and 39 deletions

View File

@ -25,6 +25,8 @@ License
\*---------------------------------------------------------------------------*/
// #define Foam_autoPtr_deprecate_setMethod
#include <memory>
#include "autoPtr.H"
#include "labelList.H"
@ -236,6 +238,11 @@ int main(int argc, char *argv[])
// Does compile (good!): ptr1 = nullptr;
ptr1.reset(std::move(ptr2));
autoPtr<labelList> ptr3;
// set() method - deprecated warning?
ptr3.set(ptr1.release());
}

View File

@ -1087,7 +1087,16 @@ void Foam::Time::setDeltaT(const scalar deltaT, const bool adjust)
Foam::TimeState Foam::Time::subCycle(const label nSubCycles)
{
prevTimeState_.set(new TimeState(*this)); // Fatal if already set
#ifdef FULLDEBUG
if (prevTimeState_)
{
FatalErrorInFunction
<< "previous time state already set" << nl
<< exit(FatalError);
}
#endif
prevTimeState_.reset(new TimeState(*this));
setTime(*this - deltaT(), (timeIndex() - 1)*nSubCycles);
deltaT_ /= nSubCycles;
@ -1118,7 +1127,7 @@ void Foam::Time::endSubCycle()
if (subCycling_)
{
TimeState::operator=(prevTimeState());
prevTimeState_.clear();
prevTimeState_.reset(nullptr);
}
subCycling_ = 0;

View File

@ -288,7 +288,7 @@ Foam::GAMGSolver::GAMGSolver
}
else if (matrixLevels_[coarsestLevel].asymmetric())
{
coarsestSolverPtr_.set
coarsestSolverPtr_.reset
(
new PBiCGStab
(
@ -303,7 +303,7 @@ Foam::GAMGSolver::GAMGSolver
}
else
{
coarsestSolverPtr_.set
coarsestSolverPtr_.reset
(
new PCG
(

View File

@ -49,6 +49,7 @@ SourceFiles
// Transitional features/misfeatures
#define Foam_autoPtr_copyConstruct
#define Foam_autoPtr_castOperator
// #define Foam_autoPtr_deprecate_setMethod
#include "stdFoam.H"
@ -163,7 +164,7 @@ public:
//- Return reference to the managed object without nullptr checking.
// When get() == nullptr, additional guards may be required to avoid
// inadvertent access to a nullptr.
// inadvertent access of a nullptr.
T& ref() { return *ptr_; }
@ -274,6 +275,9 @@ public:
// enforced a run-time check (Fatal if pointer was already set)
// but this was rarely used.
// \deprecated(2018-02) Identical to reset().
#ifdef Foam_autoPtr_deprecate_setMethod
FOAM_DEPRECATED_FOR(2018-02, "reset() - same behaviour")
#endif
void set(T* p) noexcept { reset(p); }
//- Deprecated(2018-02) No copy assignment from plain pointer

View File

@ -348,7 +348,7 @@ bool Foam::processorCyclicPolyPatch::order
UIPstream fromNeighbour(neighbProcNo(), pBufs);
fromNeighbour >> masterPts >> masterFaces;
SubList<face> fcs(masterFaces, masterFaces.size());
masterPtr.set(new primitivePatch(fcs, masterPts));
masterPtr.reset(new primitivePatch(fcs, masterPts));
}
const cyclicPolyPatch& cycPatch =

View File

@ -88,9 +88,9 @@ Foam::functionObjects::columnAverage::meshAddressing(const polyMesh& mesh) const
mesh.points()
);
globalFaces_.set(new globalIndex(uip.size()));
globalEdges_.set(new globalIndex(uip.nEdges()));
globalPoints_.set(new globalIndex(uip.nPoints()));
globalFaces_.reset(new globalIndex(uip.size()));
globalEdges_.reset(new globalIndex(uip.nEdges()));
globalPoints_.reset(new globalIndex(uip.nPoints()));
meshStructurePtr_.reset
(
new meshStructure

View File

@ -85,8 +85,8 @@ bool Foam::functionObjects::surfaceDistance::read
doCells_ = dict.getOrDefault("calculateCells", true);
geomPtr_.clear();
geomPtr_.set
geomPtr_.reset(nullptr);
geomPtr_.reset
(
new searchableSurfaces
(

View File

@ -3098,9 +3098,9 @@ void Foam::distributedTriSurfaceMesh::findNearest
{
sendMap[proci].transfer(dynSendMap[proci]);
}
map1Ptr.set(new mapDistribute(std::move(sendMap)));
map1Ptr.reset(new mapDistribute(std::move(sendMap)));
}
const mapDistribute& map1 = map1Ptr();
const mapDistribute& map1 = *map1Ptr;
if (debug)
@ -4116,9 +4116,9 @@ void Foam::distributedTriSurfaceMesh::getVolumeType
}
}
mapPtr.set(new mapDistribute(std::move(sendMap)));
mapPtr.reset(new mapDistribute(std::move(sendMap)));
}
const mapDistribute& map = mapPtr();
const mapDistribute& map = *mapPtr;
// Get the points I need to test
pointField localPoints(samples);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,6 +28,7 @@ License
#include "PurePhaseModel.H"
#include "phaseSystem.H"
#include "basicThermo.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class BasePhaseModel, class phaseThermo>
@ -39,14 +40,14 @@ Foam::PurePhaseModel<BasePhaseModel, phaseThermo>::PurePhaseModel
:
BasePhaseModel(fluid, phaseName)
{
thermoPtr_.set
thermoPtr_.reset
(
phaseThermo::New
(
fluid.mesh(),
phaseName,
basicThermo::phasePropertyName(basicThermo::dictName, phaseName)
).ptr()
)
);
}

View File

@ -212,7 +212,7 @@ void Foam::phaseSystem::generatePairsAndSubModels
<< exit(FatalError);
}
models[key][pair.index(phase)].set(tempModelIter().ptr());
models[key][pair.index(phase)].reset(tempModelIter().ptr());
}
}
}

View File

@ -953,7 +953,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
if (coalescence_.size() != 0)
{
coalescenceRate_.set
coalescenceRate_.reset
(
new volScalarField
(
@ -971,7 +971,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
if (breakup_.size() != 0)
{
breakupRate_.set
breakupRate_.reset
(
new volScalarField
(
@ -989,7 +989,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
if (binaryBreakup_.size() != 0)
{
binaryBreakupRate_.set
binaryBreakupRate_.reset
(
new volScalarField
(
@ -1012,7 +1012,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
if (drift_.size() != 0)
{
driftRate_.set
driftRate_.reset
(
new volScalarField
(
@ -1027,7 +1027,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
)
);
rx_.set
rx_.reset
(
new volScalarField
(
@ -1042,7 +1042,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
)
);
rdx_.set
rdx_.reset
(
new volScalarField
(
@ -1060,7 +1060,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
if (nucleation_.size() != 0)
{
nucleationRate_.set
nucleationRate_.reset
(
new volScalarField
(
@ -1083,7 +1083,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
if (velocityGroups_.size() > 1)
{
alphas_.set
alphas_.reset
(
new volScalarField
(
@ -1100,7 +1100,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
)
);
dsm_.set
dsm_.reset
(
new volScalarField
(
@ -1117,7 +1117,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
)
);
U_.set
U_.reset
(
new volVectorField
(
@ -1141,6 +1141,7 @@ Foam::diameterModels::populationBalanceModel::populationBalanceModel
Foam::diameterModels::populationBalanceModel::~populationBalanceModel()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::diameterModels::populationBalanceModel>

View File

@ -136,7 +136,7 @@ Foam::twoPhaseSystem::twoPhaseSystem
phasePair::scalarTable sigmaTable(lookup("sigma"));
phasePair::dictTable aspectRatioTable(lookup("aspectRatio"));
pair_.set
pair_.reset
(
new phasePair
(
@ -147,7 +147,7 @@ Foam::twoPhaseSystem::twoPhaseSystem
)
);
pair1In2_.set
pair1In2_.reset
(
new orderedPhasePair
(
@ -159,7 +159,7 @@ Foam::twoPhaseSystem::twoPhaseSystem
)
);
pair2In1_.set
pair2In1_.reset
(
new orderedPhasePair
(
@ -174,7 +174,7 @@ Foam::twoPhaseSystem::twoPhaseSystem
// Models
drag_.set
drag_.reset
(
new BlendedInterfacialModel<dragModel>
(
@ -191,7 +191,7 @@ Foam::twoPhaseSystem::twoPhaseSystem
)
);
virtualMass_.set
virtualMass_.reset
(
new BlendedInterfacialModel<virtualMassModel>
(
@ -207,7 +207,7 @@ Foam::twoPhaseSystem::twoPhaseSystem
)
);
heatTransfer_.set
heatTransfer_.reset
(
new BlendedInterfacialModel<heatTransferModel>
(
@ -223,7 +223,7 @@ Foam::twoPhaseSystem::twoPhaseSystem
)
);
lift_.set
lift_.reset
(
new BlendedInterfacialModel<liftModel>
(
@ -239,7 +239,7 @@ Foam::twoPhaseSystem::twoPhaseSystem
)
);
wallLubrication_.set
wallLubrication_.reset
(
new BlendedInterfacialModel<wallLubricationModel>
(
@ -255,7 +255,7 @@ Foam::twoPhaseSystem::twoPhaseSystem
)
);
turbulentDispersion_.set
turbulentDispersion_.reset
(
new BlendedInterfacialModel<turbulentDispersionModel>
(

View File

@ -111,7 +111,7 @@ Foam::radiation::wideBandAbsorptionEmission::wideBandAbsorptionEmission
&& "none" != coeffsDict_.get<word>("lookUpTableFileName")
)
{
lookUpTablePtr_.set
lookUpTablePtr_.reset
(
new interpolationLookUpTable<scalar>
(