![]() |
|
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2005 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 //- If object pointer points to valid object: 00092 // delete object and set pointer to that given 00093 inline void reset(T* p = NULL); 00094 00095 //- If object pointer points to valid object: 00096 // delete object and set pointer to NULL 00097 inline void clear(); 00098 00099 00100 // Member operators 00101 00102 inline T& operator()(); 00103 inline const T& operator()() const; 00104 00105 //inline T& operator*(); 00106 //inline const T& operator*() const; 00107 00108 inline operator const T&() const; 00109 00110 //- Return object pointer 00111 inline T* operator->(); 00112 00113 //- Return const object pointer 00114 inline const T* operator->() const; 00115 00116 inline void operator=(const autoPtr<T>&); 00117 }; 00118 00119 00120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00121 00122 } // End namespace Foam 00123 00124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00125 00126 #include "autoPtrI.H" 00127 00128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00129 00130 #endif 00131 00132 // ************************************************************************* //