Linked lists update

This commit is contained in:
Hrvoje Jasak 2016-08-11 15:05:46 +01:00
parent 09baafc79a
commit 4bc6ab309c
15 changed files with 68 additions and 123 deletions

View file

@ -44,7 +44,6 @@ Foam::ILList<LListBase, T>::ILList(const ILList<LListBase, T>& lst)
}
#ifndef __INTEL_COMPILER
template<class LListBase, class T>
template<class CloneArg>
Foam::ILList<LListBase, T>::ILList
@ -65,7 +64,6 @@ Foam::ILList<LListBase, T>::ILList
this->append(iter().clone(cloneArg).ptr());
}
}
#endif
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
@ -114,7 +112,7 @@ template<class LListBase, class T>
void Foam::ILList<LListBase, T>::clear()
{
label oldSize = this->size();
for (label i=0; i<oldSize; i++)
for (label i=0; i<oldSize; ++i)
{
eraseHead();
}

View file

@ -66,7 +66,7 @@ class ILList
:
public UILList<LListBase, T>
{
// Private member functions
// Private Member Functions
//- Read from Istream using given Istream constructor class
template<class INew>
@ -95,34 +95,15 @@ public:
//- Copy constructor with additional argument for clone
template<class CloneArg>
ILList(const ILList<LListBase, T>& lst, const CloneArg& cloneArg)
#ifdef __INTEL_COMPILER
:
UILList<LListBase, T>()
{
for
(
typename UILList<LListBase, T>::const_iterator iter =
lst.begin();
iter != lst.end();
++iter
)
{
append(iter().clone(cloneArg).ptr());
}
}
#else
;
#endif
ILList(const ILList<LListBase, T>& lst, const CloneArg& cloneArg);
//- Construct from Istream using given Istream constructor class
template<class INew>
ILList(Istream&, const INew&);
// Destructor
~ILList();
//- Destructor
~ILList();
// Member Functions
@ -139,7 +120,7 @@ public:
void clear();
//- Transfer the contents of the argument into this List
// and annull the argument list.
// and annul the argument list.
void transfer(ILList<LListBase, T>&);

View file

@ -21,8 +21,6 @@ License
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "ILList.H"
@ -55,7 +53,7 @@ void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
{
if (delimiter == token::BEGIN_LIST)
{
for (label i=0; i<s; i++)
for (label i=0; i<s; ++i)
{
this->append(iNew(is).ptr());
@ -77,7 +75,7 @@ void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
"reading entry"
);
for (label i=1; i<s; i++)
for (label i=1; i<s; ++i)
{
this->append(new T(*tPtr));
}
@ -133,14 +131,14 @@ template<class LListBase, class T>
template<class INew>
Foam::ILList<LListBase, T>::ILList(Istream& is, const INew& iNew)
{
read(is, iNew);
this->read(is, iNew);
}
template<class LListBase, class T>
Foam::ILList<LListBase, T>::ILList(Istream& is)
{
read(is, INew<T>());
this->read(is, INew<T>());
}
@ -156,6 +154,4 @@ Foam::Istream& Foam::operator>>(Istream& is, ILList<LListBase, T>& L)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View file

@ -37,7 +37,7 @@ Foam::LList<LListBase, T>::LList(const LList<LListBase, T>& lst)
{
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter());
this->append(iter());
}
}
@ -55,9 +55,9 @@ template<class LListBase, class T>
void Foam::LList<LListBase, T>::clear()
{
label oldSize = this->size();
for (label i=0; i<oldSize; i++)
for (label i=0; i<oldSize; ++i)
{
removeHead();
this->removeHead();
}
LListBase::clear();
@ -81,7 +81,7 @@ void Foam::LList<LListBase, T>::operator=(const LList<LListBase, T>& lst)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter());
this->append(iter());
}
}

View file

