Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_List_h 00002 #define _included_List_h 00003 00009 #ifdef DEC_ALPHA 00010 #include <sys/types.h> 00011 #endif 00012 #include <malloc.h> 00013 #include "fastAlloc.h" 00014 00015 #include "DAGHDefaults.h" 00016 00017 #ifndef ListItemsAtATime 00018 #define ListItemsAtATime (32) 00019 #endif 00020 00021 template <class Type> class List; 00022 00027 template <class Type> 00028 class ListItem 00029 { 00030 Type item; 00031 class ListItem<Type> *next; 00032 00033 inline ListItem(const Type& t) : item(t), next(0) { } 00034 inline void *operator new(size_t size, void *buf) { return buf; } 00035 #if ((defined (__xlC__) || (__GNUC__ <= 2 && __GNUC_MINOR__ < 8) || (__GNUC__ < 2)) && !defined(__KCC)) 00036 #else 00037 inline void operator delete(void *p, void *buf) {} 00038 #endif 00039 friend class List<Type>; 00040 }; 00041 00046 template <class Type> 00047 class List 00048 { 00049 fastAlloc block; 00050 00052 int n; 00054 ListItem<Type> *head; 00056 ListItem<Type> *tail; 00057 00058 private: 00059 void operator = (const List<Type>&); 00060 List(const List<Type>&); 00061 00062 public: 00063 inline List() : block(sizeof(ListItem<Type>), ListItemsAtATime), 00064 n(0), head(0), tail(0) { } 00065 inline List(const int cnt) 00066 : block(sizeof(ListItem<Type>), cnt), 00067 n(0), head(0), tail(0) { } 00068 inline int number() const { return(n); } 00069 inline int isempty() const { return(n == 0); } 00070 ~List(); 00071 00072 /* Methods to add/delete to/from the list */ 00073 void add(const Type& t); 00074 void add(const List<Type>& other); 00075 void combine(List<Type>& other); 00076 void pop(); 00077 void empty(); 00078 inline const Type& first() const { return(head->item); } 00079 void array(Type **& array, int &cnt) const; 00080 void array(Type *& array, int &cnt) const; 00081 inline void reset() { n = 0; head = 0; tail = 0; } 00082 00083 /* Methods to traverse the list */ 00084 inline ListItem<Type> *Head() const { return(head); } 00085 inline ListItem<Type> *Tail() const { return(tail); } 00086 inline ListItem<Type> *Next(ListItem<Type> *listitem) const 00087 { return(listitem->next); } 00088 inline Type& Item(ListItem<Type> *listitem) const 00089 { return(listitem->item); } 00090 }; 00091 00092 #if defined(Want_c_files) || (!defined(RS6000) && !defined(SPX)) 00093 #include "List.c" 00094 #endif 00095 00096 #ifndef DAGHListLoop 00097 #define DAGHListLoop(list,item,Type) { \ 00098 ListItem<Type> *li = 0; \ 00099 for (li=(list).Head();li;li=(list).Next(li)) { \ 00100 (item) = &(list).Item(li); 00101 #define DAGHEndLoop } } 00102 #endif 00103 00104 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04