Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_List_c 00002 #define _included_List_c 00003 00009 template <class Type> 00010 List<Type>::~List() 00011 { 00012 while (head != (ListItem<Type> *) 0) 00013 { 00014 ListItem<Type> *tmpitem = head; 00015 head = head->next; 00016 //delete tmpitem->item; 00017 block.free(tmpitem); 00018 } 00019 } 00020 00021 template <class Type> 00022 void List<Type>::empty() 00023 { 00024 while (head != (ListItem<Type> *) 0) 00025 { 00026 ListItem<Type> *tmpitem = head; 00027 head = head->next; 00028 //delete tmpitem->item; 00029 block.free(tmpitem); 00030 } 00031 n = 0; 00032 head = 0; 00033 tail = 0; 00034 } 00035 00036 template <class Type> 00037 void List<Type>::add(const Type& t) 00038 { 00039 ListItem<Type> *item = new (block.alloc()) ListItem<Type>(t); 00040 if (!head) head = item; 00041 if (tail) tail->next = item; 00042 tail = item; 00043 n++; 00044 } 00045 00046 template <class Type> 00047 void List<Type>::add(const List<Type>& other) 00048 { 00049 for (ListItem<Type> *p = other.head; p; p = p->next) 00050 { 00051 ListItem<Type> *item = new (block.alloc()) ListItem<Type>(p->item); 00052 if (!head) head = item; 00053 if (tail) tail->next = item; 00054 tail = item; 00055 n++; 00056 } 00057 } 00058 00059 template <class Type> 00060 void List<Type>::pop( ) 00061 { 00062 if (n > 0) 00063 { 00064 ListItem<Type> *byebye = head; 00065 head = head->next; 00066 if (!head) tail = 0; 00067 //delete byebye->item; 00068 block.free(byebye); 00069 n--; 00070 } 00071 } 00072 00073 template <class Type> 00074 void List<Type>::combine(List<Type>& other) 00075 { 00076 if (other.n > 0) 00077 { 00078 if (n == 0) 00079 { 00080 head = other.head; 00081 tail = other.tail; 00082 n = other.n; 00083 } 00084 else 00085 { 00086 tail->next = other.head; 00087 tail = other.tail; 00088 n += other.n; 00089 } 00090 other.n = 0; 00091 other.head = 0; 00092 other.tail = 0; 00093 } 00094 } 00095 00096 template <class Type> 00097 void List<Type>::array(Type **& array, int &cnt) const 00098 { 00099 assert(!array); 00100 cnt = n; 00101 if (cnt > 0) { 00102 array = new Type *[cnt]; 00103 int i = 0; 00104 ListItem<Type> *p = head; 00105 for (;i<cnt;p=p->next,i++) { 00106 array[i] = new Type(p->item); 00107 } 00108 } 00109 } 00110 00111 template <class Type> 00112 void List<Type>::array(Type *& array, int &cnt) const 00113 { 00114 assert(!array); 00115 cnt = n; 00116 if (cnt > 0) { 00117 array = new Type [cnt]; 00118 int i = 0; 00119 ListItem<Type> *p = head; 00120 for (;i<cnt;p=p->next,i++) { 00121 array[i] = p->item; 00122 } 00123 } 00124 } 00125 00126 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04