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:
@ -1888,7 +1888,8 @@ const Foam::labelList& Foam::globalMeshData::sharedPointGlobalLabels() const
|
||||
sharedPointGlobalLabels = -1;
|
||||
}
|
||||
}
|
||||
return sharedPointGlobalLabelsPtr_();
|
||||
|
||||
return *sharedPointGlobalLabelsPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2025,7 +2026,7 @@ const Foam::labelList& Foam::globalMeshData::sharedPointLabels() const
|
||||
{
|
||||
calcSharedPoints();
|
||||
}
|
||||
return sharedPointLabelsPtr_();
|
||||
return *sharedPointLabelsPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2035,7 +2036,7 @@ const Foam::labelList& Foam::globalMeshData::sharedPointAddr() const
|
||||
{
|
||||
calcSharedPoints();
|
||||
}
|
||||
return sharedPointAddrPtr_();
|
||||
return *sharedPointAddrPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2055,7 +2056,7 @@ const Foam::labelList& Foam::globalMeshData::sharedEdgeLabels() const
|
||||
{
|
||||
calcSharedEdges();
|
||||
}
|
||||
return sharedEdgeLabelsPtr_();
|
||||
return *sharedEdgeLabelsPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2065,7 +2066,7 @@ const Foam::labelList& Foam::globalMeshData::sharedEdgeAddr() const
|
||||
{
|
||||
calcSharedEdges();
|
||||
}
|
||||
return sharedEdgeAddrPtr_();
|
||||
return *sharedEdgeAddrPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2126,7 +2127,7 @@ const Foam::indirectPrimitivePatch& Foam::globalMeshData::coupledPatch() const
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
return coupledPatchPtr_();
|
||||
return *coupledPatchPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2146,7 +2147,7 @@ const Foam::labelList& Foam::globalMeshData::coupledPatchMeshEdges() const
|
||||
)
|
||||
);
|
||||
}
|
||||
return coupledPatchMeshEdgesPtr_();
|
||||
return *coupledPatchMeshEdgesPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2165,7 +2166,7 @@ const
|
||||
em.insert(me[i], i);
|
||||
}
|
||||
}
|
||||
return coupledPatchMeshEdgeMapPtr_();
|
||||
return *coupledPatchMeshEdgeMapPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2178,7 +2179,7 @@ const Foam::globalIndex& Foam::globalMeshData::globalPointNumbering() const
|
||||
new globalIndex(coupledPatch().nPoints())
|
||||
);
|
||||
}
|
||||
return globalPointNumberingPtr_();
|
||||
return *globalPointNumberingPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2189,7 +2190,7 @@ Foam::globalMeshData::globalTransforms() const
|
||||
{
|
||||
globalTransformsPtr_.reset(new globalIndexAndTransform(mesh_));
|
||||
}
|
||||
return globalTransformsPtr_();
|
||||
return *globalTransformsPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2199,7 +2200,7 @@ const Foam::labelListList& Foam::globalMeshData::globalPointSlaves() const
|
||||
{
|
||||
calcGlobalPointSlaves();
|
||||
}
|
||||
return globalPointSlavesPtr_();
|
||||
return *globalPointSlavesPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2210,7 +2211,7 @@ const
|
||||
{
|
||||
calcGlobalPointSlaves();
|
||||
}
|
||||
return globalPointTransformedSlavesPtr_();
|
||||
return *globalPointTransformedSlavesPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2220,7 +2221,7 @@ const Foam::mapDistribute& Foam::globalMeshData::globalPointSlavesMap() const
|
||||
{
|
||||
calcGlobalPointSlaves();
|
||||
}
|
||||
return globalPointSlavesMapPtr_();
|
||||
return *globalPointSlavesMapPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2233,7 +2234,7 @@ const Foam::globalIndex& Foam::globalMeshData::globalEdgeNumbering() const
|
||||
new globalIndex(coupledPatch().nEdges())
|
||||
);
|
||||
}
|
||||
return globalEdgeNumberingPtr_();
|
||||
return *globalEdgeNumberingPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2243,7 +2244,7 @@ const Foam::labelListList& Foam::globalMeshData::globalEdgeSlaves() const
|
||||
{
|
||||
calcGlobalEdgeSlaves();
|
||||
}
|
||||
return globalEdgeSlavesPtr_();
|
||||
return *globalEdgeSlavesPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2254,7 +2255,7 @@ const
|
||||
{
|
||||
calcGlobalEdgeSlaves();
|
||||
}
|
||||
return globalEdgeTransformedSlavesPtr_();
|
||||
return *globalEdgeTransformedSlavesPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2264,7 +2265,7 @@ const Foam::PackedBoolList& Foam::globalMeshData::globalEdgeOrientation() const
|
||||
{
|
||||
calcGlobalEdgeOrientation();
|
||||
}
|
||||
return globalEdgeOrientationPtr_();
|
||||
return *globalEdgeOrientationPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2274,7 +2275,7 @@ const Foam::mapDistribute& Foam::globalMeshData::globalEdgeSlavesMap() const
|
||||
{
|
||||
calcGlobalEdgeSlaves();
|
||||
}
|
||||
return globalEdgeSlavesMapPtr_();
|
||||
return *globalEdgeSlavesMapPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2285,7 +2286,7 @@ const
|
||||
{
|
||||
calcGlobalPointBoundaryFaces();
|
||||
}
|
||||
return globalBoundaryFaceNumberingPtr_();
|
||||
return *globalBoundaryFaceNumberingPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2296,7 +2297,7 @@ const
|
||||
{
|
||||
calcGlobalPointBoundaryFaces();
|
||||
}
|
||||
return globalPointBoundaryFacesPtr_();
|
||||
return *globalPointBoundaryFacesPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2307,7 +2308,7 @@ Foam::globalMeshData::globalPointTransformedBoundaryFaces() const
|
||||
{
|
||||
calcGlobalPointBoundaryFaces();
|
||||
}
|
||||
return globalPointTransformedBoundaryFacesPtr_();
|
||||
return *globalPointTransformedBoundaryFacesPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2318,7 +2319,7 @@ const
|
||||
{
|
||||
calcGlobalPointBoundaryFaces();
|
||||
}
|
||||
return globalPointBoundaryFacesMapPtr_();
|
||||
return *globalPointBoundaryFacesMapPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2328,7 +2329,7 @@ const Foam::labelList& Foam::globalMeshData::boundaryCells() const
|
||||
{
|
||||
calcGlobalPointBoundaryCells();
|
||||
}
|
||||
return boundaryCellsPtr_();
|
||||
return *boundaryCellsPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2339,7 +2340,7 @@ const
|
||||
{
|
||||
calcGlobalPointBoundaryCells();
|
||||
}
|
||||
return globalBoundaryCellNumberingPtr_();
|
||||
return *globalBoundaryCellNumberingPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2350,7 +2351,7 @@ const
|
||||
{
|
||||
calcGlobalPointBoundaryCells();
|
||||
}
|
||||
return globalPointBoundaryCellsPtr_();
|
||||
return *globalPointBoundaryCellsPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2361,7 +2362,7 @@ Foam::globalMeshData::globalPointTransformedBoundaryCells() const
|
||||
{
|
||||
calcGlobalPointBoundaryCells();
|
||||
}
|
||||
return globalPointTransformedBoundaryCellsPtr_();
|
||||
return *globalPointTransformedBoundaryCellsPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2372,7 +2373,7 @@ const
|
||||
{
|
||||
calcGlobalPointBoundaryCells();
|
||||
}
|
||||
return globalPointBoundaryCellsMapPtr_();
|
||||
return *globalPointBoundaryCellsMapPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2382,7 +2383,7 @@ const Foam::labelListList& Foam::globalMeshData::globalCoPointSlaves() const
|
||||
{
|
||||
calcGlobalCoPointSlaves();
|
||||
}
|
||||
return globalCoPointSlavesPtr_();
|
||||
return *globalCoPointSlavesPtr_;
|
||||
}
|
||||
|
||||
|
||||
@ -2392,7 +2393,7 @@ const Foam::mapDistribute& Foam::globalMeshData::globalCoPointSlavesMap() const
|
||||
{
|
||||
calcGlobalCoPointSlaves();
|
||||
}
|
||||
return globalCoPointSlavesMapPtr_();
|
||||
return *globalCoPointSlavesMapPtr_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user