|
|
|
autoPtr.HGo 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-2009 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 the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 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, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Class 00026 Foam::autoPtr 00027 00028 Description 00029 An auto-pointer similar to the STL auto_ptr but with automatic casting 00030 to a reference to the type and with pointer allocation checking on access. 00031 00032 SourceFiles 00033 autoPtrI.H 00034 00035 \*---------------------------------------------------------------------------*/ 00036 00037 #ifndef autoPtr_H 00038 #define autoPtr_H 00039 00040 #include <cstddef> 00041 00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00043 00044 namespace Foam 00045 { 00046 00047 /*---------------------------------------------------------------------------*\ 00048 Class autoPtr Declaration 00049 \*---------------------------------------------------------------------------*/ 00050 00051 template<class T> 00052 class autoPtr 00053 { 00054 // Public data 00055 00056 //- Pointer to object 00057 mutable T* ptr_; 00058 00059 00060 public: 00061 00062 // Constructors 00063 00064 //- Store object pointer 00065 inline explicit autoPtr(T* = 0); 00066 00067 //- Construct as copy by transfering pointer to this autoPtr and 00068 // setting the arguments pointer to NULL 00069 inline autoPtr(const autoPtr<T>&); 00070 00071 00072 // Destructor 00073 00074 //- Delete object if pointer is not NULL 00075 inline ~autoPtr(); 00076 00077 00078 // Member Functions 00079 00080 // Check 00081 00082 //- Return true if the autoPtr is empty (ie, no pointer set). 00083 inline bool empty() const; 00084 00085 //- Return true if the autoPtr valid (ie, the pointer is set). 00086 inline bool valid() const; 00087 00088 00089 // Edit 00090 00091 //- Return object pointer for reuse 00092 inline T* ptr(); 00093 00094 //- Set pointer to that given. 00095 // If object pointer already set issue a FatalError. 00096 inline void set(T*); 00097 00098 //- If object pointer already set, delete object and set to given pointer 00099 inline void reset(T* = 0); 00100 00101 //- Delete object and set pointer to NULL, if the pointer is valid. 00102 inline void clear(); 00103 00104 00105 // Member operators 00106 00107 //- Return reference to the object data 00108 inline T& operator()(); 00109 00110 //- Return const reference to the object data 00111 inline const T& operator()() const; 00112 00113 // inline T& operator*(); 00114 // inline const T& operator*() const; 00115 00116 inline operator const T&() const; 00117 00118 //- Return object pointer 00119 inline T* operator->(); 00120 00121 //- Return const object pointer 00122 inline const T* operator->() const; 00123 00124 //- Take over object pointer from parameter 00125 inline void operator=(const autoPtr<T>&); 00126 }; 00127 00128 00129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00130 00131 } // End namespace Foam 00132 00133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00134 00135 #include "autoPtrI.H" 00136 00137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00138 00139 #endif 00140 00141 // ************************************************************************* // |