Loading...
Searching...
No Matches
List< T > Class Template Reference

`#include <ftmpl_list.h>`

## Public Member Functions

| List ()
| List (const List< T > &)
| List (const T &)
| ~List ()
List< T > & | operator= (const List< T > &)
void | insert (const T &)
void | insert (const T &, int(*cmpf)(const T &, const T &))
void | insert (const T &, int(*cmpf)(const T &, const T &), void(*insf)(T &, const T &))
void | append (const T &)
int | isEmpty () const
int | length () const
T | getFirst () const
void | removeFirst ()
T | getLast () const
void | removeLast ()
void | sort (int(*)(const T &, const T &))
void | print (OSTREAM &) const

## Private Attributes

ListItem< T > * | first
ListItem< T > * | last
int | _length

## Friends

class | ListIterator< T >
OSTREAM & | operator<< (OSTREAM &os, const List< T > &l)

## Detailed Description

template<class T>
class List< T >

Definition at line 51 of file ftmpl_list.h.

## Constructor & Destructor Documentation

## List() [1/3]

template<class T>

List< T >::List | ( |  | ) |

Definition at line 86 of file ftmpl_list.cc.

{
first = last = 0;
_length = 0;
}
List::first
ListItem< T > * first
Definition ftmpl_list.h:54
List::_length
int _length
Definition ftmpl_list.h:56
List::last
ListItem< T > * last
Definition ftmpl_list.h:55

## List() [2/3]

template<class T>

List< T >::List | ( | const List< T > & | l | ) |

Definition at line 94 of file ftmpl_list.cc.

{
ListItem<T>* cur = l.last;
if ( cur )
{
first = new ListItem<T>( *(cur->item), 0, 0 );
last = first;
cur = cur->prev;
while ( cur )
{
first = new ListItem<T>( *(cur->item), first, 0 );
first->next->prev = first;
cur = cur->prev;
}
_length = l._length;
}
else
{
first = last = 0;
_length = 0;
}
}
List
Definition ftmpl_list.h:52

## List() [3/3]

template<class T>

List< T >::List | ( | const T & | t | ) |

Definition at line 119 of file ftmpl_list.cc.

{
first = last = new ListItem<T>( t, 0, 0 );
_length = 1;
}

## ~List()

template<class T>

List< T >::~List | ( |  | ) |

Definition at line 127 of file ftmpl_list.cc.

{
ListItem<T> *dummy;
while ( first )
{
dummy = first;
first = first->next;
delete dummy;
}
}

## Member Function Documentation

## append()

template<class T>

void List< T >::append | ( | const T & | t | ) |

Definition at line 256 of file ftmpl_list.cc.

{
last = new ListItem<T>( t, 0, last );
if ( first )
last->prev->next = last;
first = ( first ) ? first : last;
_length++;
}

## getFirst()

template<class T>

T List< T >::getFirst | ( |  | ) | const

Definition at line 279 of file ftmpl_list.cc.

{
ASSERT( first, "List: no item available" );
return first->getItem();
}
ASSERT
#define ASSERT(expression, message)
Definition cf_assert.h:99

## getLast()

template<class T>

T List< T >::getLast | ( |  | ) | const

Definition at line 309 of file ftmpl_list.cc.

{
ASSERT( first, "List: no item available" );
return last->getItem();
}

## insert() [1/3]

template<class T>

void List< T >::insert | ( | const T & | t | ) |

Definition at line 193 of file ftmpl_list.cc.

{
first = new ListItem<T>( t, first, 0 );
if ( last )
first->next->prev = first;
last = ( last ) ? last : first;
_length++;
}

## insert() [2/3]

template<class T>

void List< T >::insert | ( | const T & | t,
|  | int(* | cmpf )(const T &, const T &) )

Definition at line 204 of file ftmpl_list.cc.

{
if ( ! first || cmpf( *first->item, t ) > 0 )
insert( t );
else if ( cmpf( *last->item, t ) < 0 )
append( t );
else
{
ListItem<T> * cursor = first;
int c;
while ( (c = cmpf( *cursor->item, t )) < 0 )
cursor = cursor->next;
if ( c == 0 )
*cursor->item = t;
else
{
cursor = cursor->prev;
cursor->next = new ListItem<T>( t, cursor->next, cursor );
cursor->next->next->prev = cursor->next;
_length++;
}
}
}
insert
result insert(CFAFactor(LcF, 1, 1))
append
CFFList append(const CFFList &Inputlist, const CFFactor &TheFactor)
Definition facAlgFuncUtil.cc:32

