Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
memory
Xfer
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) 1991-2010 OpenCFD Ltd.
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
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
27
28
template
<
class
T>
29
inline
const
Foam::Xfer<T>
&
Foam::Xfer<T>::null
()
30
{
31
return
*
reinterpret_cast<
Xfer<T>
*
>
(0);
32
}
33
34
35
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36
37
template
<
class
T>
38
inline
Foam::Xfer<T>::Xfer
(
T
*
p
)
39
:
40
ptr_(p ? p : new
T
)
41
{}
42
43
44
template
<
class
T>
45
inline
Foam::Xfer<T>::Xfer
(
T
& t,
bool
allowTransfer)
46
:
47
ptr_(new
T
)
48
{
49
if
(allowTransfer)
50
{
51
ptr_->transfer(t);
52
}
53
else
54
{
55
ptr_->operator=(t);
56
}
57
}
58
59
60
template
<
class
T>
61
inline
Foam::Xfer<T>::Xfer
(
const
T
& t)
62
:
63
ptr_(new
T
)
64
{
65
ptr_->operator=(t);
66
}
67
68
69
template
<
class
T>
70
inline
Foam::Xfer<T>::Xfer
(
const
Xfer<T>
& t)
71
:
72
ptr_(new
T
)
73
{
74
ptr_->transfer(*(t.ptr_));
75
}
76
77
78
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
79
80
template
<
class
T>
81
inline
Foam::Xfer<T>::~Xfer
()
82
{
83
delete
ptr_;
84
ptr_ = 0;
85
}
86
87
88
// * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * * //
89
90
91
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
92
93
template
<
class
T>
94
inline
void
Foam::Xfer<T>::operator=
(
T
& t)
95
{
96
ptr_->transfer(t);
97
}
98
99
100
template
<
class
T>
101
inline
void
Foam::Xfer<T>::operator=
(
const
Xfer<T>
& t)
102
{
103
// silently ignore attempted copy to self
104
if
(
this
!= &t)
105
{
106
ptr_->transfer(*(t.ptr_));
107
}
108
}
109
110
111
template
<
class
T>
112
inline
T
&
Foam::Xfer<T>::operator()
()
const
113
{
114
return
*ptr_;
115
}
116
117
118
template
<
class
T>
119
inline
T
*
Foam::Xfer<T>::operator->
()
const
120
{
121
return
ptr_;
122
}
123
124
125
// * * * * * * * * * * * * * Helper Functions * * * * * * * * * * * * * * * //
126
127
128
template
<
class
T>
129
inline
Foam::Xfer<T>
Foam::xferCopy
(
const
T
& t)
130
{
131
return
Foam::Xfer<T>
(t);
132
}
133
134
135
template
<
class
T>
136
inline
Foam::Xfer<T>
Foam::xferMove
(
T
& t)
137
{
138
return
Foam::Xfer<T>
(t,
true
);
139
}
140
141
142
template
<
class
T>
143
inline
Foam::Xfer<T>
Foam::xferTmp
(
Foam::tmp<T>
& tt)
144
{
145
return
Foam::Xfer<T>
(tt(), tt.
isTmp
());
146
}
147
148
149
template
<
class
To,
class
From>
150
inline
Foam::Xfer<To>
Foam::xferCopyTo
(
const
From& t)
151
{
152
Foam::Xfer<To>
xf;
153
xf() = t;
154
return
xf;
155
}
156
157
158
template
<
class
To,
class
From>
159
inline
Foam::Xfer<To>
Foam::xferMoveTo
(From& t)
160
{
161
Foam::Xfer<To>
xf;
162
xf().transfer(t);
163
return
xf;
164
}
165
166
167
// ************************ vim: set sw=4 sts=4 et: ************************ //