![]() |
|
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 tmp 00027 00028 Description 00029 00030 SourceFiles 00031 tmpI.H 00032 00033 \*---------------------------------------------------------------------------*/ 00034 00035 #ifndef tmp_H 00036 #define tmp_H 00037 00038 #include "refCount.H" 00039 #include <cstddef> 00040 00041 #if defined(__GNUC__) && !defined(__INTEL_COMPILER) 00042 # define ConstructFromTmp 00043 #endif 00044 00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00046 00047 namespace Foam 00048 { 00049 00050 /*---------------------------------------------------------------------------*\ 00051 Class tmp Declaration 00052 \*---------------------------------------------------------------------------*/ 00053 00054 template<class T> 00055 class tmp 00056 { 00057 // Private data 00058 00059 //- Flag for whether field is a temporary or a constant object 00060 bool isTmp_; 00061 00062 //- Pointer to temporary object 00063 mutable T* ptr_; 00064 00065 // Const reference to constant object 00066 const T& ref_; 00067 00068 00069 public: 00070 00071 // Constructors 00072 00073 //- Store object pointer 00074 inline explicit tmp(T* = 0); 00075 00076 //- Store object const reference 00077 inline tmp(const T&); 00078 00079 //- Construct copy and increment reference count 00080 inline tmp(const tmp<T>&); 00081 00082 00083 // Destructor 00084 00085 //- Delete object when reference count == 0 00086 inline ~tmp(); 00087 00088 00089 // Member Functions 00090 00091 // Access 00092 00093 //- Is this really a temporary object 00094 inline bool isTmp() const; 00095 00096 //- Is this temporary object valid, i.e. is it a reference 00097 // or a temporary that has been allocated 00098 inline bool valid() const; 00099 00100 00101 // Edit 00102 00103 //- Return tmp pointer for reuse 00104 inline T* ptr() const; 00105 00106 //- If object pointer points to valid object: 00107 // delete object and set pointer to NULL 00108 inline void clear(); 00109 00110 //- If object pointer points to valid object: 00111 // delete object and set pointer to NULL 00112 inline void clear() const; 00113 00114 00115 // Member operators 00116 00117 //- Dereference operator 00118 inline T& operator()(); 00119 00120 //- Const dereference operator 00121 inline const T& operator()() const; 00122 00123 //- Const cast to the underlying type reference 00124 inline operator const T&() const; 00125 00126 //- Return object pointer 00127 inline T* operator->(); 00128 00129 //- Return const object pointer 00130 inline const T* operator->() const; 00131 00132 //- Assignment operator 00133 inline void operator=(const tmp<T>&); 00134 }; 00135 00136 00137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00138 00139 } // End namespace Foam 00140 00141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00142 00143 #include "tmpI.H" 00144 00145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00146 00147 #endif 00148 00149 // ************************************************************************* //