|
|
|
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-2007 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 autoPtr 00027 00028 Description 00029 An auto-pointer not unlike the STL auto_ptr but with automatic casting to 00030 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* = NULL); 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 //- Is the autoPtr valid, i.e. is the pointer set 00083 inline bool valid() const; 00084 00085 00086 // Edit 00087 00088 //- Return object pointer for reuse 00089 inline T* ptr(); 00090 00091 //- Set pointer to that given. 00092 // If object pointer already set issue a FatalError. 00093 inline void set(T* p); 00094 00095 //- If object pointer already set delete object and 00096 // set pointer to that given 00097 inline void reset(T* p = NULL); 00098 00099 //- If object pointer points to valid object: 00100 // delete object and set pointer to NULL 00101 inline void clear(); 00102 00103 00104 // Member operators 00105 00106 inline T& operator()(); 00107 inline const T& operator()() const; 00108 00109 //inline T& operator*(); 00110 //inline const T& operator*() const; 00111 00112 inline operator const T&() const; 00113 00114 //- Return object pointer 00115 inline T* operator->(); 00116 00117 //- Return const object pointer 00118 inline const T* operator->() const; 00119 00120 inline void operator=(const autoPtr<T>&); 00121 }; 00122 00123 00124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00125 00126 } // End namespace Foam 00127 00128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00129 00130 #include "autoPtrI.H" 00131 00132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00133 00134 #endif 00135 00136 // ************************************************************************* // |