Main Page | Alphabetical List | Class List | File List | Class Members | File Members

List Class Reference

#include <list.h>

List of all members.

Public Member Functions

 List ()
 ~List ()
void Prepend (void *item)
void Append (void *item)
void * Remove ()
void Mapcar (VoidFunctionPtr func)
bool IsEmpty ()
void SortedInsert (void *item, int sortKey)
void * SortedRemove (int *keyPtr)
ListElementGetFirst ()


Constructor & Destructor Documentation

List::List  ) 
 

Definition at line 43 of file list.cc.

00044 { 00045 first = last = NULL; 00046 }

List::~List  ) 
 

Definition at line 58 of file list.cc.

References Remove().

00059 { 00060 while (Remove() != NULL) 00061 ; // delete all the list elements 00062 }


Member Function Documentation

void List::Append void *  item  ) 
 

Definition at line 76 of file list.cc.

References IsEmpty(), and ListElement::next.

Referenced by SynchList::Append(), Semaphore::P(), and Scheduler::ReadyToRun().

00077 { 00078 ListElement *element = new ListElement(item, 0); 00079 00080 if (IsEmpty()) 00081 { 00082 // list is empty 00083 first = element; 00084 last = element; 00085 } 00086 else 00087 { // else put it after last 00088 last->next = element; 00089 last = element; 00090 } 00091 }

ListElement * List::GetFirst  ) 
 

Definition at line 251 of file list.cc.

00252 { 00253 return first; 00254 }

bool List::IsEmpty  ) 
 

Definition at line 159 of file list.cc.

References FALSE, and TRUE.

Referenced by Append(), Scheduler::IsEmpty(), Prepend(), SynchList::Remove(), SortedInsert(), SortedRemove(), and Interrupt::~Interrupt().

00160 { 00161 if (first == NULL) 00162 return TRUE; 00163 else 00164 return FALSE; 00165 }

void List::Mapcar VoidFunctionPtr  func  ) 
 

Definition at line 144 of file list.cc.

References DEBUG(), ListElement::item, ListElement::next, and VoidFunctionPtr.

Referenced by Interrupt::DumpState(), SynchList::Mapcar(), and Scheduler::Print().

00145 { 00146 for (ListElement *ptr = first; ptr != NULL; ptr = ptr->next) 00147 { 00148 DEBUG('l', "In mapcar, about to invoke %x(%x)\n", func, ptr->item); 00149 (*func)((int)ptr->item); 00150 } 00151 }

void List::Prepend void *  item  ) 
 

Definition at line 105 of file list.cc.

References IsEmpty(), and ListElement::next.

00106 { 00107 ListElement *element = new ListElement(item, 0); 00108 00109 if (IsEmpty()) 00110 { // list is empty 00111 first = element; 00112 last = element; 00113 } 00114 else 00115 { // else put it before first 00116 element->next = first; 00117 first = element; 00118 } 00119 }

void * List::Remove  ) 
 

Definition at line 129 of file list.cc.

References SortedRemove().

Referenced by Scheduler::FindNextToRun(), SynchList::Remove(), Semaphore::V(), Interrupt::~Interrupt(), and ~List().

00130 { 00131 return SortedRemove(NULL); // Same as SortedRemove, but ignore the key 00132 }

void List::SortedInsert void *  item,
int  sortKey
 

Definition at line 182 of file list.cc.

References IsEmpty(), ListElement::key, and ListElement::next.

Referenced by Interrupt::Schedule().

00183 { 00184 ListElement *element = new ListElement(item, sortKey); 00185 ListElement *ptr;// keep track 00186 00187 if (IsEmpty()) 00188 { // if list is empty, put 00189 first = element; 00190 last = element; 00191 } 00192 else if (sortKey < first->key) 00193 { 00194 // item goes on front of list 00195 element->next = first; 00196 first = element; 00197 } 00198 else 00199 { // look for first elt in list bigger than item 00200 for (ptr = first; ptr->next != NULL; ptr = ptr->next) 00201 { 00202 if (sortKey < ptr->next->key) 00203 { 00204 element->next = ptr->next; 00205 ptr->next = element; 00206 return; 00207 } 00208 } 00209 last->next = element;// item goes at end of list 00210 last = element; 00211 } 00212 }

void * List::SortedRemove int *  keyPtr  ) 
 

Definition at line 227 of file list.cc.

References IsEmpty(), ListElement::item, ListElement::key, and ListElement::next.

Referenced by Remove().

00228 { 00229 ListElement *element = first; 00230 void *thing; 00231 00232 if (IsEmpty()) 00233 return NULL; 00234 00235 thing = first->item; 00236 if (first == last) 00237 { // list had one item, now has none 00238 first = NULL; 00239 last = NULL; 00240 } 00241 else 00242 { 00243 first = element->next; 00244 } 00245 if (keyPtr != NULL) 00246 *keyPtr = element->key; 00247 delete element; 00248 return thing; 00249 }


The documentation for this class was generated from the following files:
Generated on Thu Sep 16 12:33:48 2004 for NachOS by doxygen 1.3.8