XferI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "nullObject.H"
27 
28 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
29 
30 template<class T>
32 {
33  return NullObjectRef<Xfer<T> >();
34 }
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
39 template<class T>
41 :
42  ptr_(p ? p : new T)
43 {}
44 
45 
46 template<class T>
47 inline Foam::Xfer<T>::Xfer(T& t, bool allowTransfer)
48 :
49  ptr_(new T)
50 {
51  if (allowTransfer)
52  {
53  ptr_->transfer(t);
54  }
55  else
56  {
57  ptr_->operator=(t);
58  }
59 }
60 
61 
62 template<class T>
63 inline Foam::Xfer<T>::Xfer(const T& t)
64 :
65  ptr_(new T)
66 {
67  ptr_->operator=(t);
68 }
69 
70 
71 template<class T>
72 inline Foam::Xfer<T>::Xfer(const Xfer<T>& t)
73 :
74  ptr_(new T)
75 {
76  ptr_->transfer(*(t.ptr_));
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
81 
82 template<class T>
84 {
85  delete ptr_;
86  ptr_ = 0;
87 }
88 
89 
90 // * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * * //
91 
92 
93 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
94 
95 template<class T>
96 inline void Foam::Xfer<T>::operator=(T& t)
97 {
98  ptr_->transfer(t);
99 }
100 
101 
102 template<class T>
103 inline void Foam::Xfer<T>::operator=(const Xfer<T>& t)
104 {
105  // silently ignore attempted copy to self
106  if (this != &t)
107  {
108  ptr_->transfer(*(t.ptr_));
109  }
110 }
111 
112 
113 template<class T>
115 {
116  return *ptr_;
117 }
118 
119 
120 template<class T>
122 {
123  return ptr_;
124 }
125 
126 
127 // * * * * * * * * * * * * * Helper Functions * * * * * * * * * * * * * * * //
128 
129 
130 template<class T>
131 inline Foam::Xfer<T> Foam::xferCopy(const T& t)
132 {
133  return Foam::Xfer<T>(t);
134 }
135 
136 
137 template<class T>
138 inline Foam::Xfer<T> Foam::xferMove(T& t)
139 {
140  return Foam::Xfer<T>(t, true);
141 }
142 
143 
144 template<class T>
146 {
147  return Foam::Xfer<T>(tt(), tt.isTmp());
148 }
149 
150 
151 template<class To, class From>
152 inline Foam::Xfer<To> Foam::xferCopyTo(const From& t)
153 {
154  Foam::Xfer<To> xf;
155  xf() = t;
156  return xf;
157 }
158 
159 
160 template<class To, class From>
161 inline Foam::Xfer<To> Foam::xferMoveTo(From& t)
162 {
163  Foam::Xfer<To> xf;
164  xf().transfer(t);
165  return xf;
166 }
167 
168 
169 // ************************************************************************* //
void operator=(T &)
Transfer the contents into the object.
Definition: XferI.H:96
Xfer(T *=0)
Store object pointer and manage its deletion.
Definition: XferI.H:40
Xfer< T > xferCopy(const T &)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Xfer< T > xferTmp(Foam::tmp< T > &)
T & operator()() const
Reference to the underlying datatype.
Definition: XferI.H:114
bool isTmp() const
Return true if this is really a temporary object.
Definition: tmpI.H:127
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Xfer< To > xferCopyTo(const From &)
Xfer< T > xferMove(T &)
Xfer< To > xferMoveTo(From &)
const volScalarField & T
Definition: createFields.H:25
T * operator->() const
Pointer to the underlying datatype.
Definition: XferI.H:121
volScalarField & p
Definition: createFields.H:51
~Xfer()
Destructor.
Definition: XferI.H:83
A class for managing temporary objects.
Definition: PtrList.H:118
static const Xfer< T > & null()
Return a null object reference.
Definition: XferI.H:31