1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 inline Foam::tmp<T>::tmp(T* tPtr)
40 inline Foam::tmp<T>::tmp(const T& tRef)
49 inline Foam::tmp<T>::tmp(const tmp<T>& t)
63 FatalErrorIn("tmp<T>::tmp(const tmp<T>&)")
64 << "attempted copy of a deallocated temporary"
72 inline Foam::tmp<T>::~tmp()
76 if (ptr_->okToDelete())
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92 inline bool Foam::tmp<T>::isTmp() const
99 inline bool Foam::tmp<T>::empty() const
101 return (isTmp_ && !ptr_);
106 inline bool Foam::tmp<T>::valid() const
108 return (!isTmp_ || (isTmp_ && ptr_));
113 inline T* Foam::tmp<T>::ptr() const
119 FatalErrorIn("tmp<T>::ptr() const")
120 << "temporary deallocated"
121 << abort(FatalError);
127 ptr->resetRefCount();
139 inline void Foam::tmp<T>::clear() const
141 if (isTmp_ && ptr_) // skip this bit: && ptr_->okToDelete())
149 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
152 inline T& Foam::tmp<T>::operator()()
158 FatalErrorIn("T& tmp<T>::operator()()")
159 << "temporary deallocated"
160 << abort(FatalError);
167 // Note: const is cast away!
168 // Perhaps there should be two refs, one for const and one for non const
169 // and if the ref is actually const then you cannot return it here.
171 // Another possibility would be to store a const ref and a flag to say
172 // whether the tmp was constructed with a const or a non-const argument.
174 // eg, enum refType { POINTER = 0, REF = 1, CONSTREF = 2 };
175 return const_cast<T&>(ref_);
181 inline const T& Foam::tmp<T>::operator()() const
187 FatalErrorIn("const T& tmp<T>::operator()() const")
188 << "temporary deallocated"
189 << abort(FatalError);
202 inline Foam::tmp<T>::operator const T&() const
209 inline T* Foam::tmp<T>::operator->()
215 FatalErrorIn("tmp<T>::operator->()")
216 << "temporary deallocated"
217 << abort(FatalError);
224 return &const_cast<T&>(ref_);
230 inline const T* Foam::tmp<T>::operator->() const
232 return const_cast<tmp<T>&>(*this).operator->();
237 inline void Foam::tmp<T>::operator=(const tmp<T>& t)
241 if (ptr_->okToDelete())
263 FatalErrorIn("tmp<T>::operator=(const tmp<T>& t)")
264 << "attempted copy of a deallocated temporary"
265 << abort(FatalError);
270 FatalErrorIn("tmp<T>::operator=(const tmp<T>& t)")
271 << "attempted to assign to a const reference to constant object"
272 << abort(FatalError);
277 // ************************************************************************* //