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:
Mark Olesen
2018-12-20 17:29:51 +01:00
parent 17419209a7
commit 08335beb6f
6 changed files with 84 additions and 36 deletions

View File

@ -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;