## insert() [3/3]

template<class T>

void List< T >::insert | ( | const T & | t,
|  | int(* | cmpf )(const T &, const T &),
|  | void(* | insf )(T &, const T &) )

Definition at line 230 of file ftmpl_list.cc.

{
if ( ! first || cmpf( *first->item, t ) > 0 )
insert( t );
else if ( cmpf( *last->item, t ) < 0 )
append( t );
else
{
ListItem<T> * cursor = first;
int c;
while ( (c = cmpf( *cursor->item, t )) < 0 )
cursor = cursor->next;
if ( c == 0 )
insf( *cursor->item, t );
else
{
cursor = cursor->prev;
cursor->next = new ListItem<T>( t, cursor->next, cursor );
cursor->next->next->prev = cursor->next;
_length++;
}
}
}

## isEmpty()

template<class T>

int List< T >::isEmpty | ( |  | ) | const

Definition at line 267 of file ftmpl_list.cc.

{
return ( first == 0 );
}

## length()

template<class T>

int List< T >::length | ( |  | ) | const

Definition at line 273 of file ftmpl_list.cc.

{
return _length;
}

## operator=()

template<class T>

List< T > & List< T >::operator= | ( | const List< T > & | l | ) |

Definition at line 140 of file ftmpl_list.cc.

{
if ( this != &l )
{
ListItem<T> *dummy;
while ( first )
{
dummy = first;
first = first->next;
delete dummy;
}
ListItem<T>* cur = l.last;
if ( cur )
{
first = new ListItem<T>( *(cur->item), 0, 0 );
last = first;
cur = cur->prev;
while ( cur )
{
first = new ListItem<T>( *(cur->item), first, 0 );
first->next->prev = first;
cur = cur->prev;
}
_length = l._length;
}
else
{
first = last = 0;
_length = 0;
}
_length = l._length;
}
return *this;
}

## print()

template<class T>

void List< T >::print | ( | OSTREAM & | os | ) | const

Definition at line 366 of file ftmpl_list.cc.

{
ListItem<T> *cur = first;
os << "( ";
while ( cur )
{
cur->print( os );
if ( (cur = cur->getNext()) )
os << ", ";
}
os << " )";
}
List::print
void print(OSTREAM &) const
Definition ftmpl_list.cc:366

## removeFirst()

template<class T>

void List< T >::removeFirst | ( |  | ) |

Definition at line 287 of file ftmpl_list.cc.

{
if ( first )
{
_length--;
if ( first == last )
{
delete first;
first = last = 0;
}
else
{
ListItem<T> *dummy = first;
first->next->prev = 0;
first = first->next;
delete dummy;
}
}
}

## removeLast()

template<class T>

void List< T >::removeLast | ( |  | ) |

Definition at line 317 of file ftmpl_list.cc.

{
if ( last )
{
_length--;
if ( first == last )
{
delete last;
first = last = 0;
}
else
{
ListItem<T> *dummy = last;
last->prev->next = 0;
last = last->prev;
delete dummy;
}
}
}

## sort()

template<class T>

void List< T >::sort | ( | int(* | swapit )(const T &, const T &) | ) |

Definition at line 339 of file ftmpl_list.cc.

{
if ( first != last )
{
int swap;
do
{
swap = 0;
ListItem<T> *cur = first;
while ( cur->next )
{
if ( swapit( *(cur->item), *(cur->next->item) ) )
{
T* dummy = cur->item;
cur->item = cur->next->item;
cur->next->item = dummy;
swap = 1;
}
cur = cur->next;
}
} while (swap);
}
}

## Friends And Related Symbol Documentation

## ListIterator< T >

template<class T>

friend class ListIterator< T >

friend

Definition at line 76 of file ftmpl_list.h.

## operator<<

template<class T>

OSTREAM & operator<< | ( | OSTREAM & | os,
|  | const List< T > & | l )

friend

Definition at line 555 of file ftmpl_list.cc.

{
l.print( os );
return os;
}

## Field Documentation

## _length

template<class T>

int List< T >::_length

private

Definition at line 56 of file ftmpl_list.h.

## first

template<class T>

ListItem<T>* List< T >::first

private

Definition at line 54 of file ftmpl_list.h.

## last

template<class T>

ListItem<T>* List< T >::last

private

Definition at line 55 of file ftmpl_list.h.

The documentation for this class was generated from the following files:

- factory/include/factory/templates/ftmpl_list.h
- factory/templates/ftmpl_list.cc