A simple container for copying or transferring objects of type <T>. More...
Public Member Functions | |
Xfer (T *=0) | |
Store object pointer and manage its deletion. More... | |
Xfer (T &, bool allowTransfer=false) | |
Construct by copying or by transferring the parameter contents. More... | |
Xfer (const T &) | |
Construct by copying the parameter contents. More... | |
Xfer (const Xfer< T > &) | |
Construct by transferring the contents. More... | |
~Xfer () | |
Destructor. More... | |
void | operator= (T &) |
Transfer the contents into the object. More... | |
void | operator= (const Xfer< T > &) |
Transfer the contents into the object. More... | |
T & | operator() () const |
Reference to the underlying datatype. More... | |
T * | operator-> () const |
Pointer to the underlying datatype. More... | |
Static Public Member Functions | |
static const Xfer< T > & | null () |
Return a null object reference. More... | |
Private Attributes | |
T * | ptr_ |
Pointer to underlying datatype. More... | |
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.
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:
Construct by copying or by transferring the parameter contents.
Definition at line 47 of file XferI.H.
References Xfer< T >::ptr_.
Construct by copying the parameter contents.
Definition at line 63 of file XferI.H.
References Xfer< T >::ptr_.
Construct by transferring the contents.
Definition at line 72 of file XferI.H.
References Xfer< T >::ptr_.
|
inlinestatic |
|
inline |
Transfer the contents into the object.
Definition at line 103 of file XferI.H.
References Xfer< T >::ptr_.
|
mutableprivate |
Pointer to underlying datatype.
Definition at line 90 of file Xfer.H.
Referenced by Xfer< T >::operator=(), and Xfer< T >::Xfer().
Copyright © 2011-2018 OpenFOAM | OPENFOAM® is a registered trademark of OpenCFD Ltd.