mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
xfer class modifications:
- removed operator* in favour of operator() for consistency with tmp
class. The previous use of operator() for const casting didn't work
anyhow due to template confusion.
- added xferCopy(), xferMove() and xferTmp() template functions instead
- preliminary changes to IOobjects and Fields for xfer
This commit is contained in:
@ -52,35 +52,35 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "lstA: " << lstA << endl;
|
Info<< "lstA: " << lstA << endl;
|
||||||
Info<< "lstC: " << lstC << endl;
|
Info<< "lstC: " << lstC << endl;
|
||||||
|
|
||||||
xfer<List<label> > xA(lstA, true);
|
xfer<List<label> > xA = xferMove(lstA);
|
||||||
xfer<List<label> > xB;
|
xfer<List<label> > xB;
|
||||||
|
|
||||||
List<label> lstB( xA );
|
List<label> lstB( xA );
|
||||||
|
|
||||||
Info<< "xA: " << *xA << endl;
|
Info<< "xA: " << xA() << endl;
|
||||||
Info<< "xB: " << *xB << endl;
|
Info<< "xB: " << xB() << endl;
|
||||||
Info<< "lstA: " << lstA << endl;
|
Info<< "lstA: " << lstA << endl;
|
||||||
Info<< "lstB: " << lstB << endl;
|
Info<< "lstB: " << lstB << endl;
|
||||||
Info<< "lstC: " << lstC << endl;
|
Info<< "lstC: " << lstC << endl;
|
||||||
|
|
||||||
xA = lstB;
|
xA = lstB;
|
||||||
|
|
||||||
Info<< "xA: " << *xA << endl;
|
Info<< "xA: " << xA() << endl;
|
||||||
Info<< "xB: " << *xB << endl;
|
Info<< "xB: " << xB() << endl;
|
||||||
Info<< "lstA: " << lstA << endl;
|
Info<< "lstA: " << lstA << endl;
|
||||||
Info<< "lstB: " << lstB << endl;
|
Info<< "lstB: " << lstB << endl;
|
||||||
Info<< "lstC: " << lstC << endl;
|
Info<< "lstC: " << lstC << endl;
|
||||||
|
|
||||||
xB = xA;
|
xB = xA;
|
||||||
|
|
||||||
List<label> lstD( xferCopy(List<label>, lstC) );
|
List<label> lstD(xferCopy(lstC));
|
||||||
List<label> lstE( xferMove(List<label>, lstC) );
|
List<label> lstE(xferMove(lstC));
|
||||||
|
|
||||||
// this must be empty
|
// this must be empty
|
||||||
List<label> lstF( xferCopy(List<label>, lstC) );
|
List<label> lstF = xferCopy(lstC);
|
||||||
|
|
||||||
Info<< "xA: " << *xA << endl;
|
Info<< "xA: " << xA() << endl;
|
||||||
Info<< "xB: " << *xB << endl;
|
Info<< "xB: " << xB() << endl;
|
||||||
Info<< "lstA: " << lstA << endl;
|
Info<< "lstA: " << lstA << endl;
|
||||||
Info<< "lstB: " << lstB << endl;
|
Info<< "lstB: " << lstB << endl;
|
||||||
Info<< "lstC: " << lstC << endl;
|
Info<< "lstC: " << lstC << endl;
|
||||||
@ -88,12 +88,12 @@ int main(int argc, char *argv[])
|
|||||||
Info<< "lstE: " << lstE << endl;
|
Info<< "lstE: " << lstE << endl;
|
||||||
Info<< "lstF: " << lstF << endl;
|
Info<< "lstF: " << lstF << endl;
|
||||||
|
|
||||||
Info<< "xB size: " << *xB << endl;
|
Info<< "xB size: " << xB->size() << endl;
|
||||||
|
|
||||||
// clear the underlying List
|
// clear the underlying List
|
||||||
xB->clear();
|
xB->clear();
|
||||||
|
|
||||||
Info<< "xB size: " << *xB << endl;
|
Info<< "xB size: " << xB->size() << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,7 +93,7 @@ HashTable<T, Key, Hash>::HashTable(const xfer<HashTable<T, Key, Hash> >& ht)
|
|||||||
endIter_(*this, NULL, 0),
|
endIter_(*this, NULL, 0),
|
||||||
endConstIter_(*this, NULL, 0)
|
endConstIter_(*this, NULL, 0)
|
||||||
{
|
{
|
||||||
transfer(*ht);
|
transfer(ht());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -90,7 +90,7 @@ StaticHashTable<T, Key, Hash>::StaticHashTable
|
|||||||
endIter_(*this, 0, 0),
|
endIter_(*this, 0, 0),
|
||||||
endConstIter_(*this, 0, 0)
|
endConstIter_(*this, 0, 0)
|
||||||
{
|
{
|
||||||
transfer(*ht);
|
transfer(ht());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -95,7 +95,7 @@ CompactListList<T>::CompactListList(const UList<label>& rowSizes, const T& t)
|
|||||||
template<class T>
|
template<class T>
|
||||||
CompactListList<T>::CompactListList(const xfer<CompactListList<T> >& lst)
|
CompactListList<T>::CompactListList(const xfer<CompactListList<T> >& lst)
|
||||||
{
|
{
|
||||||
transfer(*lst);
|
transfer(lst());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
@ -129,7 +129,7 @@ Foam::List<T>::List(const List<T>& a)
|
|||||||
template<class T>
|
template<class T>
|
||||||
Foam::List<T>::List(const xfer<List<T> >& lst)
|
Foam::List<T>::List(const xfer<List<T> >& lst)
|
||||||
{
|
{
|
||||||
transfer(*lst);
|
transfer(lst());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@ PackedList<nBits>::PackedList(const PackedList<nBits>& PList)
|
|||||||
template<int nBits>
|
template<int nBits>
|
||||||
PackedList<nBits>::PackedList(const xfer<PackedList<nBits> >& lst)
|
PackedList<nBits>::PackedList(const xfer<PackedList<nBits> >& lst)
|
||||||
{
|
{
|
||||||
transfer(*lst);
|
transfer(lst());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -74,7 +74,7 @@ Foam::PtrList<T>::PtrList(const PtrList<T>& a, const CloneArg& cloneArg)
|
|||||||
template<class T>
|
template<class T>
|
||||||
Foam::PtrList<T>::PtrList(const xfer<PtrList<T> >& lst)
|
Foam::PtrList<T>::PtrList(const xfer<PtrList<T> >& lst)
|
||||||
{
|
{
|
||||||
transfer(*lst);
|
transfer(lst());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -45,9 +45,9 @@ template <class Type>
|
|||||||
Foam::SortableList<Type>::SortableList(const xfer<List<Type> >& values)
|
Foam::SortableList<Type>::SortableList(const xfer<List<Type> >& values)
|
||||||
:
|
:
|
||||||
List<Type>(),
|
List<Type>(),
|
||||||
indices_((*values).size())
|
indices_(values->size())
|
||||||
{
|
{
|
||||||
List<Type>::transfer(*values);
|
List<Type>::transfer(values());
|
||||||
sort();
|
sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -53,7 +53,7 @@ UPtrList<T>::UPtrList(const label s)
|
|||||||
template<class T>
|
template<class T>
|
||||||
UPtrList<T>::UPtrList(const xfer<UPtrList<T> >& lst)
|
UPtrList<T>::UPtrList(const xfer<UPtrList<T> >& lst)
|
||||||
{
|
{
|
||||||
transfer(*lst);
|
transfer(lst());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -87,6 +87,25 @@ Foam::IOField<Type>::IOField(const IOobject& io, const Field<Type>& f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Foam::IOField<Type>::IOField(const IOobject& io, const xfer<Field<Type> >& f)
|
||||||
|
:
|
||||||
|
regIOobject(io)
|
||||||
|
{
|
||||||
|
Field<Type>::transfer(f());
|
||||||
|
|
||||||
|
if
|
||||||
|
(
|
||||||
|
io.readOpt() == IOobject::MUST_READ
|
||||||
|
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
|
||||||
|
)
|
||||||
|
{
|
||||||
|
readStream(typeName) >> *this;
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
|
|||||||
@ -65,11 +65,14 @@ public:
|
|||||||
//- Construct from IOobject
|
//- Construct from IOobject
|
||||||
IOField(const IOobject&);
|
IOField(const IOobject&);
|
||||||
|
|
||||||
|
//- Construct from IOobject and size (does not set values)
|
||||||
|
IOField(const IOobject&, const label size);
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from components
|
||||||
IOField(const IOobject&, const Field<Type>&);
|
IOField(const IOobject&, const Field<Type>&);
|
||||||
|
|
||||||
//- Construct from IOobject and size (does not set values)
|
//- Construct by transferring the Field contents
|
||||||
IOField(const IOobject&, const label size);
|
IOField(const IOobject&, const xfer<Field<Type> >&);
|
||||||
|
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|||||||
@ -87,6 +87,25 @@ Foam::IOList<T>::IOList(const IOobject& io, const List<T>& list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::IOList<T>::IOList(const IOobject& io, const xfer<List<T> >& list)
|
||||||
|
:
|
||||||
|
regIOobject(io)
|
||||||
|
{
|
||||||
|
List<T>::transfer(list());
|
||||||
|
|
||||||
|
if
|
||||||
|
(
|
||||||
|
io.readOpt() == IOobject::MUST_READ
|
||||||
|
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
|
||||||
|
)
|
||||||
|
{
|
||||||
|
readStream(typeName) >> *this;
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
@ -72,6 +72,9 @@ public:
|
|||||||
//- Construct from IOobject and a List
|
//- Construct from IOobject and a List
|
||||||
IOList(const IOobject&, const List<T>&);
|
IOList(const IOobject&, const List<T>&);
|
||||||
|
|
||||||
|
//- Construct by transferring the List contents
|
||||||
|
IOList(const IOobject&, const xfer<List<T> >&);
|
||||||
|
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|
||||||
|
|||||||
@ -86,6 +86,25 @@ Foam::IOMap<T>::IOMap(const IOobject& io, const Map<T>& map)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::IOMap<T>::IOMap(const IOobject& io, const xfer<Map<T> >& map)
|
||||||
|
:
|
||||||
|
regIOobject(io)
|
||||||
|
{
|
||||||
|
Map<T>::transfer(map());
|
||||||
|
|
||||||
|
if
|
||||||
|
(
|
||||||
|
io.readOpt() == IOobject::MUST_READ
|
||||||
|
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
|
||||||
|
)
|
||||||
|
{
|
||||||
|
readStream(typeName) >> *this;
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
@ -66,11 +66,14 @@ public:
|
|||||||
//- Construct from IOobject
|
//- Construct from IOobject
|
||||||
IOMap(const IOobject&);
|
IOMap(const IOobject&);
|
||||||
|
|
||||||
|
//- Construct from IOobject and size of Map
|
||||||
|
IOMap(const IOobject&, const label);
|
||||||
|
|
||||||
//- Construct from IOobject and a Map
|
//- Construct from IOobject and a Map
|
||||||
IOMap(const IOobject&, const Map<T>&);
|
IOMap(const IOobject&, const Map<T>&);
|
||||||
|
|
||||||
//- Construct from IOobject and size of Map
|
//- Construct by transferring the Map contents
|
||||||
IOMap(const IOobject&, const label);
|
IOMap(const IOobject&, const xfer<Map<T> >&);
|
||||||
|
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|||||||
@ -84,6 +84,25 @@ Foam::IOPtrList<T>::IOPtrList(const IOobject& io, const PtrList<T>& list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::IOPtrList<T>::IOPtrList(const IOobject& io, const xfer<PtrList<T> >& list)
|
||||||
|
:
|
||||||
|
regIOobject(io)
|
||||||
|
{
|
||||||
|
PtrList<T>::transfer(list());
|
||||||
|
|
||||||
|
if
|
||||||
|
(
|
||||||
|
io.readOpt() == IOobject::MUST_READ
|
||||||
|
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PtrList<T>::read(readStream(typeName), INew<T>());
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
@ -73,6 +73,9 @@ public:
|
|||||||
//- Construct from IOobject and a PtrList
|
//- Construct from IOobject and a PtrList
|
||||||
IOPtrList(const IOobject&, const PtrList<T>&);
|
IOPtrList(const IOobject&, const PtrList<T>&);
|
||||||
|
|
||||||
|
//- Construct by transferring the PtrList contents
|
||||||
|
IOPtrList(const IOobject&, const xfer<PtrList<T> >&);
|
||||||
|
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
|
|
||||||
|
|||||||
@ -138,6 +138,19 @@ DimensionedField<Type, GeoMesh>::DimensionedField
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
DimensionedField<Type, GeoMesh>::DimensionedField
|
||||||
|
(
|
||||||
|
const xfer<DimensionedField<Type, GeoMesh> >& df
|
||||||
|
)
|
||||||
|
:
|
||||||
|
regIOobject(df(), true),
|
||||||
|
Field<Type>(df),
|
||||||
|
mesh_(df->mesh_),
|
||||||
|
dimensions_(df->dimensions_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
#ifdef ConstructFromTmp
|
#ifdef ConstructFromTmp
|
||||||
template<class Type, class GeoMesh>
|
template<class Type, class GeoMesh>
|
||||||
DimensionedField<Type, GeoMesh>::DimensionedField
|
DimensionedField<Type, GeoMesh>::DimensionedField
|
||||||
@ -202,6 +215,20 @@ DimensionedField<Type, GeoMesh>::DimensionedField
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
DimensionedField<Type, GeoMesh>::DimensionedField
|
||||||
|
(
|
||||||
|
const word& newName,
|
||||||
|
const xfer<DimensionedField<Type, GeoMesh> >& df
|
||||||
|
)
|
||||||
|
:
|
||||||
|
regIOobject(IOobject(newName, df->time().timeName(), df->db())),
|
||||||
|
Field<Type>(df),
|
||||||
|
mesh_(df->mesh_),
|
||||||
|
dimensions_(df->dimensions_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
#ifdef ConstructFromTmp
|
#ifdef ConstructFromTmp
|
||||||
template<class Type, class GeoMesh>
|
template<class Type, class GeoMesh>
|
||||||
DimensionedField<Type, GeoMesh>::DimensionedField
|
DimensionedField<Type, GeoMesh>::DimensionedField
|
||||||
|
|||||||
@ -156,6 +156,12 @@ public:
|
|||||||
bool reUse
|
bool reUse
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Construct by transferring the DimensionedField
|
||||||
|
DimensionedField
|
||||||
|
(
|
||||||
|
const xfer<DimensionedField<Type, GeoMesh> >&
|
||||||
|
);
|
||||||
|
|
||||||
//- Construct as copy of tmp<DimensionedField> deleting argument
|
//- Construct as copy of tmp<DimensionedField> deleting argument
|
||||||
# ifdef ConstructFromTmp
|
# ifdef ConstructFromTmp
|
||||||
DimensionedField
|
DimensionedField
|
||||||
@ -186,6 +192,13 @@ public:
|
|||||||
bool reUse
|
bool reUse
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Construct by transferring the DimensionedField with a new name
|
||||||
|
DimensionedField
|
||||||
|
(
|
||||||
|
const word& newName,
|
||||||
|
const xfer<DimensionedField<Type, GeoMesh> >&
|
||||||
|
);
|
||||||
|
|
||||||
//- Construct as copy resetting name
|
//- Construct as copy resetting name
|
||||||
# ifdef ConstructFromTmp
|
# ifdef ConstructFromTmp
|
||||||
DimensionedField
|
DimensionedField
|
||||||
|
|||||||
@ -37,6 +37,7 @@ SourceFiles
|
|||||||
#define FieldField_H
|
#define FieldField_H
|
||||||
|
|
||||||
#include "tmp.H"
|
#include "tmp.H"
|
||||||
|
#include "xfer.H"
|
||||||
#include "PtrList.H"
|
#include "PtrList.H"
|
||||||
#include "scalar.H"
|
#include "scalar.H"
|
||||||
#include "direction.H"
|
#include "direction.H"
|
||||||
|
|||||||
@ -155,6 +155,13 @@ Field<Type>::Field(Field<Type>& f, bool reUse)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
Field<Type>::Field(const xfer<Field<Type> >& f)
|
||||||
|
:
|
||||||
|
List<Type>(f)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
Field<Type>::Field(const typename Field<Type>::subField& sf)
|
Field<Type>::Field(const typename Field<Type>::subField& sf)
|
||||||
:
|
:
|
||||||
@ -568,6 +575,20 @@ void Field<Type>::replace
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Field<Type>::transfer(Field<Type>& f)
|
||||||
|
{
|
||||||
|
List<Type>::transfer(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type>
|
||||||
|
void Field<Type>::transfer(List<Type>& lst)
|
||||||
|
{
|
||||||
|
List<Type>::transfer(lst);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
tmp<Field<Type> > Field<Type>::T() const
|
tmp<Field<Type> > Field<Type>::T() const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -43,6 +43,7 @@ SourceFiles
|
|||||||
#define Field_H
|
#define Field_H
|
||||||
|
|
||||||
#include "tmp.H"
|
#include "tmp.H"
|
||||||
|
#include "xfer.H"
|
||||||
#include "direction.H"
|
#include "direction.H"
|
||||||
#include "VectorSpace.H"
|
#include "VectorSpace.H"
|
||||||
#include "scalarList.H"
|
#include "scalarList.H"
|
||||||
@ -164,6 +165,9 @@ public:
|
|||||||
//- Construct as copy or re-use as specified.
|
//- Construct as copy or re-use as specified.
|
||||||
Field(Field<Type>&, bool reUse);
|
Field(Field<Type>&, bool reUse);
|
||||||
|
|
||||||
|
//- Construct by transferring the Field contents
|
||||||
|
Field(const xfer<Field<Type> >&);
|
||||||
|
|
||||||
//- Construct as copy of subField
|
//- Construct as copy of subField
|
||||||
Field(const typename Field<Type>::subField&);
|
Field(const typename Field<Type>::subField&);
|
||||||
|
|
||||||
@ -293,6 +297,12 @@ public:
|
|||||||
//- Replace a component field of the field
|
//- Replace a component field of the field
|
||||||
void replace(const direction, const cmptType&);
|
void replace(const direction, const cmptType&);
|
||||||
|
|
||||||
|
//- Transfer the contents of the argument Field into this Field
|
||||||
|
void transfer(Field<Type>&);
|
||||||
|
|
||||||
|
//- Transfer the contents of the argument List into this Field
|
||||||
|
void transfer(List<Type>&);
|
||||||
|
|
||||||
//- Return the field transpose (only defined for second rank tensors)
|
//- Return the field transpose (only defined for second rank tensors)
|
||||||
tmp<Field<Type> > T() const;
|
tmp<Field<Type> > T() const;
|
||||||
|
|
||||||
|
|||||||
@ -39,10 +39,6 @@ Description
|
|||||||
The wrapped object of type \<T\> must implement a transfer() method and
|
The wrapped object of type \<T\> must implement a transfer() method and
|
||||||
an operator=() copy method.
|
an operator=() copy method.
|
||||||
|
|
||||||
Note
|
|
||||||
The macros xferCopy(T,arg) and xferMove(T,arg) can be used as
|
|
||||||
workarounds for passing temporaries to copy-constructors.
|
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
xferI.H
|
xferI.H
|
||||||
|
|
||||||
@ -56,6 +52,9 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward declaration of classes
|
||||||
|
template<class T> class tmp;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class xfer Declaration
|
Class xfer Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -97,12 +96,8 @@ public:
|
|||||||
//- Transfer the contents into the object
|
//- Transfer the contents into the object
|
||||||
inline void operator=(const xfer<T>&);
|
inline void operator=(const xfer<T>&);
|
||||||
|
|
||||||
//- Return a non-const reference to const object
|
|
||||||
// @sa xferCopy, xferMove macros alternatives for copy-constructors
|
|
||||||
inline const xfer<T>& operator()() const;
|
|
||||||
|
|
||||||
//- Reference to the underlying datatype
|
//- Reference to the underlying datatype
|
||||||
inline T& operator*() const;
|
inline T& operator()() const;
|
||||||
|
|
||||||
//- Pointer to the underlying datatype
|
//- Pointer to the underlying datatype
|
||||||
inline T* operator->() const;
|
inline T* operator->() const;
|
||||||
@ -112,40 +107,54 @@ public:
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def xferCopy(T,arg)
|
* @fn template<class T> xferCopy(const T&)
|
||||||
* Construct by copying the contents of the @a arg
|
* Construct by copying 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.
|
* @sa xferMove, xferTmp and Foam::xfer
|
||||||
* This is a workaround for a template resolution issue.
|
|
||||||
*
|
|
||||||
* @sa xferMove and Foam::xfer
|
|
||||||
*/
|
*/
|
||||||
#define xferCopy(T,arg) \
|
template<class T>
|
||||||
(static_cast<const Foam::xfer< T >&>(Foam::xfer< T >(arg)()))
|
Foam::xfer<T> xferCopy(const T& t)
|
||||||
|
{
|
||||||
|
return Foam::xfer<T>(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def xferMove(T,arg)
|
* @fn template<class T> xferMove(T&)
|
||||||
* Construct by transferring the contents of the @a 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(xferMove(List<label>, a));
|
* List<label> b(xferMove(a));
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @sa xferCopy and Foam::xfer
|
* @sa xferCopy, xferTmp and Foam::xfer
|
||||||
*/
|
*/
|
||||||
#define xferMove(T,arg) \
|
template<class T>
|
||||||
(static_cast<const Foam::xfer< T >&>(Foam::xfer< T >(arg, true)()))
|
Foam::xfer<T> xferMove(T& t)
|
||||||
|
{
|
||||||
|
return Foam::xfer<T>(t, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn template<class T> xferTmp(tmp<T>&)
|
||||||
|
* Construct by transferring the contents of the @a arg
|
||||||
|
*
|
||||||
|
* @sa xferCopy, xferMove and Foam::xfer
|
||||||
|
*/
|
||||||
|
template<class T>
|
||||||
|
Foam::xfer<T> xferTmp(Foam::tmp<T>& tt)
|
||||||
|
{
|
||||||
|
return Foam::xfer<T>(tt(), tt.isTmp());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|||||||
@ -98,18 +98,12 @@ inline void Foam::xfer<T>::operator=(const xfer<T>& t)
|
|||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline const Foam::xfer<T>& Foam::xfer<T>::operator()() const
|
inline T& Foam::xfer<T>::operator()() const
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline T& Foam::xfer<T>::operator*() const
|
|
||||||
{
|
{
|
||||||
return *ptr_;
|
return *ptr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline T* Foam::xfer<T>::operator->() const
|
inline T* Foam::xfer<T>::operator->() const
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user