List< T > Class Template Reference

#include <List.h>


Public Member Functions

 List (const bool resp=true)
 ~List ()
const Listoperator= (const List &)
void print_list (ostream &) const
bool is_empty () const
bool find (const T *, ListIterator< T > &)
T * get_nth (const int n) const
int number_of_elements () const
void first (ListIterator< T > &li) const
void last (ListIterator< T > &li) const
void remove (ListIterator< T > &)
bool remove (const T *)
void insert_first (T *)
void insert_last (T *)
void delete_list ()
void set_deletion_responsibility (const bool r)

Private Attributes

ListNode< T > * list_head
bool responsible_for_deletion

template<class T>
class List< T >


Constructor & Destructor Documentation

template<class T>
List< T >::List const bool  resp = true  ) 
 

Definition at line 34 of file List.cc.

00035   : list_head(new ListNode<T>), responsible_for_deletion(resp)
00036 {
00037 }

template<class T>
List< T >::~List  ) 
 

Definition at line 40 of file List.cc.

References List< T >::delete_list().

00041 {
00042   delete_list();     // delete the actual list
00043   delete list_head;  // delet the header node
00044 }

Here is the call graph for this function:


Member Function Documentation

template<class T>
void List< T >::delete_list  ) 
 

Definition at line 48 of file List.cc.

References ListNode< T >::element, List< T >::list_head, ListNode< T >::next, ListNode< T >::prev, and List< T >::responsible_for_deletion.

Referenced by ArenaBase::delete_lists(), StartTournamentWindow::new_tournament(), List< T >::operator=(), read_dirs_from_system(), and List< T >::~List().

00049 {
00050   ListNode<T>*  p = list_head->next;  // keep the header node
00051   ListNode<T>*  temp;  
00052 
00053   while ( p != NULL )
00054     {
00055       temp = p->next;
00056       if( responsible_for_deletion && p->element ) delete p->element;
00057       delete p;
00058       p = temp;
00059     }
00060   
00061   list_head->next = NULL;
00062   list_head->prev = NULL;
00063 }

template<class T>
bool List< T >::find const T *  ,
ListIterator< T > & 
 

Definition at line 127 of file List.cc.

References List< T >::first(), and ListIterator< T >::ok().

Referenced by List< T >::remove().

00128 {
00129   for( first(li); li.ok(); li++ )
00130     {
00131       if ( li() == x )
00132         {
00133           return true;
00134         }
00135     }
00136 
00137   return false; 
00138 }

Here is the call graph for this function:

template<class T>
void List< T >::first ListIterator< T > &  li  )  const [inline]
 

Definition at line 72 of file List.h.

Referenced by StartTournamentWindow::add_all_selected(), ScoreWindow::add_robots(), StatisticsWindow::add_the_statistics_to_clist(), StartTournamentWindow::change_all_selection(), check_for_robots_and_arenas(), ArenaRealTime::check_robots(), ArenaBase::delete_lists(), Dialog::Dialog(), ArenaWindow::draw_everything(), ArenaWindow::draw_moving_objects(), ArenaRealTime::end_game(), ArenaRealTime::end_sequence(), ArenaRealTime::end_sequence_follow_up(), List< T >::find(), ArenaBase::find_object_by_id(), ArenaReplay::find_object_in_log(), StartTournamentWindow::find_row_in_clist(), Robot::get_current_game_stats(), ArenaBase::move_shots(), ArenaBase::move_shots_no_check(), StartTournamentWindow::new_tournament(), ArenaReplay::parse_log_line(), ArenaReplay::parse_this_time_index(), ArenaRealTime::read_robot_messages(), ArenaReplay::recreate_lists(), StartTournamentWindow::remove_all_selected(), ArenaBase::save_statistics_to_file(), StartTournamentWindow::save_tournament_file(), ArenaReplay::search_forward(), ArenaBase::space_available(), ArenaRealTime::start_game(), ArenaRealTime::start_sequence(), ArenaRealTime::start_sequence_follow_up(), ArenaRealTime::start_tournament(), StartTournamentWindow::StartTournamentWindow(), ArenaRealTime::timeout_function(), ScoreWindow::update_robots(), and ArenaRealTime::update_robots().

