Commit d5ac9d4c authored by Mark Olesen's avatar Mark Olesen
Browse files

LinkedLists cleanup

parent 625c7563
......@@ -26,22 +26,17 @@ License
#include "ILList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class LListBase, class T>
ILList<LListBase, T>::ILList(const ILList<LListBase, T>& slpl)
Foam::ILList<LListBase, T>::ILList(const ILList<LListBase, T>& lst)
:
UILList<LListBase, T>()
{
for
(
typename UILList<LListBase, T>::const_iterator iter = slpl.begin();
iter != slpl.end();
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
......@@ -53,9 +48,9 @@ ILList<LListBase, T>::ILList(const ILList<LListBase, T>& slpl)
#ifndef __INTEL_COMPILER
template<class LListBase, class T>
template<class CloneArg>
ILList<LListBase, T>::ILList
Foam::ILList<LListBase, T>::ILList
(
const ILList<LListBase, T>& slpl,
const ILList<LListBase, T>& lst,
const CloneArg& cloneArg
)
:
......@@ -63,8 +58,8 @@ ILList<LListBase, T>::ILList
{
for
(
typename UILList<LListBase, T>::const_iterator iter = slpl.begin();
iter != slpl.end();
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
......@@ -77,7 +72,7 @@ ILList<LListBase, T>::ILList
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
template<class LListBase, class T>
ILList<LListBase, T>::~ILList()
Foam::ILList<LListBase, T>::~ILList()
{
this->clear();
}
......@@ -85,9 +80,8 @@ ILList<LListBase, T>::~ILList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//- Return and remove head
template<class LListBase, class T>
bool ILList<LListBase, T>::eraseHead()
bool Foam::ILList<LListBase, T>::eraseHead()
{
T* tPtr;
if ((tPtr = this->removeHead()))
......@@ -101,9 +95,8 @@ bool ILList<LListBase, T>::eraseHead()
}
}
//- Return and remove element
template<class LListBase, class T>
bool ILList<LListBase, T>::erase(T* p)
bool Foam::ILList<LListBase, T>::erase(T* p)
{
T* tPtr;
if ((tPtr = remove(p)))
......@@ -119,7 +112,7 @@ bool ILList<LListBase, T>::erase(T* p)
template<class LListBase, class T>
void ILList<LListBase, T>::clear()
void Foam::ILList<LListBase, T>::clear()
{
label oldSize = this->size();
for (label i=0; i<oldSize; i++)
......@@ -134,14 +127,14 @@ void ILList<LListBase, T>::clear()
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class LListBase, class T>
void ILList<LListBase, T>::operator=(const ILList<LListBase, T>& slpl)
void Foam::ILList<LListBase, T>::operator=(const ILList<LListBase, T>& lst)
{
this->clear();
for
(
typename UILList<LListBase, T>::const_iterator iter = slpl.begin();
iter != slpl.end();
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
......@@ -149,11 +142,6 @@ void ILList<LListBase, T>::operator=(const ILList<LListBase, T>& slpl)
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
#include "ILListIO.C"
......
......@@ -71,7 +71,7 @@ class ILList
//- Read from Istream using given Istream constructor class
template<class INew>
void read(Istream&, const INew& inewt);
void read(Istream&, const INew&);
public:
......@@ -96,7 +96,7 @@ public:
//- Copy constructor with additional argument for clone
template<class CloneArg>
ILList(const ILList<LListBase, T>& slpl, const CloneArg& cloneArg)
ILList(const ILList<LListBase, T>& lst, const CloneArg& cloneArg)
#ifdef __INTEL_COMPILER
:
UILList<LListBase, T>()
......@@ -104,8 +104,8 @@ public:
for
(
typename UILList<LListBase, T>::const_iterator iter =
slpl.begin();
iter != slpl.end();
lst.begin();
iter != lst.end();
++iter
)
{
......@@ -118,7 +118,7 @@ public:
//- Construct from Istream using given Istream constructor class
template<class INew>
ILList(Istream&, const INew& inewt);
ILList(Istream&, const INew&);
// Destructor
......
......@@ -30,24 +30,19 @@ Description
#include "Istream.H"
#include "INew.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class LListBase, class T>
template<class INew>
void ILList<LListBase, T>::read(Istream& is, const INew& inewt)
void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
{
is.fatalCheck("operator>>(Istream& is, ILList<LListBase, T>& L)");
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
token firstToken(is);
is.fatalCheck
(
"operator>>(Istream& is, ILList<LListBase, T>& L) : reading first token"
"operator>>(Istream&, ILList<LListBase, T>&) : reading first token"
);
if (firstToken.isLabel())
......@@ -63,26 +58,26 @@ void ILList<LListBase, T>::read(Istream& is, const INew& inewt)
{
for (label i=0; i<s; i++)
{
append(inewt(is).ptr());
append(iNew(is).ptr());
is.fatalCheck
(
"operator>>(Istream& is, ILList<LListBase, T>& L) : "
"operator>>(Istream&, ILList<LListBase, T>&) : "
"reading entry"
);
}
}
else
{
T* tPtr = inewt(is).ptr();
T* tPtr = iNew(is).ptr();
append(tPtr);
is.fatalCheck
(
"operator>>(Istream& is, ILList<LListBase, T>& L) : "
"operator>>(Istream&, ILList<LListBase, T>&) : "
"reading entry"
);
for (label i=1; i<s; i++)
{
append(new T(*tPtr));
......@@ -99,14 +94,14 @@ void ILList<LListBase, T>::read(Istream& is, const INew& inewt)
{
FatalIOErrorIn
(
"operator>>(Istream& is, ILList<LListBase, T>& L)",
"operator>>(Istream&, ILList<LListBase, T>&)",
is
) << "incorrect first token, '(', found " << firstToken.info()
<< exit(FatalIOError);
}
token lastToken(is);
is.fatalCheck("operator>>(Istream& is, ILList<LListBase, T>& L)");
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
while
(
......@@ -117,36 +112,34 @@ void ILList<LListBase, T>::read(Istream& is, const INew& inewt)
)
{
is.putBack(lastToken);
append(inewt(is).ptr());
append(iNew(is).ptr());
is >> lastToken;
is.fatalCheck("operator>>(Istream& is, ILList<LListBase, T>& L)");
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
}
}
else
{
FatalIOErrorIn("operator>>(Istream& is, ILList<LListBase, T>& L)", is)
FatalIOErrorIn("operator>>(Istream&, ILList<LListBase, T>&)", is)
<< "incorrect first token, expected <int> or '(', found "
<< firstToken.info()
<< exit(FatalIOError);
}
is.fatalCheck("operator>>(Istream& is, ILList<LListBase, T>& L)");
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
}
//- Construct from Istream using given Istream constructor class
template<class LListBase, class T>
template<class INew>
ILList<LListBase, T>::ILList(Istream& is, const INew& inewt)
Foam::ILList<LListBase, T>::ILList(Istream& is, const INew& iNew)
{
read(is, inewt);
read(is, iNew);
}
// Construct from Istream
template<class LListBase, class T>
ILList<LListBase, T>::ILList(Istream& is)
Foam::ILList<LListBase, T>::ILList(Istream& is)
{
read(is, INew<T>());
}
......@@ -155,7 +148,7 @@ ILList<LListBase, T>::ILList(Istream& is)
// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
template<class LListBase, class T>
Istream& operator>>(Istream& is, ILList<LListBase, T>& L)
Foam::Istream& Foam::operator>>(Istream& is, ILList<LListBase, T>& L)
{
L.clear();
L.read(is, INew<T>());
......@@ -166,6 +159,4 @@ Istream& operator>>(Istream& is, ILList<LListBase, T>& L)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -27,22 +27,16 @@ Description
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "LList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class LListBase, class T>
LList<LListBase, T>::LList(const LList<LListBase, T>& slpl)
Foam::LList<LListBase, T>::LList(const LList<LListBase, T>& lst)
:
LListBase()
{
for (const_iterator iter = slpl.begin(); iter != slpl.end(); ++iter)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter());
}
......@@ -50,7 +44,7 @@ LList<LListBase, T>::LList(const LList<LListBase, T>& slpl)
template<class LListBase, class T>
LList<LListBase, T>::~LList()
Foam::LList<LListBase, T>::~LList()
{
this->clear();
}
......@@ -59,7 +53,7 @@ LList<LListBase, T>::~LList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class LListBase, class T>
void LList<LListBase, T>::clear()
void Foam::LList<LListBase, T>::clear()
{
label oldSize = this->size();
for (label i=0; i<oldSize; i++)
......@@ -74,21 +68,17 @@ void LList<LListBase, T>::clear()
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class LListBase, class T>
void LList<LListBase, T>::operator=(const LList<LListBase, T>& slpl)
void Foam::LList<LListBase, T>::operator=(const LList<LListBase, T>& lst)
{
this->clear();
for (const_iterator iter = slpl.begin(); iter != slpl.end(); ++iter)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter());
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
#include "LListIO.C"
......
......@@ -67,7 +67,7 @@ Ostream& operator<<
/*---------------------------------------------------------------------------*\
Class LList Declaration
Class LList Declaration
\*---------------------------------------------------------------------------*/
template<class LListBase, class T>
......
......@@ -30,16 +30,10 @@ Description
#include "Istream.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from Istream
template<class LListBase, class T>
LList<LListBase, T>::LList(Istream& is)
Foam::LList<LListBase, T>::LList(Istream& is)
{
operator>>(is, *this);
}
......@@ -48,18 +42,18 @@ LList<LListBase, T>::LList(Istream& is)
// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
template<class LListBase, class T>
Istream& operator>>(Istream& is, LList<LListBase, T>& L)
Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
{
// Anull list
L.clear();
is.fatalCheck(" operator>>(Istream& is, LList<LListBase, T>& L)");
is.fatalCheck(" operator>>(Istream&, LList<LListBase, T>&)");
token firstToken(is);
is.fatalCheck
(
" operator>>(Istream& is, LList<LListBase, T>& L) : reading first token"
" operator>>(Istream&, LList<LListBase, T>&) : reading first token"
);
if (firstToken.isLabel())
......@@ -101,14 +95,14 @@ Istream& operator>>(Istream& is, LList<LListBase, T>& L)
{
FatalIOErrorIn
(
" operator>>(Istream& is, LList<LListBase, T>& L)",
" operator>>(Istream&, LList<LListBase, T>&)",
is
) << "incorrect first token, '(', found " << firstToken.info()
<< exit(FatalIOError);
}
token lastToken(is);
is.fatalCheck(" operator>>(Istream& is, LList<LListBase, T>& L)");
is.fatalCheck(" operator>>(Istream&, LList<LListBase, T>&)");
while
(
......@@ -124,19 +118,19 @@ Istream& operator>>(Istream& is, LList<LListBase, T>& L)
L.append(element);
is >> lastToken;
is.fatalCheck(" operator>>(Istream& is, LList<LListBase, T>& L)");
is.fatalCheck(" operator>>(Istream&, LList<LListBase, T>&)");
}
}
else
{
FatalIOErrorIn(" operator>>(Istream& is, LList<LListBase, T>& L)", is)
FatalIOErrorIn(" operator>>(Istream&, LList<LListBase, T>&)", is)
<< "incorrect first token, expected <int> or '(', found "
<< firstToken.info()
<< exit(FatalIOError);
}
// Check state of IOstream
is.fatalCheck(" operator>>(Istream& is, LList<LListBase, T>& L)");
is.fatalCheck(" operator>>(Istream&, LList<LListBase,>&)");
return is;
}
......@@ -145,19 +139,19 @@ Istream& operator>>(Istream& is, LList<LListBase, T>& L)
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<class LListBase, class T>
Ostream& operator<<(Ostream& os, const LList<LListBase, T>& ll)
Foam::Ostream& Foam::operator<<(Ostream& os, const LList<LListBase, T>& lst)
{
// Write size of LList
os << nl << ll.size();
// Write size
os << nl << lst.size();
// Write beginning of contents
os << nl << token::BEGIN_LIST << nl;
// Write LList contents
// Write contents
for
(
typename LList<LListBase, T>::const_iterator iter = ll.begin();
iter != ll.end();
typename LList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
......@@ -168,14 +162,10 @@ Ostream& operator<<(Ostream& os, const LList<LListBase, T>& ll)
os << token::END_LIST;
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const LList&)");
os.check("Ostream& operator<<(Ostream&, const LList<LListBase, T>&)");
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -34,11 +34,11 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class LListBase, class T>
LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& slpl)
LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& lst)
:
LList<LListBase, T*>()
{
for(const_iterator iter = slpl.begin(); iter != slpl.end(); ++iter)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter().clone().ptr());
}
......@@ -89,11 +89,11 @@ void LPtrList<LListBase, T>::clear()
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class LListBase, class T>
void LPtrList<LListBase, T>::operator=(const LPtrList<LListBase, T>& slpl)
void LPtrList<LListBase, T>::operator=(const LPtrList<LListBase, T>& lst)
{
clear();
for(const_iterator iter = slpl.begin(); iter != slpl.end(); ++iter)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter().clone().ptr());
}
......
......@@ -29,16 +29,11 @@ License
#include "Ostream.H"
#include "INew.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class LListBase, class T>
template<class INew>
void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
{
is.fatalCheck
(
......@@ -66,8 +61,8 @@ void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
{
for (label i=0; i<s; i++)
{
append(inewt(is).ptr());
append(iNew(is).ptr());
is.fatalCheck
(
"LPtrList<LListBase, T>::read(Istream&, const INew&) : "
......@@ -77,7 +72,7 @@ void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
}
else
{
T* tPtr = inewt(is).ptr();
T* tPtr = iNew(is).ptr();
append(tPtr);
is.fatalCheck
......@@ -85,7 +80,7 @@ void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
"LPtrList<LListBase, T>::read(Istream&, const INew&) : "
"reading entry"
);
for (label i=1; i<s; i++)
{
append(tPtr->clone().ptr());
......@@ -120,7 +115,7 @@ void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
)
{
is.putBack(lastToken);
append(inewt(is).ptr());
append(iNew(is).ptr());
is >> lastToken;
is.fatalCheck
......@@ -148,14 +143,14 @@ void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
template<class LListBase, class T>
template<class INew>
LPtrList<LListBase, T>::LPtrList(Istream& is, const INew& inewt)
Foam::LPtrList<LListBase, T>::LPtrList(Istream& is, const INew& iNew)
{
read(is, inewt);
read(is, iNew);
}
template<class LListBase, class T>
LPtrList<LListBase, T>::LPtrList(Istream& is)
Foam::LPtrList<LListBase, T>::LPtrList(Istream& is)
{
read(is, INew<T>());
}
......@@ -164,11 +159,10 @@ LPtrList<LListBase, T>::LPtrList(Istream& is)
// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //