* resize_null() methods for PtrList variants
- for cases where an existing PtrList needs a specific size and
but not retain any existing entries.
Eg,
ptrs.resize_null(100);
vs. ptrs.free(); ptr.resize(100);
or ptr.resize(100); ptrs.free();
* remove stored pointer before emplacing PtrList elements
- may reduce memory peaks
* STYLE: static_cast of (nullptr) instead of reinterpret_cast of (0)
* COMP: implement emplace_set() for PtrDynList
- previously missing, which meant it would have leaked through to the
underlying PtrList definition
* emplace methods for autoPtr, refPtr, tmp
- applies reset() with forwarding arguments.
For example,
tmp<GeoField> tfld = ...;
later...
tfld.emplace(io, mesh);
vs.
tfld.reset(new GeoField(io, mesh));
or
tfld.reset(tmp<GeoField>::New(io, mesh));
The emplace() obviously has reduced typing, but also allows the
existing stored pointer to be deleted *before* creating its
replacement (reduces memory peaks).
- allows unambiguous of count() for other classes.
Naming as per std::shared_ptr.
STYLE: qualify use_count() and unique() methods with the refCount base
- clearer/consistent meaning
- makes it easier to use for local or alternative storage.
Eg,
```
tmp<volScalarField> tfld;
tfld.cref(obj.cfindObject<volScalarField>("name"));
if (!tfld)
{
tfld = volScalarField::New("name", ...);
}
```
- makes it easier to use in combination with various 'New' selectors,
which mostly return an autoPtr.
ENH: add very simple FFT test
- basic sanity test that the library links properly
- 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
Improve alignment of its behaviour with std::shared_ptr
- element_type typedef
- swap, reset methods
* additional reference access methods:
cref()
returns a const reference, synonymous with operator().
This provides a more verbose alternative to using the '()' operator
when that is desired.
Mnemonic: a const form of 'ref()'
constCast()
returns a non-const reference, regardless if the underlying object
itself is a managed pointer or a const object.
This is similar to ref(), but more permissive.
Mnemonic: const_cast<>
Using the constCast() method greatly reduces the amount of typing
and reading. And since the data type is already defined via the tmp
template parameter, the type deduction is automatically known.
Previously,
const tmp<volScalarField>& tfld;
const_cast<volScalarField&>(tfld()).rename("name");
volScalarField& fld = const_cast<volScalarField&>(tfld());
Now,
tfld.constCast().rename("name");
auto& fld = tfld.constCast();
--
BUG: attempts to move tmp value that may still be shared.
- old code simply checked isTmp() to decide if the contents could be
transfered. However, this means that the content of a shared tmp
would be removed, leaving other instances without content.
* movable() method checks that for a non-null temporary that is
unique (not shared).