@ -122,9 +122,8 @@ public:
LList(const LList<LListBase, T>&);
// Destructor
~LList();
//- Destructor
~LList();
// Member Functions
@ -201,9 +200,10 @@ public:
void clear();
//- Transfer the contents of the argument into this List
// and annull the argument list.
// and annul the argument list.
void transfer(LList<LListBase, T>&);
// Member operators
void operator=(const LList<LListBase, T>&);
@ -239,10 +239,7 @@ public:
public:
//- Construct from base iterator
iterator
(
LListBase_iterator baseIter
)
iterator(LListBase_iterator baseIter)
:
LListBase_iterator(baseIter)
{}
@ -283,20 +280,14 @@ public:
public:
//- Construct from base const_iterator
const_iterator
(
LListBase_const_iterator baseIter
)
const_iterator(LListBase_const_iterator baseIter)
:
LListBase_const_iterator(baseIter)
{}
//- Construct from base iterator
const_iterator
(
LListBase_iterator baseIter
)
const_iterator(LListBase_iterator baseIter)
:
LListBase_const_iterator(baseIter)
{}

View file

@ -66,7 +66,7 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
{
if (delimiter == token::BEGIN_LIST)
{
for (register label i=0; i<s; i++)
for (label i=0; i<s; ++i)
{
T element;
is >> element;
@ -78,7 +78,7 @@ Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
T element;
is >> element;
for (register label i=0; i<s; i++)
for (label i=0; i<s; ++i)
{
L.append(element);
}

View file

@ -34,7 +34,7 @@ Foam::LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& lst)
{
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter().clone().ptr());
this->append(iter().clone().ptr());
}
}
@ -44,7 +44,7 @@ Foam::LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& lst)
template<class LListBase, class T>
Foam::LPtrList<LListBase, T>::~LPtrList()
{
clear();
this->clear();
}
@ -69,8 +69,8 @@ bool Foam::LPtrList<LListBase, T>::eraseHead()
template<class LListBase, class T>
void Foam::LPtrList<LListBase, T>::clear()
{
label oldSize = this->size();
for (label i=0; i<oldSize; i++)
const label oldSize = this->size();
for (label i=0; i<oldSize; ++i)
{
eraseHead();
}
@ -96,7 +96,7 @@ void Foam::LPtrList<LListBase, T>::operator=(const LPtrList<LListBase, T>& lst)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter().clone().ptr());
this->append(iter().clone().ptr());
}
}

View file

