mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
updated xfer class
This commit is contained in:
@ -93,9 +93,9 @@ CompactListList<T>::CompactListList(const UList<label>& rowSizes, const T& t)
|
|||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
CompactListList<T>::CompactListList(xfer<CompactListList<T> >& lst)
|
CompactListList<T>::CompactListList(const xfer<CompactListList<T> >& lst)
|
||||||
{
|
{
|
||||||
transfer(lst.ref());
|
transfer(*lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
@ -104,7 +104,7 @@ public:
|
|||||||
CompactListList(const UList<label>& rowSizes, const T&);
|
CompactListList(const UList<label>& rowSizes, const T&);
|
||||||
|
|
||||||
//- Construct by transferring the parameter contents
|
//- Construct by transferring the parameter contents
|
||||||
CompactListList(xfer<CompactListList<T> >&);
|
CompactListList(const xfer<CompactListList<T> >&);
|
||||||
|
|
||||||
//- Construct as copy or re-use as specified.
|
//- Construct as copy or re-use as specified.
|
||||||
CompactListList(CompactListList<T>&, bool reUse);
|
CompactListList(CompactListList<T>&, bool reUse);
|
||||||
|
|||||||
@ -127,9 +127,9 @@ Foam::List<T>::List(const List<T>& a)
|
|||||||
|
|
||||||
// Construct by transferring the parameter contents
|
// Construct by transferring the parameter contents
|
||||||
template<class T>
|
template<class T>
|
||||||
Foam::List<T>::List(xfer<List<T> >& lst)
|
Foam::List<T>::List(const xfer<List<T> >& lst)
|
||||||
{
|
{
|
||||||
transfer(lst.ref());
|
transfer(*lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -95,7 +95,7 @@ public:
|
|||||||
List(const List<T>&);
|
List(const List<T>&);
|
||||||
|
|
||||||
//- Construct by transferring the parameter contents
|
//- Construct by transferring the parameter contents
|
||||||
List(xfer<List<T> >&);
|
List(const xfer<List<T> >&);
|
||||||
|
|
||||||
//- Construct as copy or re-use as specified.
|
//- Construct as copy or re-use as specified.
|
||||||
List(List<T>&, bool reUse);
|
List(List<T>&, bool reUse);
|
||||||
|
|||||||
@ -55,9 +55,9 @@ PackedList<nBits>::PackedList(const PackedList<nBits>& PList)
|
|||||||
|
|
||||||
|
|
||||||
template<int nBits>
|
template<int nBits>
|
||||||
PackedList<nBits>::PackedList(xfer<PackedList<nBits> >& lst)
|
PackedList<nBits>::PackedList(const xfer<PackedList<nBits> >& lst)
|
||||||
{
|
{
|
||||||
transfer(lst.ref());
|
transfer(*lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -135,7 +135,7 @@ public:
|
|||||||
PackedList(const PackedList<nBits>& PList);
|
PackedList(const PackedList<nBits>& PList);
|
||||||
|
|
||||||
//- Construct by transferring the parameter contents
|
//- Construct by transferring the parameter contents
|
||||||
PackedList(xfer<PackedList<nBits> >&);
|
PackedList(const xfer<PackedList<nBits> >&);
|
||||||
|
|
||||||
//- Construct from labelList.
|
//- Construct from labelList.
|
||||||
PackedList(const labelList&);
|
PackedList(const labelList&);
|
||||||
|
|||||||
@ -72,9 +72,9 @@ Foam::PtrList<T>::PtrList(const PtrList<T>& a, const CloneArg& cloneArg)
|
|||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Foam::PtrList<T>::PtrList(xfer<PtrList<T> >& lst)
|
Foam::PtrList<T>::PtrList(const xfer<PtrList<T> >& lst)
|
||||||
{
|
{
|
||||||
transfer(lst.ref());
|
transfer(*lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -130,7 +130,7 @@ public:
|
|||||||
PtrList(const PtrList<T>&, const CloneArg&);
|
PtrList(const PtrList<T>&, const CloneArg&);
|
||||||
|
|
||||||
//- Construct by transferring the parameter contents
|
//- Construct by transferring the parameter contents
|
||||||
PtrList(xfer<PtrList<T> >&);
|
PtrList(const xfer<PtrList<T> >&);
|
||||||
|
|
||||||
//- Construct as copy or re-use as specified.
|
//- Construct as copy or re-use as specified.
|
||||||
PtrList(PtrList<T>&, bool reUse);
|
PtrList(PtrList<T>&, bool reUse);
|
||||||
|
|||||||
@ -51,9 +51,9 @@ UPtrList<T>::UPtrList(const label s)
|
|||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
UPtrList<T>::UPtrList(xfer<UPtrList<T> >& lst)
|
UPtrList<T>::UPtrList(const xfer<UPtrList<T> >& lst)
|
||||||
{
|
{
|
||||||
transfer(lst.ref());
|
transfer(*lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -111,7 +111,7 @@ public:
|
|||||||
explicit UPtrList(const label);
|
explicit UPtrList(const label);
|
||||||
|
|
||||||
//- Construct by transferring the parameter contents
|
//- Construct by transferring the parameter contents
|
||||||
UPtrList(xfer<UPtrList<T> >&);
|
UPtrList(const xfer<UPtrList<T> >&);
|
||||||
|
|
||||||
//- Construct as copy or re-use as specified.
|
//- Construct as copy or re-use as specified.
|
||||||
UPtrList(UPtrList<T>&, bool reUse);
|
UPtrList(UPtrList<T>&, bool reUse);
|
||||||
|
|||||||
@ -26,11 +26,15 @@ Class
|
|||||||
Foam::xfer
|
Foam::xfer
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A simple container for objects of type \<T\> that can be used for
|
A simple container that can be used to transfer the contents of objects
|
||||||
transferring the contents rather than copying them.
|
of type \<T\> of rather than copying them.
|
||||||
|
|
||||||
The wrapped object of type \<T\> must implement a transfer() method.
|
The wrapped object of type \<T\> must implement a transfer() method.
|
||||||
|
|
||||||
|
Note
|
||||||
|
The macro xferTmp(T,arg) can be used as a workaround for passing
|
||||||
|
temporaries to copy-constructors.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
xferI.H
|
xferI.H
|
||||||
|
|
||||||
@ -44,16 +48,6 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
class Istream;
|
|
||||||
class Ostream;
|
|
||||||
|
|
||||||
// Forward declaration of friend functions and operators
|
|
||||||
template<class T> class xfer;
|
|
||||||
|
|
||||||
template<class T> Istream& operator>>(Istream&, xfer<T>&);
|
|
||||||
template<class T> Ostream& operator<<(Ostream&, const xfer<T>&);
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class xfer Declaration
|
Class xfer Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -63,81 +57,40 @@ class xfer
|
|||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Reference to the underlying datatype
|
//- Pointer to temporary object
|
||||||
T& ref_;
|
mutable T* ptr_;
|
||||||
|
|
||||||
// Private Member Functions
|
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
|
||||||
xfer(const xfer<T>&);
|
|
||||||
|
|
||||||
//- Disallow default bitwise assignment
|
|
||||||
void operator=(const xfer<T>&);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct null, delaying the transfer to later
|
//- Null constructor, transfer later by assignment
|
||||||
inline xfer();
|
inline xfer();
|
||||||
|
|
||||||
//- Construct by transferring the parameter into this object
|
//- Construct by transferring the parameter contents into the object
|
||||||
inline xfer(T&);
|
inline xfer(T&);
|
||||||
|
|
||||||
//- Construct by transferring the parameter into this object
|
//- Construct by transferring the parameter contents into the object
|
||||||
inline xfer(xfer<T>&);
|
inline xfer(const xfer<T>&);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|
||||||
inline ~xfer();
|
inline ~xfer();
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- Access to the underlying datatype
|
|
||||||
inline T& ref();
|
|
||||||
|
|
||||||
//- Transfer the contents of the parameter into this object
|
|
||||||
inline void transfer(T&);
|
|
||||||
|
|
||||||
//- Transfer the contents of the parameter into this object
|
|
||||||
inline void transfer(xfer<T>&);
|
|
||||||
|
|
||||||
//- Transfer the contents from this object to the parameter
|
|
||||||
inline void yield(T&);
|
|
||||||
|
|
||||||
//- Transfer the contents from this object to the parameter
|
|
||||||
inline void yield(xfer<T>&);
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Transfer the contents into this object
|
//- Transfer the contents into the object
|
||||||
inline void operator=(T&);
|
inline void operator=(T&);
|
||||||
|
|
||||||
//- Transfer the contents into this object
|
//- Transfer the contents into the object
|
||||||
inline void operator=(xfer<T>&);
|
inline void operator=(const xfer<T>&);
|
||||||
|
|
||||||
//- Return a non-const reference to const object
|
//- Return a non-const reference to const object
|
||||||
// Useful for read-constructors where the argument is temporary
|
// @sa xferTmp macro for an alternative for copy-constructors
|
||||||
inline xfer<T>& operator()() const;
|
inline const xfer<T>& operator()() const;
|
||||||
|
|
||||||
|
//- Reference to the underlying datatype
|
||||||
// Istream operator
|
inline T& operator*() const;
|
||||||
|
|
||||||
//- Read from Istream, discarding current contents
|
|
||||||
friend Istream& operator>>
|
|
||||||
#ifndef __CINT__
|
|
||||||
<T>
|
|
||||||
#endif
|
|
||||||
(Istream&, xfer<T>&);
|
|
||||||
|
|
||||||
// Ostream operator
|
|
||||||
|
|
||||||
//- Write to Ostream
|
|
||||||
friend Ostream& operator<<
|
|
||||||
#ifndef __CINT__
|
|
||||||
<T>
|
|
||||||
#endif
|
|
||||||
(Ostream&, const xfer<T>&);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -146,6 +99,27 @@ public:
|
|||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def xferTmp(T,arg)
|
||||||
|
* Construct a temporary and return a const reference to an xfer of
|
||||||
|
* type \<T\> and return a const reference.
|
||||||
|
*
|
||||||
|
* Useful for copy-constructors where the argument is temporary.
|
||||||
|
* This is a workaround for a template resolution problem.
|
||||||
|
*
|
||||||
|
* @par Example Use
|
||||||
|
* @code
|
||||||
|
* List<label> a;
|
||||||
|
* ...
|
||||||
|
* List<label> b(xferTmp(List<label>, a));
|
||||||
|
*
|
||||||
|
* @endcode
|
||||||
|
* @sa xfer class
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define xferTmp(T,arg) \
|
||||||
|
(static_cast<const Foam::xfer< T >&>(Foam::xfer< T >(arg)()))
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#include "xferI.H"
|
#include "xferI.H"
|
||||||
|
|||||||
@ -27,125 +27,71 @@ License
|
|||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Foam::xfer<T>::xfer()
|
inline Foam::xfer<T>::xfer()
|
||||||
:
|
:
|
||||||
ref_()
|
ptr_(new T)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Foam::xfer<T>::xfer(T& t)
|
inline Foam::xfer<T>::xfer(T& t)
|
||||||
:
|
:
|
||||||
ref_()
|
ptr_(new T)
|
||||||
{
|
{
|
||||||
transfer(t);
|
ptr_->transfer(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Foam::xfer<T>::xfer(xfer<T>& t)
|
inline Foam::xfer<T>::xfer(const xfer<T>& t)
|
||||||
:
|
:
|
||||||
ref_()
|
ptr_(new T)
|
||||||
{
|
{
|
||||||
transfer(t);
|
ptr_->transfer(*(t.ptr_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Foam::xfer<T>::~xfer()
|
inline Foam::xfer<T>::~xfer()
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
T& Foam::xfer<T>::ref()
|
|
||||||
{
|
{
|
||||||
return ref_;
|
delete ptr_;
|
||||||
}
|
ptr_ = 0;
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void Foam::xfer<T>::transfer(T& t)
|
|
||||||
{
|
|
||||||
ref_.transfer(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void Foam::xfer<T>::transfer(xfer<T>& t)
|
|
||||||
{
|
|
||||||
ref_.transfer(t.ref_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void Foam::xfer<T>::yield(T& t)
|
|
||||||
{
|
|
||||||
t.transfer(ref_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void Foam::xfer<T>::yield(xfer<T>& t)
|
|
||||||
{
|
|
||||||
t.ref_.transfer(ref_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void Foam::xfer<T>::operator=(T& t)
|
inline void Foam::xfer<T>::operator=(T& t)
|
||||||
{
|
{
|
||||||
transfer(t);
|
ptr_->transfer(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void Foam::xfer<T>::operator=(xfer<T>& t)
|
inline void Foam::xfer<T>::operator=(const xfer<T>& t)
|
||||||
{
|
{
|
||||||
if (this == &t)
|
// silently ignore copy to self
|
||||||
|
if (this != &t)
|
||||||
{
|
{
|
||||||
FatalErrorIn
|
ptr_->transfer(*(t.ptr_));
|
||||||
(
|
|
||||||
"Foam::xfer<T>::operator="
|
|
||||||
"(const Foam::xfer<T>&)"
|
|
||||||
) << "Attempted assignment to self"
|
|
||||||
<< abort(FatalError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transfer(t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Foam::xfer<T>& Foam::xfer<T>::operator()() const
|
inline const Foam::xfer<T>& Foam::xfer<T>::operator()() const
|
||||||
{
|
{
|
||||||
return const_cast<xfer<T>&>(*this);
|
return *this;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, xfer<T>& t)
|
|
||||||
{
|
|
||||||
is >> t.ref_;
|
|
||||||
return is;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const xfer<T>& t)
|
inline T& Foam::xfer<T>::operator*() const
|
||||||
{
|
{
|
||||||
os << t.ref_;
|
return *ptr_;
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
Reference in New Issue
Block a user