1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 An auto-pointer similar to the STL auto_ptr but with automatic casting
29 to a reference to the type and with pointer allocation checking on access.
34 \*---------------------------------------------------------------------------*/
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 /*---------------------------------------------------------------------------*\
47 Class autoPtr Declaration
48 \*---------------------------------------------------------------------------*/
63 //- Store object pointer
64 inline explicit autoPtr(T* = 0);
66 //- Construct as copy by transfering pointer to this autoPtr and
67 // setting the arguments pointer to NULL
68 inline autoPtr(const autoPtr<T>&);
71 //- Destructor, delete object if pointer is not NULL
79 //- Return true if the autoPtr is empty (ie, no pointer set).
80 inline bool empty() const;
82 //- Return true if the autoPtr valid (ie, the pointer is set).
83 inline bool valid() const;
88 //- Return object pointer for reuse
91 //- Set pointer to that given.
92 // If object pointer already set issue a FatalError.
95 //- If object pointer already set, delete object and set to given
97 inline void reset(T* = 0);
99 //- Delete object (if the pointer is valid) and set pointer to NULL.
105 //- Return reference to the object data
106 inline T& operator()();
108 //- Return const reference to the object data
109 inline const T& operator()() const;
111 //- Const cast to the underlying type reference
112 inline operator const T&() const;
114 //- Return object pointer
115 inline T* operator->();
117 //- Return const object pointer
118 inline const T* operator->() const;
120 //- Take over the object pointer from parameter
121 inline void operator=(const autoPtr<T>&);
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 } // End namespace Foam
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 #include "autoPtrI.H"
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 // ************************************************************************* //