@ -71,11 +71,11 @@ class LPtrList
:
public LList<LListBase, T*>
{
// Private member functions
// Private Member Functions
//- Read from Istream using given Istream constructor class
template<class INew>
void read(Istream&, const INew& inewt);
void read(Istream&, const INew&);
public:
@ -112,9 +112,8 @@ public:
LPtrList(const LPtrList&);
// Destructor
~LPtrList();
//- Destructor
~LPtrList();
// Member Functions
@ -155,7 +154,7 @@ public:
void clear();
//- Transfer the contents of the argument into this List
// and annull the argument list.
// and annul the argument list.
void transfer(LPtrList<LListBase, T>&);
@ -189,10 +188,7 @@ public:
public:
//- Construct from base iterator
iterator
(
LListBase_iterator baseIter
)
iterator(LListBase_iterator baseIter)
:
LList<LListBase, T*>::iterator(baseIter)
{}
@ -225,19 +221,13 @@ public:
public:
//- Construct from base const_iterator
const_iterator
(
LListBase_const_iterator baseIter
)
const_iterator(LListBase_const_iterator baseIter)
:
LList<LListBase, T*>::const_iterator(baseIter)
{}
//- Construct from base iterator
const_iterator
(
LListBase_iterator baseIter
)
const_iterator(LListBase_iterator baseIter)
:
LList<LListBase, T*>::const_iterator(baseIter)
{}

View file

@ -58,7 +58,7 @@ void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
{
if (delimiter == token::BEGIN_LIST)
{
for (label i=0; i<s; i++)
for (label i=0; i<s; ++i)
{
this->append(iNew(is).ptr());
@ -80,7 +80,7 @@ void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
"reading entry"
);
for (label i=1; i<s; i++)
for (label i=1; i<s; ++i)
{
this->append(tPtr->clone().ptr());
}

View file

@ -34,7 +34,7 @@ Foam::UILList<LListBase, T>::UILList(const UILList<LListBase, T>& lst)
{
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(&iter());
this->append(&iter());
}
}
@ -48,7 +48,7 @@ void Foam::UILList<LListBase, T>::operator=(const UILList<LListBase, T>& rhs)
for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
{
append(&iter());
this->append(&iter());
}
}

View file

@ -181,10 +181,7 @@ public:
public:
//- Construct from base iterator
iterator
(
LListBase_iterator baseIter
)
iterator(LListBase_iterator baseIter)
:
LListBase_iterator(baseIter)
{}
@ -223,19 +220,13 @@ public:
public:
//- Construct from base const_iterator
const_iterator
(
LListBase_const_iterator baseIter
)
const_iterator(LListBase_const_iterator baseIter)
:
LListBase_const_iterator(baseIter)
{}
//- Construct from base iterator
const_iterator
(
LListBase_iterator baseIter
)
const_iterator(LListBase_iterator baseIter)
:
LListBase_const_iterator(baseIter)
{}

View file

@ -94,23 +94,23 @@ bool Foam::DLListBase::swapUp(DLListBase::link* a)
if (ap == first_)
{
first_ = a;
ap->prev_ = a;
}
else
{
ap->prev_->next_ = a;
}
if (a == last_)
{
last_ = ap;
a->next_ = ap;
}
if (a->next_)
else
{
a->next_->prev_ = ap;
}
if (ap->prev_)
{
ap->prev_->next_ = a;
}
a->prev_ = ap->prev_;
ap->prev_ = a;
@ -135,19 +135,19 @@ bool Foam::DLListBase::swapDown(DLListBase::link* a)
if (a == first_)
{
first_ = an;
a->prev_ = an;
}
else
{
a->prev_->next_ = an;
}
if (an == last_)
{
last_ = a;
an->next_ = a;
}
if (a->prev_)
{
a->prev_->next_ = an;
}
if (an->next_)
else
{
an->next_->prev_ = a;
}

View file

@ -81,7 +81,7 @@ private:
label nElmts_;
// Private member functions
// Private Member Functions
//- Disallow default bitwise copy construct
DLListBase(const DLListBase&);
@ -110,9 +110,8 @@ public:
inline DLListBase(link*);
// Destructor
~DLListBase();
//- Destructor
~DLListBase();
// Member Functions
@ -171,7 +170,7 @@ public:
inline void clear();
//- Transfer the contents of the argument into this List
// and annull the argument list.
// and annul the argument list.
inline void transfer(DLListBase&);
// STL iterator
@ -263,7 +262,7 @@ public:
private:
//- iterator returned by end()
//- Iterator returned by end()
static iterator endIter_;
//- const_iterator returned by end()

View file

@ -78,7 +78,7 @@ private:
//- Number of elements in in list
label nElmts_;
// Private member functions
// Private Member Functions
//- Disallow default bitwise copy construct
SLListBase(const SLListBase&);
@ -107,9 +107,8 @@ public:
inline SLListBase(link*);
// Destructor
~SLListBase();
//- Destructor
~SLListBase();
// Member Functions
@ -156,7 +155,7 @@ public:
inline void clear();
//- Transfer the contents of the argument into this List
// and annull the argument list.
// and annul the argument list.
inline void transfer(SLListBase&);
// STL iterator
@ -250,7 +249,7 @@ public:
private:
//- iterator returned by end()
//- Iterator returned by end()
static iterator endIter_;
//- const_iterator returned by end()

View file

@ -65,7 +65,7 @@ public:
{}
//- Construct from Istream
SLList(Istream& is)
explicit SLList(Istream& is)
:
LList<SLListBase, T>(is)
{}