Commit 91cb6d29 authored by Mark Olesen's avatar Mark Olesen
Browse files

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
parent 5cca2643
......@@ -52,35 +52,35 @@ int main(int argc, char *argv[])
Info<< "lstA: " << lstA << endl;
Info<< "lstC: " << lstC << endl;
xfer<List<label> > xA(lstA, true);
xfer<List<label> > xA = xferMove(lstA);
xfer<List<label> > xB;
List<label> lstB( xA );
Info<< "xA: " << *xA << endl;
Info<< "xB: " << *xB << endl;
Info<< "xA: " << xA() << endl;
Info<< "xB: " << xB() << endl;
Info<< "lstA: " << lstA << endl;
Info<< "lstB: " << lstB << endl;
Info<< "lstC: " << lstC << endl;
xA = lstB;
Info<< "xA: " << *xA << endl;
Info<< "xB: " << *xB << endl;
Info<< "xA: " << xA() << endl;
Info<< "xB: " << xB() << endl;
Info<< "lstA: " << lstA << endl;
Info<< "lstB: " << lstB << endl;
Info<< "lstC: " << lstC << endl;
xB = xA;
List<label> lstD( xferCopy(List<label>, lstC) );
List<label> lstE( xferMove(List<label>, lstC) );
List<label> lstD(xferCopy(lstC));
List<label> lstE(xferMove(lstC));
// this must be empty
List<label> lstF( xferCopy(List<label>, lstC) );
List<label> lstF = xferCopy(lstC);
Info<< "xA: " << *xA << endl;
Info<< "xB: " << *xB << endl;
Info<< "xA: " << xA() << endl;
Info<< "xB: " << xB() << endl;
Info<< "lstA: " << lstA << endl;
Info<< "lstB: " << lstB << endl;
Info<< "lstC: " << lstC << endl;
......@@ -88,12 +88,12 @@ int main(int argc, char *argv[])
Info<< "lstE: " << lstE << endl;
Info<< "lstF: " << lstF << endl;
Info<< "xB size: " << *xB << endl;
Info<< "xB size: " << xB->size() << endl;
// clear the underlying List
xB->clear();
Info<< "xB size: " << *xB << endl;
Info<< "xB size: " << xB->size() << endl;
return 0;
}
......
......@@ -93,7 +93,7 @@ HashTable<T, Key, Hash>::HashTable(const xfer<HashTable<T, Key, Hash> >& ht)
endIter_(*this, NULL, 0),
endConstIter_(*this, NULL, 0)
{
transfer(*ht);
transfer(ht());
}
......
......@@ -90,7 +90,7 @@ StaticHashTable<T, Key, Hash>::StaticHashTable
endIter_(*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>
CompactListList<T>::CompactListList(const xfer<CompactListList<T> >& lst)
{
transfer(*lst);
transfer(lst());
}
template<class T>
......
......@@ -129,7 +129,7 @@ Foam::List<T>::List(const List<T>& a)
template<class T>
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>
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>
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)
:
List<Type>(),
indices_((*values).size())
indices_(values->size())
{
List<Type>::transfer(*values);
List<Type>::transfer(values());
sort();
}
......
......@@ -53,7 +53,7 @@ UPtrList<T>::UPtrList(const label s)
template<class T>
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 * * * * * * * * * * * * * * * * //
template<class Type>
......
......@@ -65,11 +65,14 @@ public:
//- Construct from IOobject
IOField(const IOobject&);
//- Construct from IOobject and size (does not set values)
IOField(const IOobject&, const label size);
//- Construct from components
IOField(const IOobject&, const Field<Type>&);
//- Construct from IOobject and size (does not set values)
IOField(const IOobject&, const label size);
//- Construct by transferring the Field contents
IOField(const IOobject&, const xfer<Field<Type> >&);
// 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 * * * * * * * * * * * * * * * * //
template<class T>
......
......@@ -72,6 +72,9 @@ public:
//- Construct from IOobject and a List
IOList(const IOobject&, const List<T>&);
//- Construct by transferring the List contents
IOList(const IOobject&, const xfer<List<T> >&);
// 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 * * * * * * * * * * * * * * * * //
template<class T>
......
......@@ -66,11 +66,14 @@ public:
//- Construct from IOobject
IOMap(const IOobject&);
//- Construct from IOobject and size of Map
IOMap(const IOobject&, const label);
//- Construct from IOobject and a Map
IOMap(const IOobject&, const Map<T>&);
//- Construct from IOobject and size of Map
IOMap(const IOobject&, const label);
//- Construct by transferring the Map contents
IOMap(const IOobject&, const xfer<Map<T> >&);
// 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 * * * * * * * * * * * * * * * * //
template<class T>
......
......@@ -73,6 +73,9 @@ public:
//- Construct from IOobject and a PtrList
IOPtrList(const IOobject&, const PtrList<T>&);
//- Construct by transferring the PtrList contents
IOPtrList(const IOobject&, const xfer<PtrList<T> >&);
// 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
template<class Type, class GeoMesh>
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
template<class Type, class GeoMesh>
DimensionedField<Type, GeoMesh>::DimensionedField
......@@ -248,7 +275,7 @@ DimensionedField<Type, GeoMesh>::~DimensionedField()
template<class Type, class GeoMesh>
const DimensionedField<Type, GeoMesh>& DimensionedField<Type, GeoMesh>::null()
{
DimensionedField<Type, GeoMesh>* nullPtr =
DimensionedField<Type, GeoMesh>* nullPtr =
reinterpret_cast<DimensionedField<Type, GeoMesh>*>(NULL);
return *nullPtr;
}
......@@ -258,8 +285,8 @@ template<class Type, class GeoMesh>
tmp
<
DimensionedField
<typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
>
<typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
>
DimensionedField<Type, GeoMesh>::component
(
const direction d
......@@ -315,7 +342,7 @@ void DimensionedField<Type, GeoMesh>::replace
template<class Type, class GeoMesh>
tmp<DimensionedField<Type, GeoMesh> >
tmp<DimensionedField<Type, GeoMesh> >
DimensionedField<Type, GeoMesh>::T() const
{
tmp<DimensionedField<Type, GeoMesh> > result
......
......@@ -49,7 +49,7 @@ namespace Foam
{
// Forward declaration of friend functions and operators
template<class Type, class GeoMesh> class DimensionedField;
template<class Type, class GeoMesh> Ostream& operator<<
......@@ -156,6 +156,12 @@ public:
bool reUse
);
//- Construct by transferring the DimensionedField
DimensionedField
(
const xfer<DimensionedField<Type, GeoMesh> >&
);
//- Construct as copy of tmp<DimensionedField> deleting argument
# ifdef ConstructFromTmp
DimensionedField
......@@ -186,6 +192,13 @@ public:
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
# ifdef ConstructFromTmp
DimensionedField
......
......@@ -37,6 +37,7 @@ SourceFiles
#define FieldField_H
#include "tmp.H"
#include "xfer.H"
#include "PtrList.H"
#include "scalar.H"
#include "direction.H"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment