mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
xfer class improvements
- Allow xfer to assume control of a pointer - Added xferCopy macro - Doxygen
This commit is contained in:
@ -26,14 +26,22 @@ Class
|
|||||||
Foam::xfer
|
Foam::xfer
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A simple container that can be used to transfer the contents of objects
|
A simple container that can be used to copy or transfer the contents
|
||||||
of type \<T\> of rather than copying them.
|
of objects of type \<T\>.
|
||||||
|
|
||||||
The wrapped object of type \<T\> must implement a transfer() method.
|
Since it is decided upon construction of the xfer object whether the
|
||||||
|
parameter is to be copied or transferred, the contents of resulting
|
||||||
|
object can be transferred unconditionally.
|
||||||
|
|
||||||
|
This greatly simplifies defining the constructors for other classes
|
||||||
|
with mixed transfer/copy semantics.
|
||||||
|
|
||||||
|
The wrapped object of type \<T\> must implement a transfer() method and
|
||||||
|
an operator=() copy method.
|
||||||
|
|
||||||
Note
|
Note
|
||||||
The macro xferTmp(T,arg) can be used as a workaround for passing
|
The macros xferCopy(T,arg) and xferTmp(T,arg) can be used as workarounds
|
||||||
temporaries to copy-constructors.
|
for passing temporaries to copy-constructors.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
xferI.H
|
xferI.H
|
||||||
@ -60,25 +68,23 @@ class xfer
|
|||||||
//- Pointer to temporary object
|
//- Pointer to temporary object
|
||||||
mutable T* ptr_;
|
mutable T* ptr_;
|
||||||
|
|
||||||
// Private Member Functions
|
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
|
||||||
xfer(const xfer<T>&);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Null constructor
|
//- Store object pointer and manage its deletion
|
||||||
// Can be used later to transfer by assignment
|
// Can also be used later to transfer by assignment
|
||||||
inline xfer();
|
inline explicit xfer(T* = 0);
|
||||||
|
|
||||||
//- Construct by copying or by transferring the parameter contents
|
//- Construct by copying or by transferring the parameter contents
|
||||||
inline xfer(T&, bool allowTransfer=false);
|
inline xfer(T&, bool allowTransfer=false);
|
||||||
|
|
||||||
//- Copy constructor
|
//- Construct by copying the parameter contents
|
||||||
inline xfer(const T&);
|
inline xfer(const T&);
|
||||||
|
|
||||||
|
//- Construct by transferring the contents
|
||||||
|
inline xfer(const xfer<T>&);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|
||||||
inline ~xfer();
|
inline ~xfer();
|
||||||
@ -106,25 +112,37 @@ public:
|
|||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def xferTmp(T,arg)
|
* @def xferCopy(T,arg)
|
||||||
* Construct a temporary and return a const reference to an xfer of
|
* Construct by copying the contents of the @a arg
|
||||||
* type \<T\> and return a const reference.
|
* and return a const reference to an xfer of type \<T\>
|
||||||
*
|
*
|
||||||
* Useful for copy-constructors where the argument is temporary.
|
* Useful for constructors where the argument is temporary.
|
||||||
* This is a workaround for a template resolution problem.
|
* This is a workaround for a template resolution issue.
|
||||||
|
*
|
||||||
|
* @sa xferTmp and Foam::xfer
|
||||||
|
*/
|
||||||
|
#define xferCopy(T,arg) \
|
||||||
|
(static_cast<const Foam::xfer< T >&>(Foam::xfer< T >(arg)()))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def xferTmp(T,arg)
|
||||||
|
* Construct by transferring the contents of the @a arg
|
||||||
|
* and return a const reference to an xfer of type \<T\>
|
||||||
|
*
|
||||||
|
* Useful for constructors where the argument is temporary.
|
||||||
|
* This is a workaround for a template resolution issue.
|
||||||
*
|
*
|
||||||
* @par Example Use
|
* @par Example Use
|
||||||
* @code
|
* @code
|
||||||
* List<label> a;
|
* List<label> a;
|
||||||
* ...
|
* ...
|
||||||
* List<label> b(xferTmp(List<label>, a));
|
* List<label> b(xferTmp(List<label>, a));
|
||||||
*
|
|
||||||
* @endcode
|
* @endcode
|
||||||
* @sa xfer class
|
*
|
||||||
|
* @sa xferCopy and Foam::xfer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define xferTmp(T,arg) \
|
#define xferTmp(T,arg) \
|
||||||
(static_cast<const Foam::xfer< T >&>(Foam::xfer< T >(arg)()))
|
(static_cast<const Foam::xfer< T >&>(Foam::xfer< T >(arg, true)()))
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|||||||
@ -27,9 +27,9 @@ License
|
|||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline Foam::xfer<T>::xfer()
|
inline Foam::xfer<T>::xfer(T* p)
|
||||||
:
|
:
|
||||||
ptr_(new T)
|
ptr_(p ? p : new T)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -58,6 +58,15 @@ inline Foam::xfer<T>::xfer(const T& t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline Foam::xfer<T>::xfer(const xfer<T>& t)
|
||||||
|
:
|
||||||
|
ptr_(new T)
|
||||||
|
{
|
||||||
|
ptr_->transfer(*(t.ptr_));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
Reference in New Issue
Block a user