mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add get() accessor to tmp classes
- similar to autoPtr and unique_ptr. Returns the pointer value without
any checks. This provides a simple way for use to use either
an autoPtr or a tmp for local memory management without accidentally
stealing the pointer.
Eg,
volVectorField* ptr;
tmp<volVectorField> tempField;
if (someField.valid())
{
ptr = someField.get();
}
else
{
tempField.reset(new volVectorField(....));
ptr = tmpField.get();
}
const volVectorField& withField = *ptr;
STYLE: make more tmp methods noexcept
This commit is contained in:
@ -56,16 +56,18 @@ int main()
|
||||
}
|
||||
|
||||
{
|
||||
tmp<scalarField> tfld1 = tmp<scalarField>::New(20, Zero);
|
||||
auto tfld1 = tmp<scalarField>::New(20, Zero);
|
||||
|
||||
Info<< "tmp refCount = " << tfld1->count() << nl;
|
||||
if (tfld1.valid())
|
||||
{
|
||||
Info<<"tmp: " << tfld1() << nl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
Info<<"tmp addr: " << long(tfld1.get()) << nl;
|
||||
|
||||
// Hold on to the old content for a bit
|
||||
|
||||
tmp<scalarField> tfld2 =
|
||||
tmp<scalarField>::NewFrom<myScalarField>(20, Zero);
|
||||
|
||||
@ -74,6 +76,12 @@ int main()
|
||||
{
|
||||
Info<<"tmp: " << tfld2() << nl;
|
||||
}
|
||||
|
||||
Info<<"tmp addr: " << long(tfld2.get()) << nl;
|
||||
|
||||
tfld2.clear();
|
||||
|
||||
Info<<"after clear: " << long(tfld2.get()) << nl;
|
||||
}
|
||||
|
||||
Info<< "\nEnd" << endl;
|
||||
|
||||
Reference in New Issue
Block a user