initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / memory / Xfer / XferI.H
blob42c16035910426752d53f2a8b62809311752d6eb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM 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 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
29 template<class T>
30 inline const Foam::Xfer<T>& Foam::Xfer<T>::null()
32     return *reinterpret_cast< Xfer<T>* >(0);
36 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
38 template<class T>
39 inline Foam::Xfer<T>::Xfer(T* p)
41     ptr_(p ? p : new T)
45 template<class T>
46 inline Foam::Xfer<T>::Xfer(T& t, bool allowTransfer)
48     ptr_(new T)
50     if (allowTransfer)
51     {
52         ptr_->transfer(t);
53     }
54     else
55     {
56         ptr_->operator=(t);
57     }
61 template<class T>
62 inline Foam::Xfer<T>::Xfer(const T& t)
64     ptr_(new T)
66     ptr_->operator=(t);
70 template<class T>
71 inline Foam::Xfer<T>::Xfer(const Xfer<T>& t)
73     ptr_(new T)
75     ptr_->transfer(*(t.ptr_));
79 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
81 template<class T>
82 inline Foam::Xfer<T>::~Xfer()
84     delete ptr_;
85     ptr_ = 0;
89 // * * * * * * * * * * * * *  Member Functions * * * * * * * * * * * * * * * //
92 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
94 template<class T>
95 inline void Foam::Xfer<T>::operator=(T& t)
97     ptr_->transfer(t);
101 template<class T>
102 inline void Foam::Xfer<T>::operator=(const Xfer<T>& t)
104     // silently ignore attempted copy to self
105     if (this != &t)
106     {
107         ptr_->transfer(*(t.ptr_));
108     }
112 template<class T>
113 inline T& Foam::Xfer<T>::operator()() const
115     return *ptr_;
119 template<class T>
120 inline T* Foam::Xfer<T>::operator->() const
122     return ptr_;
126 // * * * * * * * * * * * * *  Helper Functions * * * * * * * * * * * * * * * //
129 template<class T>
130 inline Foam::Xfer<T> Foam::xferCopy(const T& t)
132     return Foam::Xfer<T>(t);
136 template<class T>
137 inline Foam::Xfer<T> Foam::xferMove(T& t)
139     return Foam::Xfer<T>(t, true);
143 template<class T>
144 inline Foam::Xfer<T> Foam::xferTmp(Foam::tmp<T>& tt)
146     return Foam::Xfer<T>(tt(), tt.isTmp());
150 template<class To, class From>
151 inline Foam::Xfer<To> Foam::xferCopyTo(const From& t)
153     Foam::Xfer<To> xf;
154     xf() = t;
155     return xf;
159 template<class To, class From>
160 inline Foam::Xfer<To> Foam::xferMoveTo(From& t)
162     Foam::Xfer<To> xf;
163     xf().transfer(t);
164     return xf;
168 // ************************************************************************* //