00072 { li.listp = list_head->next; };

template<class T>
T * List< T >::get_nth const int  n  )  const
 

Definition at line 95 of file List.cc.

References ListNode< T >::element, Error(), List< T >::list_head, and ListNode< T >::next.

Referenced by ArenaRealTime::start_game().

00096 {
00097   ListNode<T>*  p;
00098   int index = 1;
00099 
00100   if( n < 1 ) Error(true, "n < 1", "List::get_nth");
00101 
00102   for( p=list_head->next; p != NULL && index < n; p=p->next ) index++;
00103     
00104   if( p == NULL ) Error(true, "No such element", "List::get_nth");
00105 
00106   return p->element;
00107 }

Here is the call graph for this function:

template<class T>
void List< T >::insert_first T *   ) 
 

Definition at line 201 of file List.cc.

References Error(), List< T >::list_head, ListNode< T >::next, and ListNode< T >::prev.

Referenced by ArenaBase::parse_arena_line().

00202 {
00203   ListNode<T>*  p = new ListNode<T>(x, list_head->next, NULL);
00204 
00205   if( p == NULL ) Error(true, "Out of memory", "List::insert_first");
00206 
00207   if( list_head->next == NULL ) list_head->prev = p;
00208   if( p->next ) p->next->prev = p;
00209   list_head->next = p;
00210 }

Here is the call graph for this function:

template<class T>
void List< T >::insert_last T *   ) 
 

Definition at line 214 of file List.cc.

References Error(), List< T >::list_head, ListNode< T >::next, and ListNode< T >::prev.

Referenced by StartTournamentWindow::add_all_selected(), ArenaRealTime::add_cookie(), ArenaRealTime::add_mine(), check_for_robots_and_arenas(), ControlWindow::end_clicked(), StartTournamentWindow::load_tournament_file(), StartTournamentWindow::new_tournament(), Gui::open_starttournamentwindow(), List< T >::operator=(), ArenaBase::parse_arena_line(), ArenaReplay::parse_log_line(), ArenaReplay::parse_log_line_forward(), ArenaReplay::parse_log_line_rewind(), read_dirs_from_system(), ArenaReplay::recreate_lists(), ControlWindow::replay_tournament(), StartTournamentWindow::save_tournament_file(), search_directories(), Robot::set_stats(), split_colonseparated_dirs(), StartTournamentWindow::start(), ArenaRealTime::start_game(), ArenaRealTime::start_tournament(), and StartTournamentWindow::StartTournamentWindow().

00215 {
00216   ListNode<T>*  p = new ListNode<T>(x, NULL, list_head->prev);
00217 
00218   if( p == NULL ) Error(true, "Out of memory", "List::insert_last");
00219 
00220   if( list_head->prev == NULL ) list_head->next = p;
00221   if( p->prev ) p->prev->next = p;
00222   list_head->prev = p;
00223 }

Here is the call graph for this function:

template<class T>
bool List< T >::is_empty  )  const [inline]
 

Definition at line 67 of file List.h.

Referenced by StartTournamentWindow::save_tournament_file(), and Robot::set_values_at_process_start_up().

00067 { return list_head->next == NULL; }

template<class T>
void List< T >::last ListIterator< T > &  li  )  const [inline]
 

Definition at line 73 of file List.h.

Referenced by Robot::get_last_position(), Robot::get_total_points(), and Robot::set_stats().

00073 { li.listp = list_head->prev; };

template<class T>
int List< T >::number_of_elements  )  const
 

Definition at line 143 of file List.cc.

References List< T >::list_head, and ListNode< T >::next.

Referenced by parse_tournament_file(), StartTournamentWindow::save_tournament_file(), and StartTournamentWindow::set_entry().

