|
|
|
tmp.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::tmp 00027 00028 Description 00029 A class for managing temporary objects 00030 00031 SourceFiles 00032 tmpI.H 00033 00034 \*---------------------------------------------------------------------------*/ 00035 00036 #ifndef tmp_H 00037 #define tmp_H 00038 00039 #include "refCount.H" 00040 #include <cstddef> 00041 00042 #if defined(__GNUC__) && !defined(__INTEL_COMPILER) 00043 # define ConstructFromTmp 00044 #endif 00045 00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00047 00048 namespace Foam 00049 { 00050 00051 /*---------------------------------------------------------------------------*\ 00052 Class tmp Declaration 00053 \*---------------------------------------------------------------------------*/ 00054 00055 template<class T> 00056 class tmp 00057 { 00058 // Private data 00059 00060 //- Flag for whether object is a temporary or a constant object 00061 bool isTmp_; 00062 00063 //- Pointer to temporary object 00064 mutable T* ptr_; 00065 00066 // Const reference to constant object 00067 const T& ref_; 00068 00069 00070 public: 00071 00072 // Constructors 00073 00074 //- Store object pointer 00075 inline explicit tmp(T* = 0); 00076 00077 //- Store object const reference 00078 inline tmp(const T&); 00079 00080 //- Construct copy and increment reference count 00081 inline tmp(const tmp<T>&); 00082 00083 00084 // Destructor 00085 00086 //- Delete object when reference count == 0 00087 inline ~tmp(); 00088 00089 00090 // Member Functions 00091 00092 // Access 00093 00094 //- Return true if this is really a temporary object 00095 inline bool isTmp() const; 00096 00097 //- Return true if this temporary object empty, 00098 // ie, a temporary without allocation 00099 inline bool empty() const; 00100 00101 //- Is this temporary object valid, 00102 // ie, it is a reference or a temporary that has been allocated 00103 inline bool valid() const; 00104 00105 // Edit 00106 00107 //- Return tmp pointer for reuse 00108 inline T* ptr() const; 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 // ************************************************************************* // |