FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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