FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

autoPtr.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::autoPtr
00026 
00027 Description
00028     An auto-pointer similar to the STL auto_ptr but with automatic casting
00029     to a reference to the type and with pointer allocation checking on access.
00030 
00031 SourceFiles
00032     autoPtrI.H
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef autoPtr_H
00037 #define autoPtr_H
00038 
00039 #include <cstddef>
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00042 
00043 namespace Foam
00044 {
00045 
00046 /*---------------------------------------------------------------------------*\
00047                            Class autoPtr Declaration
00048 \*---------------------------------------------------------------------------*/
00049 
00050 template<class T>
00051 class autoPtr
00052 {
00053     // Public data
00054 
00055         //- Pointer to object
00056         mutable T* ptr_;
00057 
00058 
00059 public:
00060 
00061     // Constructors
00062 
00063         //- Store object pointer
00064         inline explicit autoPtr(T* = 0);
00065 
00066         //- Construct as copy by transfering pointer to this autoPtr and
00067         //  setting the arguments pointer to NULL
00068         inline autoPtr(const autoPtr<T>&);
00069 
00070 
00071     // Destructor
00072 
00073         //- Delete object if pointer is not NULL
00074         inline ~autoPtr();
00075 
00076 
00077     // Member Functions
00078 
00079     // Check
00080 
00081         //- Return true if the autoPtr is empty (ie, no pointer set).
00082         inline bool empty() const;
00083 
00084         //- Return true if the autoPtr valid (ie, the pointer is set).
00085         inline bool valid() const;
00086 
00087 
00088     // Edit
00089 
00090         //- Return object pointer for reuse
00091         inline T* ptr();
00092 
00093         //- Set pointer to that given.
00094         //  If object pointer already set issue a FatalError.
00095         inline void set(T*);
00096 
00097         //- If object pointer already set, delete object and set to given pointer
00098         inline void reset(T* = 0);
00099 
00100         //- Delete object and set pointer to NULL, if the pointer is valid.
00101         inline void clear();
00102 
00103 
00104     // Member operators
00105 
00106         //- Return reference to the object data
00107         inline T& operator()();
00108 
00109         //- Return const reference to the object data
00110         inline const T& operator()() const;
00111 
00112         // inline T& operator*();
00113         // inline const T& operator*() const;
00114 
00115         inline operator const T&() const;
00116 
00117         //- Return object pointer
00118         inline T* operator->();
00119 
00120         //- Return const object pointer
00121         inline const T* operator->() const;
00122 
00123         //- Take over object pointer from parameter
00124         inline void operator=(const autoPtr<T>&);
00125 };
00126 
00127 
00128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00129 
00130 } // End namespace Foam
00131 
00132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00133 
00134 #include "autoPtrI.H"
00135 
00136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00137 
00138 #endif
00139 
00140 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines