- naming similarity with autoPtr, unique_ptr and other containers.
For UPtrList derivatives, this is equivalent to the existing
operator(). The read-only variant is also equivalent to the
single-parameter 'set(label)' method.
With PtrList<T> list(...) :
const T* ptr = list.get(10);
if (ptr)
{
ptr->method();
}
vs.
if (list.set(10))
{
list[10].method();
}
For HashPtrTable there is only a read-only variant which is equivalent
to testing for existence and for value.
With HashPtrTable<T> hash(...) :
const T* ptr = list.get("key");
if (ptr)
{
ptr->method();
}
vs.
if (list.found("key"))
{
// Fails on null pointer!!
list["key"].method();
}
Use of get() is largely a matter of taste or local coding requirements
- forwarding like the emplace() method, but overwriting existing
entries as required
- propagate similar changes to HashPtrTable
For example, with HashPtrTable<labelList> table(...) :
With 'insert' semantics
table.emplace("list1", 1000);
vs
if (!table.found("list1"))
{
table.set("list1", new labelList(1000));
}
or
table.insert("list1", autoPtr<labelList>::New(1000));
Note that the last example invokes an unnecessary allocation/deletion
if the insertion is unsuccessful.
With 'set' semantics:
table.emplace_set("list1", 15);
vs
table.set("list1", new labelList(15));
- support move insert/set and emplace insertion.
These adjustments can be used for improved memory efficiency, and
allow hash tables of non-copyable objects (eg, std::unique_ptr).
- extend special HashTable output treatment to include pointer-like
objects such as autoPtr and unique_ptr.
ENH: HashTable::at() method with checking. Fatal if entry does not exist.
- 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