00144 {
00145   ListNode<T>* p;
00146   int index=0;
00147 
00148   for( p=list_head->next; p != NULL; p=p->next ) index++;
00149 
00150   return(index);
00151 }

template<class T>
const List< T > & List< T >::operator= const List< T > &   ) 
 

Definition at line 71 of file List.cc.

References List< T >::delete_list(), ListNode< T >::element, List< T >::insert_last(), List< T >::list_head, and ListNode< T >::next.

00072 {
00073   if( this == &old ) return *this; // don't copy yourself!
00074   
00075   if( list_head != NULL )
00076     delete_list();  // delete all nodes but the header node. 
00077   else
00078     list_head = new ListNode<T>;
00079 
00080 
00081   ListNode<T>* p;
00082 
00083   for( p=old.list_head->next; p != NULL; p=p->next )
00084     insert_last(p->element);
00085 
00086   return *this;
00087 }

Here is the call graph for this function:

template<class T>
void List< T >::print_list ostream &   )  const
 

Definition at line 112 of file List.cc.

References List< T >::list_head, and ListNode< T >::next.

00113 {
00114   ListNode<T>*  p;
00115 
00116   for( p=list_head->next; p != NULL; p=p->next );
00117     //    os << *(p->element) << " ";
00118 }

template<class T>
bool List< T >::remove const T *   ) 
 

Definition at line 186 of file List.cc.

References List< T >::find(), and List< T >::remove().

00187 {
00188   ListIterator<T> li;
00189   if ( find(x, li) )
00190     {
00191       remove(li);
00192       return true;
00193     }
00194   
00195   return false;
00196 }

Here is the call graph for this function:

template<class T>
void List< T >::remove ListIterator< T > &   ) 
 

Definition at line 157 of file List.cc.

References ListNode< T >::element, Error(), List< T >::list_head, ListIterator< T >::listp, ListNode< T >::next, ListNode< T >::prev, and List< T >::responsible_for_deletion.

Referenced by ArenaRealTime::end_sequence_follow_up(), ArenaBase::move_shots(), ArenaReplay::parse_log_line_forward(), ArenaReplay::parse_log_line_rewind(), ArenaReplay::recreate_lists(), List< T >::remove(), StartTournamentWindow::remove_all_selected(), ArenaRealTime::start_sequence_follow_up(), and ArenaRealTime::update_robots().

00158 {
00159   if( li.listp == NULL ) Error(true, "Nothing to remove", "List::remove");
00160 
00161   ListNode<T>* current_pos = li.listp;
00162 
00163   if( current_pos->prev )
00164     {
00165       current_pos->prev->next = current_pos->next;
00166       li.listp = current_pos->prev;
00167     }
00168   else
00169     {
00170       list_head->next = current_pos->next;
00171       li.listp = list_head;
00172     }
00173 
00174   if( current_pos->next )
00175     current_pos->next->prev = current_pos->prev;
00176   else
00177     list_head->prev = current_pos->prev;
00178   
00179   if( responsible_for_deletion && current_pos->element ) delete current_pos->element;
00180   delete current_pos;
00181 }

Here is the call graph for this function:

template<class T>
void List< T >::set_deletion_responsibility const bool  r  )  [inline]
 

Definition at line 85 of file List.h.

Referenced by ArenaBase::ArenaBase().

00085 { responsible_for_deletion = r; }


Field Documentation

template<class T>
ListNode<T>* List< T >::list_head [private]
 

Definition at line 89 of file List.h.

Referenced by List< T >::delete_list(), List< T >::get_nth(), List< T >::insert_first(), List< T >::insert_last(), List< T >::number_of_elements(), List< T >::operator=(), List< T >::print_list(), and List< T >::remove().

template<class T>
bool List< T >::responsible_for_deletion [private]
 

Definition at line 90 of file List.h.

Referenced by List< T >::delete_list(), and List< T >::remove().


The documentation for this class was generated from the following files:
Generated on Fri Oct 15 15:50:08 2004 for Real Time Battle by  doxygen 1.3.9.1