mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: cleanup autoPtr class (issue #639)
Improve alignment of its behaviour with std::unique_ptr
- element_type typedef
- release() method - identical to ptr() method
- get() method to get the pointer without checking and without releasing it.
- operator*() for dereferencing
Method name changes
- renamed rawPtr() to get()
- renamed rawRef() to ref(), removed unused const version.
Removed methods/operators
- assignment from a raw pointer was deleted (was rarely used).
Can be convenient, but uncontrolled and potentially unsafe.
Do allow assignment from a literal nullptr though, since this
can never leak (and also corresponds to the unique_ptr API).
Additional methods
- clone() method: forwards to the clone() method of the underlying
data object with argument forwarding.
- reset(autoPtr&&) as an alternative to operator=(autoPtr&&)
STYLE: avoid implicit conversion from autoPtr to object type in many places
- existing implementation has the following:
operator const T&() const { return operator*(); }
which means that the following code works:
autoPtr<mapPolyMesh> map = ...;
updateMesh(*map); // OK: explicit dereferencing
updateMesh(map()); // OK: explicit dereferencing
updateMesh(map); // OK: implicit dereferencing
for clarity it may preferable to avoid the implicit dereferencing
- prefer operator* to operator() when deferenced a return value
so it is clearer that a pointer is involve and not a function call
etc Eg, return *meshPtr_; vs. return meshPtr_();
This commit is contained in:
@ -220,7 +220,7 @@ Foam::dynamicIndexedOctree<Type>::divide
|
||||
{
|
||||
if (!replaced)
|
||||
{
|
||||
contents_[contentI]().transfer(subIndices());
|
||||
contents_[contentI]->transfer(subIndices());
|
||||
nod.subNodes_[octant] = contentPlusOctant(contentI, octant);
|
||||
|
||||
replaced = true;
|
||||
@ -239,7 +239,7 @@ Foam::dynamicIndexedOctree<Type>::divide
|
||||
)
|
||||
);
|
||||
|
||||
contents_[sz]().transfer(subIndices());
|
||||
contents_[sz]->transfer(subIndices());
|
||||
|
||||
nod.subNodes_[octant] = contentPlusOctant(sz, octant);
|
||||
}
|
||||
@ -280,7 +280,7 @@ void Foam::dynamicIndexedOctree<Type>::recursiveSubDivision
|
||||
{
|
||||
if
|
||||
(
|
||||
contents_[contentI]().size() > minSize_
|
||||
contents_[contentI]->size() > minSize_
|
||||
&& nLevels < maxLevels_
|
||||
)
|
||||
{
|
||||
@ -524,7 +524,7 @@ void Foam::dynamicIndexedOctree<Type>::findNearest
|
||||
{
|
||||
shapes_.findNearest
|
||||
(
|
||||
contents_[getContent(index)],
|
||||
*(contents_[getContent(index)]),
|
||||
sample,
|
||||
|
||||
nearestDistSqr,
|
||||
@ -589,7 +589,7 @@ void Foam::dynamicIndexedOctree<Type>::findNearest
|
||||
{
|
||||
shapes_.findNearest
|
||||
(
|
||||
contents_[getContent(index)],
|
||||
*(contents_[getContent(index)]),
|
||||
ln,
|
||||
|
||||
tightest,
|
||||
@ -1341,7 +1341,7 @@ void Foam::dynamicIndexedOctree<Type>::traverseNode
|
||||
|
||||
if (isContent(index))
|
||||
{
|
||||
const labelList& indices = contents_[getContent(index)];
|
||||
const labelList& indices = *(contents_[getContent(index)]);
|
||||
|
||||
if (indices.size())
|
||||
{
|
||||
@ -1755,7 +1755,7 @@ void Foam::dynamicIndexedOctree<Type>::findBox
|
||||
|
||||
if (subBb.overlaps(searchBox))
|
||||
{
|
||||
const labelList& indices = contents_[getContent(index)];
|
||||
const labelList& indices = *(contents_[getContent(index)]);
|
||||
|
||||
forAll(indices, i)
|
||||
{
|
||||
@ -1803,7 +1803,7 @@ void Foam::dynamicIndexedOctree<Type>::findSphere
|
||||
|
||||
if (subBb.overlaps(centre, radiusSqr))
|
||||
{
|
||||
const labelList& indices = contents_[getContent(index)];
|
||||
const labelList& indices = *(contents_[getContent(index)]);
|
||||
|
||||
forAll(indices, i)
|
||||
{
|
||||
@ -2016,7 +2016,7 @@ Foam::label Foam::dynamicIndexedOctree<Type>::countElements
|
||||
}
|
||||
else if (isContent(index))
|
||||
{
|
||||
nElems += contents_[getContent(index)]().size();
|
||||
nElems += contents_[getContent(index)]->size();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2302,7 +2302,7 @@ Foam::label Foam::dynamicIndexedOctree<Type>::findInside
|
||||
// Need to check for the presence of content, in-case the node is empty
|
||||
if (isContent(contentIndex))
|
||||
{
|
||||
labelList indices = contents_[getContent(contentIndex)];
|
||||
const labelList& indices = *(contents_[getContent(contentIndex)]);
|
||||
|
||||
forAll(indices, elemI)
|
||||
{
|
||||
@ -2334,12 +2334,10 @@ const Foam::labelList& Foam::dynamicIndexedOctree<Type>::findIndices
|
||||
// Need to check for the presence of content, in-case the node is empty
|
||||
if (isContent(contentIndex))
|
||||
{
|
||||
return contents_[getContent(contentIndex)];
|
||||
}
|
||||
else
|
||||
{
|
||||
return emptyList<label>();
|
||||
return *(contents_[getContent(contentIndex)]);
|
||||
}
|
||||
|
||||
return emptyList<label>();
|
||||
}
|
||||
|
||||
|
||||
@ -2454,7 +2452,7 @@ bool Foam::dynamicIndexedOctree<Type>::insert(label startIndex, label endIndex)
|
||||
)
|
||||
);
|
||||
|
||||
contents_[0]().append(0);
|
||||
contents_[0]->append(0);
|
||||
|
||||
// Create topnode.
|
||||
node topNode = divide(bb_, 0, -1, 0);
|
||||
@ -2518,7 +2516,7 @@ bool Foam::dynamicIndexedOctree<Type>::insertIndex
|
||||
{
|
||||
const label contentI = getContent(subNodeLabel);
|
||||
|
||||
contents_[contentI]().append(index);
|
||||
contents_[contentI]->append(index);
|
||||
|
||||
recursiveSubDivision
|
||||
(
|
||||
@ -2545,7 +2543,7 @@ bool Foam::dynamicIndexedOctree<Type>::insertIndex
|
||||
autoPtr<DynamicList<label>>(new DynamicList<label>(1))
|
||||
);
|
||||
|
||||
contents_[sz]().append(index);
|
||||
contents_[sz]->append(index);
|
||||
|
||||
nodes_[nodIndex].subNodes_[octant]
|
||||
= contentPlusOctant(sz, octant);
|
||||
@ -2618,7 +2616,7 @@ Foam::label Foam::dynamicIndexedOctree<Type>::removeIndex
|
||||
|
||||
if (shapes().overlaps(index, subBb))
|
||||
{
|
||||
DynamicList<label>& contentList = contents_[contentI]();
|
||||
DynamicList<label>& contentList = *(contents_[contentI]);
|
||||
|
||||
DynamicList<label> newContent(contentList.size());
|
||||
|
||||
@ -2644,7 +2642,7 @@ Foam::label Foam::dynamicIndexedOctree<Type>::removeIndex
|
||||
contentList.transfer(newContent);
|
||||
}
|
||||
|
||||
totalContents += contents_[contentI]().size();
|
||||
totalContents += contents_[contentI]->size();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2695,7 +2693,7 @@ void Foam::dynamicIndexedOctree<Type>::print
|
||||
}
|
||||
else if (isContent(index))
|
||||
{
|
||||
const labelList& indices = contents_[getContent(index)];
|
||||
const labelList& indices = *(contents_[getContent(index)]);
|
||||
|
||||
if (false) //debug)
|
||||
{
|
||||
@ -2735,7 +2733,7 @@ void Foam::dynamicIndexedOctree<Type>::writeTreeInfo() const
|
||||
label nEntries = 0;
|
||||
forAll(contents_, i)
|
||||
{
|
||||
nEntries += contents_[i]().size();
|
||||
nEntries += contents_[i]->size();
|
||||
}
|
||||
|
||||
Pout<< "indexedOctree<Type>::indexedOctree"
|
||||
|
||||
Reference in New Issue
Block a user