OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

XferI.H

Go 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 \*---------------------------------------------------------------------------*/
00026 
00027 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
00028 
00029 template<class T>
00030 inline const Foam::Xfer<T>& Foam::Xfer<T>::null()
00031 {
00032     return *reinterpret_cast< Xfer<T>* >(0);
00033 }
00034 
00035 
00036 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00037 
00038 template<class T>
00039 inline Foam::Xfer<T>::Xfer(T* p)
00040 :
00041     ptr_(p ? p : new T)
00042 {}
00043 
00044 
00045 template<class T>
00046 inline Foam::Xfer<T>::Xfer(T& t, bool allowTransfer)
00047 :
00048     ptr_(new T)
00049 {
00050     if (allowTransfer)
00051     {
00052         ptr_->transfer(t);
00053     }
00054     else
00055     {
00056         ptr_->operator=(t);
00057     }
00058 }
00059 
00060 
00061 template<class T>
00062 inline Foam::Xfer<T>::Xfer(const T& t)
00063 :
00064     ptr_(new T)
00065 {
00066     ptr_->operator=(t);
00067 }
00068 
00069 
00070 template<class T>
00071 inline Foam::Xfer<T>::Xfer(const Xfer<T>& t)
00072 :
00073     ptr_(new T)
00074 {
00075     ptr_->transfer(*(t.ptr_));
00076 }
00077 
00078 
00079 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00080 
00081 template<class T>
00082 inline Foam::Xfer<T>::~Xfer()
00083 {
00084     delete ptr_;
00085     ptr_ = 0;
00086 }
00087 
00088 
00089 // * * * * * * * * * * * * *  Member Functions * * * * * * * * * * * * * * * //
00090 
00091 
00092 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00093 
00094 template<class T>
00095 inline void Foam::Xfer<T>::operator=(T& t)
00096 {
00097     ptr_->transfer(t);
00098 }
00099 
00100 
00101 template<class T>
00102 inline void Foam::Xfer<T>::operator=(const Xfer<T>& t)
00103 {
00104     // silently ignore attempted copy to self
00105     if (this != &t)
00106     {
00107         ptr_->transfer(*(t.ptr_));
00108     }
00109 }
00110 
00111 
00112 template<class T>
00113 inline T& Foam::Xfer<T>::operator()() const
00114 {
00115     return *ptr_;
00116 }
00117 
00118 
00119 template<class T>
00120 inline T* Foam::Xfer<T>::operator->() const
00121 {
00122     return ptr_;
00123 }
00124 
00125 
00126 // * * * * * * * * * * * * *  Helper Functions * * * * * * * * * * * * * * * //
00127 
00128 
00129 template<class T>
00130 inline Foam::Xfer<T> Foam::xferCopy(const T& t)
00131 {
00132     return Foam::Xfer<T>(t);
00133 }
00134 
00135 
00136 template<class T>
00137 inline Foam::Xfer<T> Foam::xferMove(T& t)
00138 {
00139     return Foam::Xfer<T>(t, true);
00140 }
00141 
00142 
00143 template<class T>
00144 inline Foam::Xfer<T> Foam::xferTmp(Foam::tmp<T>& tt)
00145 {
00146     return Foam::Xfer<T>(tt(), tt.isTmp());
00147 }
00148 
00149 
00150 template<class To, class From>
00151 inline Foam::Xfer<To> Foam::xferCopyTo(const From& t)
00152 {
00153     Foam::Xfer<To> xf;
00154     xf() = t;
00155     return xf;
00156 }
00157 
00158 
00159 template<class To, class From>
00160 inline Foam::Xfer<To> Foam::xferMoveTo(From& t)
00161 {
00162     Foam::Xfer<To> xf;
00163     xf().transfer(t);
00164     return xf;
00165 }
00166 
00167 
00168 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd