00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 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 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your 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, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::tmp 00026 00027 Description 00028 A class for managing temporary objects 00029 00030 SourceFiles 00031 tmpI.H 00032 00033 \*---------------------------------------------------------------------------*/ 00034 00035 #ifndef tmp_H 00036 #define tmp_H 00037 00038 #include <OpenFOAM/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 object 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 //- Return true if this is really a temporary object 00094 inline bool isTmp() const; 00095 00096 //- Return true if this temporary object empty, 00097 // ie, a temporary without allocation 00098 inline bool empty() const; 00099 00100 //- Is this temporary object valid, 00101 // ie, it is a reference or a temporary that has been allocated 00102 inline bool valid() const; 00103 00104 // Edit 00105 00106 //- Return tmp pointer for reuse 00107 inline T* ptr() const; 00108 00109 //- If object pointer points to valid object: 00110 // delete object and set pointer to NULL 00111 inline void clear() const; 00112 00113 00114 // Member operators 00115 00116 //- Dereference operator 00117 inline T& operator()(); 00118 00119 //- Const dereference operator 00120 inline const T& operator()() const; 00121 00122 //- Const cast to the underlying type reference 00123 inline operator const T&() const; 00124 00125 //- Return object pointer 00126 inline T* operator->(); 00127 00128 //- Return const object pointer 00129 inline const T* operator->() const; 00130 00131 //- Assignment operator 00132 inline void operator=(const tmp<T>&); 00133 }; 00134 00135 00136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00137 00138 } // End namespace Foam 00139 00140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00141 00142 #include <OpenFOAM/tmpI.H> 00143 00144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00145 00146 #endif 00147 00148 // ************************ vim: set sw=4 sts=4 et: ************************ //