ENH: prefer PtrList set/get/test instead of PtrList::operator() access

- clearer coding intent. Mark operator() as 'deprecated'

- add bounds checking to get(label) and set(label) methods.

  This gives failsafe behaviour for get() that is symmetric with
  HashPtrTable, autoPtr etc and aligns the set(label) methods
  for UPtrList, PtrList and PtrDynList.

- use top-level PtrList::clone() instead of cloning individual elements

ENH: support HashPtrTable set with refPtr/tmp (flexibility)
This commit is contained in:
Mark Olesen
2022-09-12 12:50:10 +02:00
parent b9ca63b118
commit a0282c7e41
18 changed files with 239 additions and 207 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -31,7 +31,10 @@ Description
#include <memory>
#include <iostream>
#include "autoPtr.H"
#include "HashPtrTable.H"
#include "refPtr.H"
#include "tmp.H"
#include "PtrMap.H"
#include "primitiveFields.H"
using namespace Foam;
@ -250,6 +253,42 @@ int main()
Info<< "Table: " << tbl << nl;
}
{
PtrMap<scalarField> fields;
{
const label patchi = 2;
scalarField fld1(patchi, 5.0);
scalarField fld2(patchi, 8.0);
// assign from tmp<>
fields.set( patchi, (fld1 * fld2));
}
{
const label patchi = 3;
scalarField fld1(patchi, 6.0);
// From tmp (clone)
fields.set(patchi, tmp<scalarField>(fld1));
}
{
const label patchi = 4;
// From refPtr
fields.set(patchi, refPtr<scalarField>::New(patchi, 10.0));
}
Info<< nl
<< "PtrMap:" << nl
<< fields << endl;
}
Info<< "\nEnd" << nl;
return 0;
}