Commit 3efb4ebe authored by mattijs's avatar mattijs
Browse files

merge from master

parent 4c5ebb4c
......@@ -43,20 +43,58 @@ int main(int argc, char *argv[])
ldl[0](3) = 3;
ldl[0](1) = 1;
ldl[1](0) = 1;
ldl[1](1) = 2;
ldl[0].setSize(5); // increase allocated size
ldl[1].setSize(10); // increase allocated size
ldl[1](2) = 2;
ldl[1] = 3;
Info<< ldl[1];
Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
forAll(ldl, i)
{
Info<< " " << ldl[i].size() << "/" << ldl[i].allocSize();
}
Info<< endl;
List<List<label> > ll(2);
ll[0].transfer(ldl[0].shrink());
ll[0].transfer(ldl[0]);
ll[1].transfer(ldl[1].shrink());
Info<< ll << endl;
Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
forAll(ldl, i)
{
Info<< " " << ldl[i].size() << "/" << ldl[i].allocSize();
}
Info<< endl;
Info<< "<ll>" << ll << "</ll>" << nl << endl;
// test the transfer between DynamicLists
DynamicList<label, 1, 0> dlA;
DynamicList<label, 1, 0> dlB;
for (label i = 0; i < 5; i++)
{
dlA.append(i);
}
dlA.setSize(10);
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.allocSize() << endl;
dlB.transfer(dlA);
// provokes memory error if previous transfer did not maintain
// the correct allocated space
dlB[6] = 6;
Info<< "Transferred to dlB" << endl;
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.allocSize() << endl;
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.allocSize() << endl;
Info << "\nEnd\n" << endl;
return 0;
}
......
......@@ -52,34 +52,48 @@ 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( xferTmp(List<label>, lstC) );
// List<label> lstB( xfer<List<label> >(lstC) );
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(lstC));
List<label> lstE(xferMove(lstC));
// this must be empty
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;
Info<< "lstD: " << lstD << endl;
Info<< "lstE: " << lstE << endl;
Info<< "lstF: " << lstF << endl;
Info<< "xB size: " << xB->size() << endl;
// clear the underlying List
xB->clear();
Info<< "xB size: " << xB->size() << endl;
return 0;
}
......
......@@ -121,7 +121,7 @@ unset MPI_ARCH_PATH
switch ("$WM_MPLIB")
case OPENMPI:
set mpi_version=openmpi-1.2.6
set mpi_version=openmpi-1.2.8
setenv MPI_HOME $WM_THIRD_PARTY_DIR/$mpi_version
setenv MPI_ARCH_PATH $MPI_HOME/platforms/$WM_OPTIONS
......
......@@ -151,7 +151,7 @@ unset MPI_ARCH_PATH
case "$WM_MPLIB" in
OPENMPI)
mpi_version=openmpi-1.2.6
mpi_version=openmpi-1.2.8
export MPI_HOME=$WM_THIRD_PARTY_DIR/$mpi_version
export MPI_ARCH_PATH=$MPI_HOME/platforms/$WM_OPTIONS
......
......@@ -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>
......
......@@ -115,39 +115,36 @@ public:
// Access
//- Size of the underlying storage.
inline label allocSize() const;
//- Size of the underlying storage.
inline label allocSize() const;
// Edit
//- Alter the list size.
// When the new size is greater than the addressed list size, the
// allocated list sizes is adjusted and the
// addressed size does not change.
// Otherwise the addressed list size is just reduced and the
// allocated size does not change.
inline void setSize(const label);
//- Alter the list size.
// When the new size is greater than the addressed list size, the
// allocated list sizes is adjusted and the
// addressed size does not change.
// Otherwise the addressed list size is just reduced and the
// allocated size does not change.
inline void setSize(const label);
//- Clear the list, i.e. set the size to zero.
// Allocated size does not change
inline void clear();
//- Clear the list, i.e. set the size to zero.
// Allocated size does not change
inline void clear();
//- Clear the list and delete storage.
inline void clearStorage();
//- Clear the list and delete storage.
inline void clearStorage();
//- Shrink the List<T> to the number of elements used
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink();
//- Shrink the allocated space to the number of elements used.
// Returns a reference to the DynamicList.
inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink();
//- Transfer the contents of the argument List into this List
// and annull the argument list. Is same as List::transfer except
// checks that you're not changing the underlying list to something
// smaller than allocSize_.
inline void transfer(List<T>&);
//- Transfer contents of the argument List into this DynamicList
inline void transfer(List<T>&);
//- Transfer the contents of the argument DynamicList into this
// DynamicList and annull the argument list.
inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
//- Transfer contents of the argument DynamicList into this DynamicList
inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
// Member Operators
......@@ -158,8 +155,7 @@ public:
//- Remove and return the top element
inline T remove();
//- Return non-const access to an element,
// resizing the list if necessary
//- Return non-const access to an element, resizing list if necessary
inline T& operator()(const label);
//- Assignment of all addressed entries to the given value
......
......@@ -26,7 +26,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct null
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList()
:
......@@ -37,7 +36,6 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList()
}
//- Construct given size
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
(
......@@ -51,15 +49,14 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
}
//- Construct given size
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
(
const UList<T>& s
const UList<T>& lst
)
:
List<T>(s),
allocSize_(s.size())
List<T>(lst),
allocSize_(lst.size())
{}
......@@ -114,31 +111,24 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>&
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::shrink()
{
allocSize_ = List<T>::size();
List<T>::setSize(allocSize_);
if (allocSize_ > List<T>::size())
{
allocSize_ = List<T>::size();
// force re-allocation/copying in List<T>::setSize() by temporarily
// faking a larger list size that will be truncated
List<T>::size(allocSize_+1);
List<T>::setSize(allocSize_);
}
return *this;
}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer(List<T>& l)
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer(List<T>& lst)
{
if (l.size() < List<T>::size())
{
FatalErrorIn
(
"void DynamicList<T, SizeInc, SizeMult"
", SizeDiv>::transfer(List<T>&)"
) << "Cannot replace the underlying storage of this DynamicList"
<< " of which " << List<T>::size() << " elements are used" << nl
<< "with a List of size " << l.size() << abort(FatalError);
}
else
{
allocSize_ = l.size();
List<T>::transfer(l); // take over storage
}
allocSize_ = lst.size();
List<T>::transfer(lst); // take over storage, clear addressing for lst.
}
......@@ -146,11 +136,14 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer
(
DynamicList<T, SizeInc, SizeMult, SizeDiv>& l
DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
)
{
allocSize_ = l.allocSize();
List<T>::transfer(l); // take over storage. Null l.
// take over storage as-is (without shrink), clear addressing for lst.
allocSize_ = lst.allocSize_;
lst.allocSize_ = 0;
List<T>::transfer(static_cast<List<T>&>(lst));
}
......@@ -240,10 +233,13 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
(
const List<T>& l
const List<T>& lst
)
{
List<T>::operator=(l);
// make the entire storage available for the copy operation:
List<T>::size(allocSize_);
List<T>::operator=(lst);
allocSize_ = List<T>::size();
}
......
......@@ -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());
}
......@@ -430,6 +430,9 @@ template<class T>
template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
void Foam::List<T>::transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>& a)
{
// shrink the allocated space to the number of elements used
a.shrink();
if (this->v_) delete[] this->v_;
this->size_ = a.size_;
this->v_ = a.v_;
......
......@@ -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();
}
......
......@@ -45,7 +45,7 @@ void Foam::UList<T>::assign(const UList<T>& a)
{
if (a.size_ != this->size_)
{
FatalErrorIn("UList<T>::operator=(const UList<T>&)")
FatalErrorIn("UList<T>::assign(const UList<T>&)")
<< "ULists have different sizes: "
<< this->size_ << " " << a.size_
<< abort(FatalError);
......
......@@ -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>
......
Supports Markdown
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