diff --git a/src/OpenFOAM/memory/autoPtr/autoPtr.H b/src/OpenFOAM/memory/autoPtr/autoPtr.H index 748975b5cf..a8802f23a9 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtr.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtr.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -104,6 +104,15 @@ public: inline void clear(); + // Access + + //- Return reference, without checking pointer validity. + inline T& refOrNull(); + + //- Return const reference, without checking pointer validity. + inline const T& refOrNull() const; + + // Member operators //- Return reference to the object data diff --git a/src/OpenFOAM/memory/autoPtr/autoPtrI.H b/src/OpenFOAM/memory/autoPtr/autoPtrI.H index ef199ca20c..7440bdce69 100644 --- a/src/OpenFOAM/memory/autoPtr/autoPtrI.H +++ b/src/OpenFOAM/memory/autoPtr/autoPtrI.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -129,6 +129,20 @@ inline void Foam::autoPtr::clear() } +template +inline T& Foam::autoPtr::refOrNull() +{ + return *ptr_; +} + + +template +inline const T& Foam::autoPtr::refOrNull() const +{ + return *ptr_; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template