Changeset 534 for abuse/trunk/src/imlib/linked.h
- Timestamp:
- Apr 22, 2011, 7:32:17 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/linked.h
r519 r534 11 11 // linked.h - linked list and linked list node classes 12 12 // written June 2, 1992 by Jonathan Clark (at home) 13 // these classes provide the basic groundwork for any future linked list14 // please derive your own linked_node subclass and define the virtual15 // function compare.16 // example compare function17 // virtual int compare(void *n1, int field)18 // { return ((classname *) n1)->data > data); }19 // should return (1 if n1 is greater than (self)) else return 020 // field is the value determined by linked_list::set_sort_field21 // this defaults to 122 13 14 #ifndef __LINKED_H__ 15 #define __LINKED_H__ 23 16 24 #ifndef linkman25 #define linkman26 17 #include <stdio.h> 27 18 #include <stdlib.h> 28 19 #include <string.h> 29 20 30 #define loop(controll,first,inside) { controll=first; \31 if (first) do { inside controll=controll->next(); } \32 while (controll!=first); }33 34 #define loopt(type,controll,first,inside) { controll=(type *)(first); \35 if (first) do { inside controll=(type *)(controll->next()); } \36 while (controll!=(type *)(first)); }37 38 39 #define loop_rev(controll,last,inside) { controll=last; \40 if (first) do { inside controll=controll->last(); } \41 while (controll!=last); }42 43 #define loopct(type,controll,first,cond,inside) { controll=(type *)first; \44 if (first && (cond)) do { inside controll=(type *)controll->next(); } \45 while (controll!=(type *)first && (cond)); }46 47 #define loop_fort(type,controll,first,x) \48 int x=0; \49 if (first) \50 for (controll=(type *)(first); \51 (!x || (controll)!=(type *)(first)); \52 controll=(type *)(controll->next()),x++)53 54 #define loop_forct(type,controll,first,cond,x) int x=0; if (first) for \55 (controll=(type *)(first); cond && (!x || controll!=(type *)(first)); \56 controll=(type *)(controll->next()),x++)57 58 21 class linked_node 59 22 { 60 class linked_node *nextp, *lastp; 23 friend class linked_list; 24 61 25 public: 62 virtual int compare(void *n1, int field) { return(0); } // default is = (equal) 63 class linked_node *next() { return nextp; } 64 class linked_node *last() { return lastp; } 65 void set_next(class linked_node *p) { nextp=p; } 66 void set_last(class linked_node *p) { lastp=p; } 67 virtual ~linked_node() { ; } 68 linked_node() { nextp=NULL; lastp=NULL; } 26 linked_node() { m_next = m_prev = NULL; } 27 virtual ~linked_node() { ; } 28 29 inline class linked_node *Next() { return m_next; } 30 inline class linked_node *Prev() { return m_prev; } 31 inline void SetNext(class linked_node *p) { m_next = p; } 32 inline void SetPrev(class linked_node *p) { m_prev = p; } 33 34 private: 35 class linked_node *m_next, *m_prev; 69 36 }; 70 37 … … 83 50 class linked_list 84 51 { 85 class linked_node *fn, *cn; // first and current nodes 86 int nn; char sortby; 87 public : 88 linked_list(linked_node *first=NULL); 89 void add_front(class linked_node *p); 90 void add_end(class linked_node *p); 91 void insert(class linked_node *p); 92 void set_sort_field(int x) { sortby=x; } // this is passed to compare 93 class linked_node *current() { return cn; } 94 class linked_node *first() { return fn; } 95 class linked_node *last() { return fn->last(); } 96 class linked_node *get_node(int x); 97 void set_current(class linked_node *p) { cn=p; } 98 void go_first() { cn=fn; } 99 void go_end() { cn=fn->last(); } 100 void go_next() { cn=cn->next(); } 101 void go_last() { cn=cn->last(); } 102 int number_nodes() { return nn; } 103 int node_number(linked_node *p); 104 int unlink(linked_node *p); 105 ~linked_list(); 52 public: 53 linked_list(); 54 ~linked_list(); 55 56 void add_front(class linked_node *p); 57 void add_end(class linked_node *p); 58 int unlink(linked_node *p); 59 60 inline class linked_node *first() { return m_first; } 61 inline class linked_node *prev() { return m_first->Prev(); } 62 inline size_t Count() { return m_count; } 63 64 private: 65 linked_node *m_first; 66 size_t m_count; 106 67 }; 107 68 108 69 #endif 109 70 110 111
Note: See TracChangeset
for help on using the changeset viewer.