mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: avoid memory leaks for HashPtrTable, PtrMap insertion (issue #749)
- disallow insert() of raw pointers, since a failed insertion (ie, entry already existed) results in an unmanaged pointer. Either insert using an autoPtr, or set() with raw pointers or autoPtr. - IOobjectList::add() now takes an autoPtr instead of an object reference - IOobjectList::remove() now returns an autoPtr instead of a raw pointer
This commit is contained in:
@ -426,7 +426,7 @@ Foam::multiphaseSystem::multiphaseSystem
|
||||
iter(),
|
||||
*phases_.lookup(iter.key().first()),
|
||||
*phases_.lookup(iter.key().second())
|
||||
).ptr()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -664,7 +664,7 @@ Foam::tmp<Foam::volVectorField> Foam::multiphaseSystem::Svm
|
||||
Foam::autoPtr<Foam::multiphaseSystem::dragCoeffFields>
|
||||
Foam::multiphaseSystem::dragCoeffs() const
|
||||
{
|
||||
autoPtr<dragCoeffFields> dragCoeffsPtr(new dragCoeffFields);
|
||||
auto dragCoeffsPtr = autoPtr<dragCoeffFields>::New();
|
||||
|
||||
forAllConstIter(dragModelTable, dragModels_, iter)
|
||||
{
|
||||
@ -706,7 +706,7 @@ Foam::multiphaseSystem::dragCoeffs() const
|
||||
}
|
||||
}
|
||||
|
||||
dragCoeffsPtr().insert(iter.key(), Kptr);
|
||||
dragCoeffsPtr().set(iter.key(), Kptr);
|
||||
}
|
||||
|
||||
return dragCoeffsPtr;
|
||||
|
||||
@ -70,7 +70,7 @@ HeatAndMassTransferPhaseSystem
|
||||
|
||||
// Initially assume no mass transfer
|
||||
|
||||
dmdt_.insert
|
||||
dmdt_.set
|
||||
(
|
||||
pair,
|
||||
new volScalarField
|
||||
@ -88,7 +88,7 @@ HeatAndMassTransferPhaseSystem
|
||||
)
|
||||
);
|
||||
|
||||
dmdtExplicit_.insert
|
||||
dmdtExplicit_.set
|
||||
(
|
||||
pair,
|
||||
new volScalarField
|
||||
@ -107,7 +107,7 @@ HeatAndMassTransferPhaseSystem
|
||||
volScalarField H1(heatTransferModels_[pair][pair.first()]->K());
|
||||
volScalarField H2(heatTransferModels_[pair][pair.second()]->K());
|
||||
|
||||
Tf_.insert
|
||||
Tf_.set
|
||||
(
|
||||
pair,
|
||||
new volScalarField
|
||||
@ -257,18 +257,12 @@ template<class BasePhaseSystem>
|
||||
Foam::autoPtr<Foam::phaseSystem::heatTransferTable>
|
||||
Foam::HeatAndMassTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
|
||||
{
|
||||
autoPtr<phaseSystem::heatTransferTable> eqnsPtr
|
||||
(
|
||||
new phaseSystem::heatTransferTable()
|
||||
);
|
||||
auto eqnsPtr = autoPtr<phaseSystem::heatTransferTable>::New();
|
||||
auto& eqns = *eqnsPtr;
|
||||
|
||||
phaseSystem::heatTransferTable& eqns = eqnsPtr();
|
||||
|
||||
forAll(this->phaseModels_, phasei)
|
||||
for (const phaseModel& phase : this->phaseModels_)
|
||||
{
|
||||
const phaseModel& phase = this->phaseModels_[phasei];
|
||||
|
||||
eqns.insert
|
||||
eqns.set
|
||||
(
|
||||
phase.name(),
|
||||
new fvScalarMatrix(phase.thermo().he(), dimEnergy/dimTime)
|
||||
|
||||
@ -107,18 +107,12 @@ template<class BasePhaseSystem>
|
||||
Foam::autoPtr<Foam::phaseSystem::heatTransferTable>
|
||||
Foam::HeatTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
|
||||
{
|
||||
autoPtr<phaseSystem::heatTransferTable> eqnsPtr
|
||||
(
|
||||
new phaseSystem::heatTransferTable()
|
||||
);
|
||||
auto eqnsPtr = autoPtr<phaseSystem::heatTransferTable>::New();
|
||||
auto& eqns = *eqnsPtr;
|
||||
|
||||
phaseSystem::heatTransferTable& eqns = eqnsPtr();
|
||||
|
||||
forAll(this->phaseModels_, phasei)
|
||||
for (const phaseModel& phase : this->phaseModels_)
|
||||
{
|
||||
const phaseModel& phase = this->phaseModels_[phasei];
|
||||
|
||||
eqns.insert
|
||||
eqns.set
|
||||
(
|
||||
phase.name(),
|
||||
new fvScalarMatrix(phase.thermo().he(), dimEnergy/dimTime)
|
||||
|
||||
@ -62,22 +62,16 @@ Foam::InterfaceCompositionPhaseChangePhaseSystem<BasePhaseSystem>::
|
||||
massTransfer() const
|
||||
{
|
||||
// Create a mass transfer matrix for each species of each phase
|
||||
autoPtr<phaseSystem::massTransferTable> eqnsPtr
|
||||
(
|
||||
new phaseSystem::massTransferTable()
|
||||
);
|
||||
auto eqnsPtr = autoPtr<phaseSystem::massTransferTable>::New();
|
||||
auto& eqns = *eqnsPtr;
|
||||
|
||||
phaseSystem::massTransferTable& eqns = eqnsPtr();
|
||||
|
||||
forAll(this->phaseModels_, phasei)
|
||||
for (const phaseModel& phase : this->phaseModels_)
|
||||
{
|
||||
const phaseModel& phase = this->phaseModels_[phasei];
|
||||
|
||||
const PtrList<volScalarField>& Yi = phase.Y();
|
||||
|
||||
forAll(Yi, i)
|
||||
{
|
||||
eqns.insert
|
||||
eqns.set
|
||||
(
|
||||
Yi[i].name(),
|
||||
new fvScalarMatrix(Yi[i], dimMass/dimTime)
|
||||
|
||||
@ -87,7 +87,7 @@ MomentumTransferPhaseSystem
|
||||
const phasePair& pair =
|
||||
*(this->phasePairs_[dragModelIter.key()]);
|
||||
|
||||
Kds_.insert
|
||||
Kds_.set
|
||||
(
|
||||
pair,
|
||||
new volScalarField
|
||||
@ -103,7 +103,7 @@ MomentumTransferPhaseSystem
|
||||
const phasePair& pair =
|
||||
*(this->phasePairs_[virtualMassModelIter.key()]);
|
||||
|
||||
Vms_.insert
|
||||
Vms_.set
|
||||
(
|
||||
pair,
|
||||
new volScalarField
|
||||
@ -373,18 +373,12 @@ Foam::autoPtr<Foam::phaseSystem::momentumTransferTable>
|
||||
Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::momentumTransfer() const
|
||||
{
|
||||
// Create a momentum transfer matrix for each phase
|
||||
autoPtr<phaseSystem::momentumTransferTable> eqnsPtr
|
||||
(
|
||||
new phaseSystem::momentumTransferTable()
|
||||
);
|
||||
auto eqnsPtr = autoPtr<phaseSystem::momentumTransferTable>::New();
|
||||
auto& eqns = *eqnsPtr;
|
||||
|
||||
phaseSystem::momentumTransferTable& eqns = eqnsPtr();
|
||||
|
||||
forAll(this->phaseModels_, phasei)
|
||||
for (const phaseModel& phase : this->phaseModels_)
|
||||
{
|
||||
const phaseModel& phase = this->phaseModels_[phasei];
|
||||
|
||||
eqns.insert
|
||||
eqns.set
|
||||
(
|
||||
phase.name(),
|
||||
new fvVectorMatrix(phase.U(), dimMass*dimVelocity/dimTime)
|
||||
@ -492,11 +486,8 @@ template<class BasePhaseSystem>
|
||||
Foam::autoPtr<Foam::PtrList<Foam::volVectorField>>
|
||||
Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::Fs() const
|
||||
{
|
||||
autoPtr<PtrList<volVectorField>> tFs
|
||||
(
|
||||
new PtrList<volVectorField>(this->phases().size())
|
||||
);
|
||||
PtrList<volVectorField>& Fs = tFs();
|
||||
auto tFs = autoPtr<PtrList<volVectorField>>::New(this->phases().size());
|
||||
auto& Fs = *tFs;
|
||||
|
||||
// Add the lift force
|
||||
forAllConstIters(liftModels_, modelIter)
|
||||
@ -570,11 +561,9 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::phiDs
|
||||
const PtrList<volScalarField>& rAUs
|
||||
) const
|
||||
{
|
||||
autoPtr<PtrList<surfaceScalarField>> tphiDs
|
||||
(
|
||||
new PtrList<surfaceScalarField>(this->phases().size())
|
||||
);
|
||||
PtrList<surfaceScalarField>& phiDs = tphiDs();
|
||||
auto tphiDs =
|
||||
autoPtr<PtrList<surfaceScalarField>>::New(this->phases().size());
|
||||
auto& phiDs = *tphiDs;
|
||||
|
||||
// Add the turbulent dispersion force
|
||||
forAllConstIters(turbulentDispersionModels_, turbulentDispersionModelIter)
|
||||
|
||||
@ -52,7 +52,7 @@ ThermalPhaseChangePhaseSystem
|
||||
}
|
||||
|
||||
// Initially assume no mass transfer
|
||||
iDmdt_.insert
|
||||
iDmdt_.set
|
||||
(
|
||||
pair,
|
||||
new volScalarField
|
||||
@ -186,22 +186,16 @@ Foam::autoPtr<Foam::phaseSystem::massTransferTable>
|
||||
Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::massTransfer() const
|
||||
{
|
||||
// Create a mass transfer matrix for each species of each phase
|
||||
autoPtr<phaseSystem::massTransferTable> eqnsPtr
|
||||
(
|
||||
new phaseSystem::massTransferTable()
|
||||
);
|
||||
auto eqnsPtr = autoPtr<phaseSystem::massTransferTable>::New();
|
||||
auto& eqns = *eqnsPtr;
|
||||
|
||||
phaseSystem::massTransferTable& eqns = eqnsPtr();
|
||||
|
||||
forAll(this->phaseModels_, phasei)
|
||||
for (const phaseModel& phase : this->phaseModels_)
|
||||
{
|
||||
const phaseModel& phase = this->phaseModels_[phasei];
|
||||
|
||||
const PtrList<volScalarField>& Yi = phase.Y();
|
||||
|
||||
forAll(Yi, i)
|
||||
{
|
||||
eqns.insert
|
||||
eqns.set
|
||||
(
|
||||
Yi[i].name(),
|
||||
new fvScalarMatrix(Yi[i], dimMass/dimTime)
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
Test-hashPtrTable.C
|
||||
Test-HashPtrTable.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-hashPtrTable
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-HashPtrTable
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -27,6 +27,7 @@ Description
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <iostream>
|
||||
#include "autoPtr.H"
|
||||
#include "HashPtrTable.H"
|
||||
|
||||
using namespace Foam;
|
||||
@ -42,7 +43,7 @@ void printTable(const HashPtrTable<T>& table)
|
||||
Info<< iter.key() << " = ";
|
||||
if (ptr)
|
||||
{
|
||||
Info<< *ptr;
|
||||
Info<< *ptr << " (" << long(ptr) << ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -77,11 +78,11 @@ void printTable(const HashPtrTable<T>& table)
|
||||
int main()
|
||||
{
|
||||
HashPtrTable<double> myTable;
|
||||
myTable.insert("abc", new double(42.1));
|
||||
myTable.insert("def", nullptr);
|
||||
myTable.insert("pi", new double(3.14159));
|
||||
myTable.insert("natlog", new double(2.718282));
|
||||
myTable.insert("sqrt2", new double(1.414214));
|
||||
myTable.set("abc", new double(42.1));
|
||||
myTable.set("def", nullptr);
|
||||
myTable.set("pi", new double(3.14159));
|
||||
myTable.set("natlog", new double(2.718282));
|
||||
myTable.insert("sqrt2", autoPtr<double>::New(1.414214));
|
||||
|
||||
// Info<< myTable << endl;
|
||||
printTable(myTable);
|
||||
@ -105,6 +106,25 @@ int main()
|
||||
|
||||
printTable(myTable);
|
||||
|
||||
HashPtrTable<double> moved(std::move(copy));
|
||||
|
||||
Info<< nl << "test movable" << nl;
|
||||
Info<<"input:" << nl;
|
||||
printTable(copy);
|
||||
|
||||
Info<<"output:" << nl;
|
||||
printTable(moved);
|
||||
|
||||
HashPtrTable<double> other;
|
||||
|
||||
Info<<"move assign" << nl;
|
||||
|
||||
other = std::move(moved);
|
||||
printTable(other);
|
||||
|
||||
Info<<"old" << nl;
|
||||
printTable(moved);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
3
applications/test/PtrMap/Make/files
Normal file
3
applications/test/PtrMap/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
Test-PtrMap.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/Test-PtrMap
|
||||
0
applications/test/PtrMap/Make/options
Normal file
0
applications/test/PtrMap/Make/options
Normal file
130
applications/test/PtrMap/Test-PtrMap.C
Normal file
130
applications/test/PtrMap/Test-PtrMap.C
Normal file
@ -0,0 +1,130 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Description
|
||||
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <iostream>
|
||||
#include "PtrMap.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
template<class T>
|
||||
void printTable(const PtrMap<T>& table)
|
||||
{
|
||||
Info<< table.size() << nl << "(" << nl;
|
||||
|
||||
forAllConstIters(table, iter)
|
||||
{
|
||||
const T* ptr = iter.object();
|
||||
Info<< iter.key() << " = ";
|
||||
if (ptr)
|
||||
{
|
||||
Info<< *ptr << " (" << long(ptr) << ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "nullptr";
|
||||
}
|
||||
Info<< nl;
|
||||
}
|
||||
|
||||
Info<< ")" << endl;
|
||||
|
||||
// Values only, with for-range
|
||||
Info<< "values (";
|
||||
for (auto val : table)
|
||||
{
|
||||
Info<< ' ';
|
||||
if (val)
|
||||
{
|
||||
Info<< *val;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "nullptr";
|
||||
}
|
||||
}
|
||||
Info<< " )" << nl;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main()
|
||||
{
|
||||
PtrMap<double> myTable;
|
||||
myTable.set(1, new double(42.1));
|
||||
myTable.set(2, nullptr);
|
||||
myTable.set(3, new double(3.14159));
|
||||
myTable.set(4, new double(2.718282));
|
||||
myTable.set(4, new double(1.414214));
|
||||
|
||||
// Info<< myTable << endl;
|
||||
printTable(myTable);
|
||||
|
||||
PtrMap<double> copy(myTable);
|
||||
|
||||
// Info<< copy << endl;
|
||||
printTable(copy);
|
||||
Info<< copy << endl;
|
||||
|
||||
Info<<"\nerase some existing and non-existing entries" << nl;
|
||||
|
||||
auto iter = myTable.find(3);
|
||||
myTable.erase(iter);
|
||||
|
||||
iter = myTable.find(1000); // unknown key
|
||||
myTable.erase(iter);
|
||||
|
||||
myTable.erase(1);
|
||||
iter = myTable.find(100000); // unknown key
|
||||
|
||||
printTable(myTable);
|
||||
|
||||
PtrMap<double> moved(std::move(copy));
|
||||
|
||||
Info<< nl << "test movable" << nl;
|
||||
Info<<"input:" << nl;
|
||||
printTable(copy);
|
||||
|
||||
Info<<"output:" << nl;
|
||||
printTable(moved);
|
||||
|
||||
PtrMap<double> other;
|
||||
|
||||
Info<<"move assign" << nl;
|
||||
|
||||
other = std::move(moved);
|
||||
printTable(other);
|
||||
|
||||
Info<<"old" << nl;
|
||||
printTable(moved);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -813,28 +813,33 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Read all fields in time and constant directories
|
||||
IOobjectList objects(mesh, runTime.timeName());
|
||||
IOobjectList timeObjects(IOobjectList(mesh, mesh.facesInstance()));
|
||||
forAllConstIter(IOobjectList, timeObjects, iter)
|
||||
{
|
||||
IOobjectList timeObjects(mesh, mesh.facesInstance());
|
||||
|
||||
// Transfer specific types
|
||||
forAllIters(timeObjects, iter)
|
||||
{
|
||||
autoPtr<IOobject> objPtr(timeObjects.remove(iter));
|
||||
const auto& obj = *objPtr;
|
||||
|
||||
if
|
||||
(
|
||||
iter()->headerClassName() == volScalarField::typeName
|
||||
|| iter()->headerClassName() == volVectorField::typeName
|
||||
|| iter()->headerClassName() == volSphericalTensorField::typeName
|
||||
|| iter()->headerClassName() == volTensorField::typeName
|
||||
|| iter()->headerClassName() == volSymmTensorField::typeName
|
||||
|| iter()->headerClassName() == surfaceScalarField::typeName
|
||||
|| iter()->headerClassName() == surfaceVectorField::typeName
|
||||
|| iter()->headerClassName()
|
||||
== surfaceSphericalTensorField::typeName
|
||||
|| iter()->headerClassName() == surfaceSymmTensorField::typeName
|
||||
|| iter()->headerClassName() == surfaceTensorField::typeName
|
||||
obj.headerClassName() == volScalarField::typeName
|
||||
|| obj.headerClassName() == volVectorField::typeName
|
||||
|| obj.headerClassName() == volSphericalTensorField::typeName
|
||||
|| obj.headerClassName() == volTensorField::typeName
|
||||
|| obj.headerClassName() == volSymmTensorField::typeName
|
||||
|| obj.headerClassName() == surfaceScalarField::typeName
|
||||
|| obj.headerClassName() == surfaceVectorField::typeName
|
||||
|| obj.headerClassName() == surfaceSphericalTensorField::typeName
|
||||
|| obj.headerClassName() == surfaceSymmTensorField::typeName
|
||||
|| obj.headerClassName() == surfaceTensorField::typeName
|
||||
)
|
||||
{
|
||||
objects.add(*iter());
|
||||
objects.add(objPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read vol fields and subset.
|
||||
|
||||
wordList scalarNames(objects.names(volScalarField::typeName));
|
||||
|
||||
Submodule modules/catalyst updated: 5828d45108...d31e13e12b
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,20 +28,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable()
|
||||
:
|
||||
parent_type()
|
||||
{}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable(const label size)
|
||||
:
|
||||
parent_type(size)
|
||||
{}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
|
||||
(
|
||||
@ -55,16 +41,26 @@ Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
|
||||
const T* ptr = iter.object();
|
||||
if (ptr)
|
||||
{
|
||||
this->insert(iter.key(), new T(*ptr));
|
||||
this->set(iter.key(), new T(*ptr));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->insert(iter.key(), nullptr);
|
||||
this->set(iter.key(), nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::HashPtrTable<T, Key, Hash>::HashPtrTable
|
||||
(
|
||||
HashPtrTable<T, Key, Hash>&& ht
|
||||
)
|
||||
:
|
||||
parent_type(std::move(ht))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
@ -77,13 +73,13 @@ Foam::HashPtrTable<T, Key, Hash>::~HashPtrTable()
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
T* Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
|
||||
Foam::autoPtr<T> Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
|
||||
{
|
||||
if (iter.found())
|
||||
{
|
||||
T* ptr = iter.object();
|
||||
autoPtr<T> aptr(iter.object());
|
||||
this->parent_type::erase(iter);
|
||||
return ptr;
|
||||
return aptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
@ -140,11 +136,10 @@ void Foam::HashPtrTable<T, Key, Hash>::operator=
|
||||
const HashPtrTable<T, Key, Hash>& rhs
|
||||
)
|
||||
{
|
||||
// Check for assignment to self
|
||||
if (this == &rhs)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "attempted assignment to self"
|
||||
<< "attempted copy assignment to self"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
@ -155,16 +150,34 @@ void Foam::HashPtrTable<T, Key, Hash>::operator=
|
||||
const T* ptr = iter.object();
|
||||
if (ptr)
|
||||
{
|
||||
this->insert(iter.key(), new T(*ptr));
|
||||
this->set(iter.key(), new T(*ptr));
|
||||
}
|
||||
else
|
||||
{
|
||||
this->insert(iter.key(), nullptr);
|
||||
this->set(iter.key(), nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
void Foam::HashPtrTable<T, Key, Hash>::operator=
|
||||
(
|
||||
HashPtrTable<T, Key, Hash>&& rhs
|
||||
)
|
||||
{
|
||||
if (this == &rhs)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "attempted move assignment to self"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
this->clear();
|
||||
this->transfer(rhs);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
||||
|
||||
#include "HashPtrTableIO.C"
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -43,11 +43,12 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
|
||||
class Istream;
|
||||
class Ostream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
|
||||
template<class T> class autoPtr;
|
||||
template<class T, class Key, class Hash> class HashPtrTable;
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
@ -92,10 +93,10 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct null with default table capacity
|
||||
HashPtrTable();
|
||||
inline HashPtrTable();
|
||||
|
||||
//- Construct given initial table capacity
|
||||
explicit HashPtrTable(const label size);
|
||||
explicit inline HashPtrTable(const label size);
|
||||
|
||||
//- Construct from Istream using given Istream constructor class
|
||||
template<class INew>
|
||||
@ -107,9 +108,12 @@ public:
|
||||
//- Construct from dictionary with default dictionary constructor class
|
||||
explicit HashPtrTable(const dictionary& dict);
|
||||
|
||||
//- Construct as copy
|
||||
//- Copy construct
|
||||
HashPtrTable(const this_type& ht);
|
||||
|
||||
//- Move construct
|
||||
HashPtrTable(this_type&& ht);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~HashPtrTable();
|
||||
@ -121,16 +125,18 @@ public:
|
||||
|
||||
//- Remove and return the pointer specified by given iterator.
|
||||
// Includes a safeguard against the end-iterator.
|
||||
T* remove(iterator& iter);
|
||||
autoPtr<T> remove(iterator& iter);
|
||||
|
||||
//- Erase an entry specified by given iterator.
|
||||
//- Erase an entry specified by given iterator and delete the
|
||||
//- allocated pointer.
|
||||
// Includes a safeguard against the end-iterator.
|
||||
bool erase(iterator& iter);
|
||||
|
||||
//- Erase an entry specified by the given key
|
||||
//- Erase an entry specified by the given key and delete the
|
||||
//- allocated pointer.
|
||||
bool erase(const Key& key);
|
||||
|
||||
//- Clear all entries from table and deleting any allocated pointers
|
||||
//- Clear all entries from table and delete any allocated pointers
|
||||
void clear();
|
||||
|
||||
//- Write
|
||||
@ -142,6 +148,9 @@ public:
|
||||
//- Copy assignment
|
||||
void operator=(const this_type& rhs);
|
||||
|
||||
//- Move assignment
|
||||
void operator=(this_type&& rhs);
|
||||
|
||||
|
||||
// IOstream Operators
|
||||
|
||||
@ -156,6 +165,31 @@ public:
|
||||
Ostream& os,
|
||||
const HashPtrTable<T, Key, Hash>& tbl
|
||||
);
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- No insert() with raw pointers (potential memory leaks)
|
||||
// Use insert() with autoPtr or set()
|
||||
inline bool insert(const Key&, T*) = delete;
|
||||
|
||||
//- Insert a new entry, not overwriting existing entries.
|
||||
// \return True if the entry inserted, which means that it did
|
||||
// not previously exist in the table.
|
||||
inline bool insert(const Key& key, autoPtr<T>& aptr);
|
||||
|
||||
//- Insert a new entry, not overwriting existing entries.
|
||||
inline bool insert(const Key& key, autoPtr<T>&& aptr);
|
||||
|
||||
//- Use set(), not insert() to avoid potential memory leaks
|
||||
//- Assign a new entry, overwriting existing entries.
|
||||
inline bool set(const Key& key, T* ptr);
|
||||
|
||||
//- Assign a new entry, overwriting existing entries.
|
||||
inline bool set(const Key& key, autoPtr<T>& aptr);
|
||||
|
||||
//- Assign a new entry, overwriting existing entries.
|
||||
inline bool set(const Key& key, autoPtr<T>&& aptr);
|
||||
};
|
||||
|
||||
|
||||
@ -165,6 +199,10 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "HashPtrTableI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "HashPtrTable.C"
|
||||
#endif
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -65,7 +65,7 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inew)
|
||||
{
|
||||
Key key;
|
||||
is >> key;
|
||||
this->insert(key, inew(key, is).ptr());
|
||||
this->set(key, inew(key, is).ptr());
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
@ -110,7 +110,7 @@ void Foam::HashPtrTable<T, Key, Hash>::read(Istream& is, const INew& inew)
|
||||
is.putBack(lastToken);
|
||||
Key key;
|
||||
is >> key;
|
||||
this->insert(key, inew(key, is).ptr());
|
||||
this->set(key, inew(key, is).ptr());
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
@ -147,7 +147,7 @@ void Foam::HashPtrTable<T, Key, Hash>::read
|
||||
{
|
||||
const word& k = iter().keyword();
|
||||
|
||||
this->insert(k, inew(dict.subDict(k)).ptr());
|
||||
this->set(k, inew(dict.subDict(k)).ptr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -298,7 +298,7 @@ Foam::label Foam::HashTable<T, Key, Hash>::countEntries
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
bool Foam::HashTable<T, Key, Hash>::set
|
||||
bool Foam::HashTable<T, Key, Hash>::setEntry
|
||||
(
|
||||
const Key& key,
|
||||
const T& obj,
|
||||
|
||||
@ -165,8 +165,10 @@ class HashTable
|
||||
}
|
||||
|
||||
private:
|
||||
//- Disallow default bitwise copy construct / assignment
|
||||
//- No copy construct
|
||||
pair_entry(const pair_entry&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const pair_entry&) = delete;
|
||||
};
|
||||
|
||||
@ -214,8 +216,10 @@ class HashTable
|
||||
|
||||
|
||||
private:
|
||||
//- Disallow default bitwise copy construct / assignment
|
||||
//- No copy construct
|
||||
unary_entry(const unary_entry&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const unary_entry&) = delete;
|
||||
};
|
||||
|
||||
@ -249,7 +253,7 @@ class HashTable
|
||||
|
||||
//- Assign a new hash-entry to a possibly already existing key.
|
||||
// \return True if the new entry was set.
|
||||
bool set(const Key& key, const T& obj, const bool overwrite);
|
||||
bool setEntry(const Key& key, const T& obj, const bool overwrite);
|
||||
|
||||
|
||||
public:
|
||||
@ -606,10 +610,10 @@ public:
|
||||
//- Return existing entry or insert a new entry.
|
||||
inline T& operator()(const Key& key, const T& deflt);
|
||||
|
||||
//- Copy assignment
|
||||
//- Copy assign
|
||||
void operator=(const HashTable<T, Key, Hash>& rhs);
|
||||
|
||||
//- Copy assignment from an initializer list
|
||||
//- Copy assign from an initializer list
|
||||
void operator=(std::initializer_list<std::pair<Key, T>> rhs);
|
||||
|
||||
//- Move assign
|
||||
|
||||
@ -121,7 +121,7 @@ inline bool Foam::HashTable<T, Key, Hash>::insert
|
||||
const T& obj
|
||||
)
|
||||
{
|
||||
return this->set(key, obj, false); // No overwrite
|
||||
return this->setEntry(key, obj, false); // No overwrite
|
||||
}
|
||||
|
||||
|
||||
@ -132,7 +132,7 @@ inline bool Foam::HashTable<T, Key, Hash>::set
|
||||
const T& obj
|
||||
)
|
||||
{
|
||||
return this->set(key, obj, true); // Overwrite
|
||||
return this->setEntry(key, obj, true); // Overwrite
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -80,11 +80,32 @@ public:
|
||||
parent_type(is)
|
||||
{}
|
||||
|
||||
//- Construct as copy
|
||||
//- Copy construct
|
||||
PtrMap(const this_type& map)
|
||||
:
|
||||
parent_type(map)
|
||||
{}
|
||||
|
||||
//- Move construct
|
||||
PtrMap(this_type&& map)
|
||||
:
|
||||
parent_type(std::move(map))
|
||||
{}
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Copy assignment
|
||||
void operator=(const this_type& rhs)
|
||||
{
|
||||
parent_type::operator=(rhs);
|
||||
}
|
||||
|
||||
//- Move assignment
|
||||
void operator=(this_type&& rhs)
|
||||
{
|
||||
parent_type::operator=(std::move(rhs));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -52,7 +52,7 @@ namespace Foam
|
||||
InfoInFunction << "Found " << iter.key() << endl;
|
||||
}
|
||||
|
||||
results.insert
|
||||
results.set
|
||||
(
|
||||
iter.key(),
|
||||
new IOobject(*(iter.object()))
|
||||
@ -123,9 +123,27 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::IOobjectList::IOobjectList(const label nIoObjects)
|
||||
Foam::IOobjectList::IOobjectList()
|
||||
:
|
||||
HashPtrTable<IOobject>(nIoObjects)
|
||||
HashPtrTable<IOobject>()
|
||||
{}
|
||||
|
||||
|
||||
Foam::IOobjectList::IOobjectList(const label nObjects)
|
||||
:
|
||||
HashPtrTable<IOobject>(nObjects) // Could also use 2*nObjects instead
|
||||
{}
|
||||
|
||||
|
||||
Foam::IOobjectList::IOobjectList(const IOobjectList& list)
|
||||
:
|
||||
HashPtrTable<IOobject>(list)
|
||||
{}
|
||||
|
||||
|
||||
Foam::IOobjectList::IOobjectList(IOobjectList&& list)
|
||||
:
|
||||
HashPtrTable<IOobject>(std::move(list))
|
||||
{}
|
||||
|
||||
|
||||
@ -142,7 +160,7 @@ Foam::IOobjectList::IOobjectList
|
||||
HashPtrTable<IOobject>()
|
||||
{
|
||||
word newInstance;
|
||||
fileNameList ObjectNames = fileHandler().readObjects
|
||||
fileNameList objNames = fileHandler().readObjects
|
||||
(
|
||||
db,
|
||||
instance,
|
||||
@ -150,9 +168,9 @@ Foam::IOobjectList::IOobjectList
|
||||
newInstance
|
||||
);
|
||||
|
||||
for (const auto& objName : ObjectNames)
|
||||
for (const auto& objName : objNames)
|
||||
{
|
||||
IOobject* objectPtr = new IOobject
|
||||
auto objectPtr = autoPtr<IOobject>::New
|
||||
(
|
||||
objName,
|
||||
newInstance,
|
||||
@ -183,35 +201,35 @@ Foam::IOobjectList::IOobjectList
|
||||
{
|
||||
insert(objectPtr->name(), objectPtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete objectPtr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::IOobjectList::IOobjectList(const IOobjectList& iolist)
|
||||
:
|
||||
HashPtrTable<IOobject>(iolist)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::IOobjectList::~IOobjectList()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::IOobjectList::add(IOobject& io)
|
||||
bool Foam::IOobjectList::add(autoPtr<IOobject>& objectPtr)
|
||||
{
|
||||
return insert(io.name(), &io);
|
||||
if (objectPtr.valid())
|
||||
{
|
||||
return insert(objectPtr->name(), objectPtr);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::IOobjectList::remove(IOobject& io)
|
||||
bool Foam::IOobjectList::add(autoPtr<IOobject>&& objectPtr)
|
||||
{
|
||||
if (objectPtr.valid())
|
||||
{
|
||||
return insert(objectPtr->name(), objectPtr);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::IOobjectList::remove(const IOobject& io)
|
||||
{
|
||||
return erase(io.name());
|
||||
}
|
||||
@ -219,7 +237,7 @@ bool Foam::IOobjectList::remove(IOobject& io)
|
||||
|
||||
Foam::IOobject* Foam::IOobjectList::lookup(const word& name) const
|
||||
{
|
||||
const_iterator iter = find(name);
|
||||
const_iterator iter = cfind(name);
|
||||
|
||||
if (iter.found())
|
||||
{
|
||||
@ -267,7 +285,7 @@ Foam::IOobjectList Foam::IOobjectList::lookupClass(const word& clsName) const
|
||||
InfoInFunction << "Found " << iter.key() << endl;
|
||||
}
|
||||
|
||||
results.insert
|
||||
results.set
|
||||
(
|
||||
iter.key(),
|
||||
new IOobject(*(iter.object()))
|
||||
@ -369,6 +387,14 @@ Foam::wordList Foam::IOobjectList::sortedNames
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::IOobjectList::operator=(IOobjectList&& list)
|
||||
{
|
||||
transfer(list);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const IOobjectList& list)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -45,7 +45,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
// Forward declarations
|
||||
class IOobjectList;
|
||||
Ostream& operator<<(Ostream& os, const IOobjectList& list);
|
||||
|
||||
@ -58,18 +58,21 @@ class IOobjectList
|
||||
:
|
||||
public HashPtrTable<IOobject>
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const IOobjectList&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct given an initial estimate for the number of entries
|
||||
explicit IOobjectList(const label nIoObjects = 128);
|
||||
//- Construct null with default (128) table capacity
|
||||
IOobjectList();
|
||||
|
||||
//- Construct given initial table capacity
|
||||
explicit IOobjectList(const label nObjects);
|
||||
|
||||
//- Copy construct
|
||||
IOobjectList(const IOobjectList& list);
|
||||
|
||||
//- Move construct
|
||||
IOobjectList(IOobjectList&& list);
|
||||
|
||||
//- Construct from objectRegistry and instance path
|
||||
IOobjectList
|
||||
@ -82,12 +85,9 @@ public:
|
||||
bool registerObject = true
|
||||
);
|
||||
|
||||
//- Construct as copy
|
||||
IOobjectList(const IOobjectList& iolist);
|
||||
|
||||
|
||||
//- Destructor
|
||||
~IOobjectList();
|
||||
~IOobjectList() = default;
|
||||
|
||||
|
||||
// Member functions
|
||||
@ -95,10 +95,16 @@ public:
|
||||
// Basic methods
|
||||
|
||||
//- Add an IOobject to the list
|
||||
bool add(IOobject& io);
|
||||
bool add(autoPtr<IOobject>& objectPtr);
|
||||
|
||||
//- Add an IOobject to the list
|
||||
bool add(autoPtr<IOobject>&& objectPtr);
|
||||
|
||||
//- Remove an IOobject from the list, by iterator
|
||||
using HashPtrTable<IOobject>::remove;
|
||||
|
||||
//- Remove an IOobject from the list
|
||||
bool remove(IOobject& io);
|
||||
bool remove(const IOobject& io);
|
||||
|
||||
|
||||
// Lookup
|
||||
@ -230,6 +236,15 @@ public:
|
||||
wordList sortedNames(const word& clsName, const wordRes& matcher) const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const IOobjectList&) = delete;
|
||||
|
||||
//- Move assignment
|
||||
void operator=(IOobjectList&& list);
|
||||
|
||||
|
||||
// Ostream Operator
|
||||
|
||||
friend Ostream& operator<<(Ostream& os, const IOobjectList& list);
|
||||
|
||||
@ -1460,7 +1460,7 @@ Foam::instantList Foam::fileOperations::masterUncollatedFileOperation::findTimes
|
||||
|
||||
instantList* tPtr = new instantList(std::move(times));
|
||||
|
||||
times_.insert(directory, tPtr);
|
||||
times_.set(directory, tPtr);
|
||||
|
||||
if (debug)
|
||||
{
|
||||
|
||||
@ -66,7 +66,7 @@ void Foam::graph::readCurves(Istream& is)
|
||||
y[i] = xyData[i].y_;
|
||||
}
|
||||
|
||||
insert
|
||||
set
|
||||
(
|
||||
wordify(yName_),
|
||||
new curve(wordify(yName_), curve::curveStyle::CONTINUOUS, y)
|
||||
@ -105,7 +105,11 @@ Foam::graph::graph
|
||||
yName_(yName),
|
||||
x_(x)
|
||||
{
|
||||
insert(wordify(yName), new curve(yName, curve::curveStyle::CONTINUOUS, y));
|
||||
set
|
||||
(
|
||||
wordify(yName),
|
||||
new curve(yName, curve::curveStyle::CONTINUOUS, y)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -122,11 +122,10 @@ void Foam::functionObjects::runTimePostPro::scene::readColours
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
const wordList colours = dict.toc();
|
||||
forAll(colours, i)
|
||||
const wordList colours(dict.toc());
|
||||
for (const word& c : colours)
|
||||
{
|
||||
const word& c = colours[i];
|
||||
colours_.insert(c, Function1<vector>::New(c, dict).ptr());
|
||||
colours_.insert(c, Function1<vector>::New(c, dict));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -109,7 +109,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
scalarFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new scalarField(0)
|
||||
autoPtr<scalarField>::New()
|
||||
);
|
||||
}
|
||||
else
|
||||
@ -133,7 +133,8 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
== token::Compound<List<scalar>>::typeName
|
||||
)
|
||||
{
|
||||
scalarField* fPtr = new scalarField;
|
||||
auto fPtr = autoPtr<scalarField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast<token::Compound<List<scalar>>>
|
||||
@ -167,7 +168,8 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
== token::Compound<List<vector>>::typeName
|
||||
)
|
||||
{
|
||||
vectorField* fPtr = new vectorField;
|
||||
auto fPtr = autoPtr<vectorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast<token::Compound<List<vector>>>
|
||||
@ -201,7 +203,8 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
== token::Compound<List<sphericalTensor>>::typeName
|
||||
)
|
||||
{
|
||||
sphericalTensorField* fPtr = new sphericalTensorField;
|
||||
auto fPtr = autoPtr<sphericalTensorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast
|
||||
@ -238,7 +241,8 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
== token::Compound<List<symmTensor>>::typeName
|
||||
)
|
||||
{
|
||||
symmTensorField* fPtr = new symmTensorField;
|
||||
auto fPtr = autoPtr<symmTensorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast
|
||||
@ -275,7 +279,8 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
== token::Compound<List<tensor>>::typeName
|
||||
)
|
||||
{
|
||||
tensorField* fPtr = new tensorField;
|
||||
auto fPtr = autoPtr<tensorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast<token::Compound<List<tensor>>>
|
||||
@ -331,7 +336,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
scalarFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new scalarField
|
||||
autoPtr<scalarField>::New
|
||||
(
|
||||
this->size(),
|
||||
fieldToken.number()
|
||||
@ -352,7 +357,11 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
vectorFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new vectorField(this->size(), vs)
|
||||
autoPtr<vectorField>::New
|
||||
(
|
||||
this->size(),
|
||||
vs
|
||||
)
|
||||
);
|
||||
}
|
||||
else if (l.size() == sphericalTensor::nComponents)
|
||||
@ -362,7 +371,11 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
sphericalTensorFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new sphericalTensorField(this->size(), vs)
|
||||
autoPtr<sphericalTensorField>::New
|
||||
(
|
||||
this->size(),
|
||||
vs
|
||||
)
|
||||
);
|
||||
}
|
||||
else if (l.size() == symmTensor::nComponents)
|
||||
@ -372,7 +385,11 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
symmTensorFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new symmTensorField(this->size(), vs)
|
||||
autoPtr<symmTensorField>::New
|
||||
(
|
||||
this->size(),
|
||||
vs
|
||||
)
|
||||
);
|
||||
}
|
||||
else if (l.size() == tensor::nComponents)
|
||||
@ -387,7 +404,11 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
tensorFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new tensorField(this->size(), vs)
|
||||
autoPtr<tensorField>::New
|
||||
(
|
||||
this->size(),
|
||||
vs
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
@ -434,7 +455,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
scalarFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new scalarField(*iter(), mapper)
|
||||
autoPtr<scalarField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -448,7 +469,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
vectorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new vectorField(*iter(), mapper)
|
||||
autoPtr<vectorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -462,7 +483,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
sphericalTensorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new sphericalTensorField(*iter(), mapper)
|
||||
autoPtr<sphericalTensorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -476,7 +497,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
symmTensorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new symmTensorField(*iter(), mapper)
|
||||
autoPtr<symmTensorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -490,7 +511,7 @@ Foam::genericFaPatchField<Type>::genericFaPatchField
|
||||
tensorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new tensorField(*iter(), mapper)
|
||||
autoPtr<tensorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
scalarFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new scalarField(0)
|
||||
autoPtr<scalarField>::New()
|
||||
);
|
||||
}
|
||||
else
|
||||
@ -133,7 +133,8 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
== token::Compound<List<scalar>>::typeName
|
||||
)
|
||||
{
|
||||
scalarField* fPtr = new scalarField;
|
||||
auto fPtr = autoPtr<scalarField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast<token::Compound<List<scalar>>>
|
||||
@ -167,7 +168,8 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
== token::Compound<List<vector>>::typeName
|
||||
)
|
||||
{
|
||||
vectorField* fPtr = new vectorField;
|
||||
auto fPtr = autoPtr<vectorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast<token::Compound<List<vector>>>
|
||||
@ -201,7 +203,8 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
== token::Compound<List<sphericalTensor>>::typeName
|
||||
)
|
||||
{
|
||||
sphericalTensorField* fPtr = new sphericalTensorField;
|
||||
auto fPtr = autoPtr<sphericalTensorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast
|
||||
@ -238,7 +241,8 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
== token::Compound<List<symmTensor>>::typeName
|
||||
)
|
||||
{
|
||||
symmTensorField* fPtr = new symmTensorField;
|
||||
auto fPtr = autoPtr<symmTensorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast
|
||||
@ -275,7 +279,8 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
== token::Compound<List<tensor>>::typeName
|
||||
)
|
||||
{
|
||||
tensorField* fPtr = new tensorField;
|
||||
auto fPtr = autoPtr<tensorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast<token::Compound<List<tensor>>>
|
||||
@ -331,7 +336,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
scalarFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new scalarField
|
||||
autoPtr<scalarField>::New
|
||||
(
|
||||
this->size(),
|
||||
fieldToken.number()
|
||||
@ -352,7 +357,11 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
vectorFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new vectorField(this->size(), vs)
|
||||
autoPtr<vectorField>::New
|
||||
(
|
||||
this->size(),
|
||||
vs
|
||||
)
|
||||
);
|
||||
}
|
||||
else if (l.size() == sphericalTensor::nComponents)
|
||||
@ -362,7 +371,11 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
sphericalTensorFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new sphericalTensorField(this->size(), vs)
|
||||
autoPtr<sphericalTensorField>::New
|
||||
(
|
||||
this->size(),
|
||||
vs
|
||||
)
|
||||
);
|
||||
}
|
||||
else if (l.size() == symmTensor::nComponents)
|
||||
@ -372,7 +385,11 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
symmTensorFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new symmTensorField(this->size(), vs)
|
||||
autoPtr<symmTensorField>::New
|
||||
(
|
||||
this->size(),
|
||||
vs
|
||||
)
|
||||
);
|
||||
}
|
||||
else if (l.size() == tensor::nComponents)
|
||||
@ -387,7 +404,11 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
tensorFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new tensorField(this->size(), vs)
|
||||
autoPtr<tensorField>::New
|
||||
(
|
||||
this->size(),
|
||||
vs
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
@ -434,7 +455,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
scalarFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new scalarField(*iter(), mapper)
|
||||
autoPtr<scalarField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -448,7 +469,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
vectorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new vectorField(*iter(), mapper)
|
||||
autoPtr<vectorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -462,7 +483,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
sphericalTensorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new sphericalTensorField(*iter(), mapper)
|
||||
autoPtr<sphericalTensorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -476,7 +497,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
symmTensorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new symmTensorField(*iter(), mapper)
|
||||
autoPtr<symmTensorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -490,7 +511,7 @@ Foam::genericFvPatchField<Type>::genericFvPatchField
|
||||
tensorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new tensorField(*iter(), mapper)
|
||||
autoPtr<tensorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
scalarFields_.insert
|
||||
(
|
||||
iter().keyword(),
|
||||
new scalarField(0)
|
||||
autoPtr<scalarField>::New()
|
||||
);
|
||||
}
|
||||
else
|
||||
@ -111,7 +111,8 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
== token::Compound<List<scalar>>::typeName
|
||||
)
|
||||
{
|
||||
scalarField* fPtr = new scalarField;
|
||||
auto fPtr = autoPtr<scalarField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast<token::Compound<List<scalar>>>
|
||||
@ -145,7 +146,8 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
== token::Compound<List<vector>>::typeName
|
||||
)
|
||||
{
|
||||
vectorField* fPtr = new vectorField;
|
||||
auto fPtr = autoPtr<vectorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast<token::Compound<List<vector>>>
|
||||
@ -179,7 +181,8 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
== token::Compound<List<sphericalTensor>>::typeName
|
||||
)
|
||||
{
|
||||
sphericalTensorField* fPtr = new sphericalTensorField;
|
||||
auto fPtr = autoPtr<sphericalTensorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast
|
||||
@ -216,7 +219,8 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
== token::Compound<List<symmTensor>>::typeName
|
||||
)
|
||||
{
|
||||
symmTensorField* fPtr = new symmTensorField;
|
||||
auto fPtr = autoPtr<symmTensorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast
|
||||
@ -253,7 +257,8 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
== token::Compound<List<tensor>>::typeName
|
||||
)
|
||||
{
|
||||
tensorField* fPtr = new tensorField;
|
||||
auto fPtr = autoPtr<tensorField>::New();
|
||||
|
||||
fPtr->transfer
|
||||
(
|
||||
dynamicCast<token::Compound<List<tensor>>>
|
||||
@ -325,7 +330,7 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
scalarFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new scalarField(*iter(), mapper)
|
||||
autoPtr<scalarField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -339,7 +344,7 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
vectorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new vectorField(*iter(), mapper)
|
||||
autoPtr<vectorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -353,7 +358,7 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
sphericalTensorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new sphericalTensorField(*iter(), mapper)
|
||||
autoPtr<sphericalTensorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -367,7 +372,7 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
symmTensorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new symmTensorField(*iter(), mapper)
|
||||
autoPtr<symmTensorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
|
||||
@ -381,7 +386,7 @@ Foam::genericPointPatchField<Type>::genericPointPatchField
|
||||
tensorFields_.insert
|
||||
(
|
||||
iter.key(),
|
||||
new tensorField(*iter(), mapper)
|
||||
autoPtr<tensorField>::New(*iter(), mapper)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,13 +217,13 @@ Foam::label Foam::probes::prepare()
|
||||
probeDir.clean(); // Remove unneeded ".."
|
||||
|
||||
// ignore known fields, close streams for fields that no longer exist
|
||||
forAllIter(HashPtrTable<OFstream>, probeFilePtrs_, iter)
|
||||
forAllIters(probeFilePtrs_, iter)
|
||||
{
|
||||
if (!currentFields.erase(iter.key()))
|
||||
{
|
||||
DebugInfo<< "close probe stream: " << iter()->name() << endl;
|
||||
|
||||
delete probeFilePtrs_.remove(iter);
|
||||
probeFilePtrs_.remove(iter);
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,9 +233,8 @@ Foam::label Foam::probes::prepare()
|
||||
// Create directory if does not exist.
|
||||
mkDir(probeDir);
|
||||
|
||||
OFstream* fPtr = new OFstream(probeDir/fieldName);
|
||||
|
||||
OFstream& fout = *fPtr;
|
||||
auto fPtr = autoPtr<OFstream>::New(probeDir/fieldName);
|
||||
auto& fout = *fPtr;
|
||||
|
||||
DebugInfo<< "open probe stream: " << fout.name() << endl;
|
||||
|
||||
@ -426,9 +425,8 @@ void Foam::probes::updateMesh(const mapPolyMesh& mpm)
|
||||
DynamicList<label> elems(faceList_.size());
|
||||
|
||||
const labelList& reverseMap = mpm.reverseFaceMap();
|
||||
forAll(faceList_, i)
|
||||
for (const label facei : faceList_)
|
||||
{
|
||||
label facei = faceList_[i];
|
||||
if (facei != -1)
|
||||
{
|
||||
label newFacei = reverseMap[facei];
|
||||
|
||||
@ -600,7 +600,7 @@ bool finishReaction = false;
|
||||
speciesThermo_.insert
|
||||
(
|
||||
currentSpecieName,
|
||||
new gasHThermoPhysics
|
||||
autoPtr<gasHThermoPhysics>::New
|
||||
(
|
||||
janafThermo<perfectGas<specie>>
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user