A simple container for copying or transferring objects of type <T>.
More...
#include <OpenFOAM/Xfer.H>
Detailed Description
template<class T>
class Foam::Xfer< T >
A simple container for copying or transferring objects of type <T>.
The wrapped object of type <T> must implement a transfer() method and an operator=() copy method.
Since it is decided upon construction of the Xfer object whether the parameter is to be copied or transferred, the contents of the resulting Xfer object can be transferred unconditionally. This greatly simplifies defining constructors or methods in other classes with mixed transfer/copy semantics without requiring 2^N different versions.
When transferring between dissimilar types, the xferCopyTo() and xferMoveTo() functions can prove useful. An example is transferring from a DynamicList to a List. Since the List<T>::transfer(List<T>&) method could result in some allocated memory becoming inaccessible, the xferMoveTo() function should be used to invoke the correct List<T>::transfer(DynamicList<T>&) method.
DynamicList<label> dynLst;
...
labelList plainLst( xferMoveTo<labelList>(dynLst) );
Of course, since this example is a very common operation, the DynamicList::xfer() method transfers to a plain List anyhow. It would thus be simpler (and clearer) just to use the following code:
DynamicList<label> dynLst;
...
labelList plainLst(dynLst.xfer());
- See also:
- xferCopy, xferCopyTo, xferMove, xferMoveTo, xferTmp
- Source files
-
Definition at line 86 of file Xfer.H.
List of all members.
Public Member Functions
|
| Xfer (T *=0) |
| Store object pointer and manage its deletion.
|
| Xfer (T &, bool allowTransfer=false) |
| Construct by copying or by transferring the parameter contents.
|
| Xfer (const T &) |
| Construct by copying the parameter contents.
|
| Xfer (const Xfer< T > &) |
| Construct by transferring the contents.
|
| ~Xfer () |
void
| operator= (T &) |
| Transfer the contents into the object.
|
void
| operator= (const Xfer< T > &) |
| Transfer the contents into the object.
|
T &
| operator() () const |
| Reference to the underlying datatype.
|
T *
| operator-> () const |
| Pointer to the underlying datatype.
|
Static Public Member Functions
|
static const Xfer< T > &
| null () |
| Return a null object reference.
|
Constructor & Destructor Documentation
Xfer
|
( |
T *
|
p = 0
) |
[inline, explicit]
|
Store object pointer and manage its deletion.
Can also be used later to transfer by assignment
Definition at line 38 of file XferI.H.
Xfer
|
( |
T &
|
t,
|
|
|
bool
|
allowTransfer = false
|
|
) |
| [inline, explicit]
|
Construct by copying or by transferring the parameter contents.
Definition at line 45 of file XferI.H.
Xfer
|
( |
const T &
|
t
) |
[inline, explicit]
|
Construct by copying the parameter contents.
Definition at line 61 of file XferI.H.
Construct by transferring the contents.
Definition at line 70 of file XferI.H.
Member Function Documentation
Return a null object reference.
Definition at line 29 of file XferI.H.
void operator=
|
( |
T &
|
t
) |
[inline]
|
Transfer the contents into the object.
Definition at line 94 of file XferI.H.
void operator=
|
( |
const Xfer< T > &
|
t
) |
[inline]
|
Transfer the contents into the object.
Definition at line 101 of file XferI.H.
T & operator()
|
( |
) |
const [inline]
|
Reference to the underlying datatype.
Definition at line 112 of file XferI.H.
T * operator->
|
( |
) |
const [inline]
|
Pointer to the underlying datatype.
Definition at line 119 of file XferI.H.
The documentation for this class was generated from the following files: