OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Basic / OrderList.hh
1 // $XConsortium: OrderList.hh /main/3 1996/06/11 16:21:08 cde-hal $
2 #ifndef _OrderListType_hh
3 #define _OrderListType_hh
4
5
6 // List status definitions
7
8 #define OLIST_ERROR        (int)-1
9 #define OLIST_OK           (int)1
10 #define OLIST_NOOP         (int)0
11 #define OLIST_LAST_REMOVD  (int)100
12 #define OLIST_TAIL_REMOVD  (int)101
13 #define OLIST_HEAD_REMOVD  (int)102
14
15 // Where flags for add
16
17 enum AddCode {
18         addAfter,               // Add after list cursor
19         addBefore,              // Add before list cursor
20         addHead,                // Add at list head
21         addTail                 // Add at list tail
22 };
23
24 class ListEntry;
25
26 class OrderList {
27  public:
28     // Constructor
29     OrderList();
30     // Destructor
31     ~OrderList();
32     // Public methods
33     void       clear();
34     int        add(ListEntry *entry, AddCode where, bool mvcursor = 1);
35     int        remove();
36     ListEntry *extract();
37     bool    isempty();
38     int        size();
39     int        next();
40     int        prev();
41     int        head();
42     int        tail();
43     ListEntry *value();
44     ListEntry *set_cursor(ListEntry *cursor_pos);
45     // NOTE: could just put the OrderList as user data
46     ListEntry *iterate(bool (*fn)(ListEntry *, void *), void *usr_def);
47     ListEntry *iterate(bool (*fn)(OrderList *, ListEntry *, void *), void *usr_def);
48   private:
49     // Private data
50     int                 f_size   ;
51     ListEntry          *f_head   ;
52     ListEntry          *f_tail   ;
53     ListEntry          *f_cursor ;
54     
55     // Private methods
56     void insertNew    (ListEntry *node);
57     void insertAfter  (ListEntry *node);
58     void insertBefore (ListEntry *node);
59     void insertTail   (ListEntry *node);
60     void insertHead   (ListEntry *node);
61 };
62
63 inline OrderList::OrderList()
64 : f_size(0),
65   f_head(NULL),
66   f_tail(NULL),
67   f_cursor(NULL)
68 {
69 }
70
71 inline int
72 OrderList::size()
73 {
74     return f_size ;
75 }
76
77 inline bool
78 OrderList::isempty()
79 {
80     if (f_size)
81       return FALSE;
82     else
83       return TRUE;
84 }
85
86 inline ListEntry    *
87 OrderList::value()
88 {
89     return f_cursor;
90 }
91
92 inline ListEntry *
93 OrderList::set_cursor(ListEntry *value)
94 {
95     assert(value != NULL);
96     f_cursor = value ;
97     return f_cursor ;
98 }
99 // //////////////////////////////////////////////////////////////
100 // List entry class
101 // //////////////////////////////////////////////////////////////
102
103 class ListEntry : public FolioObject {
104 friend class OrderList;
105     
106   public:
107     ListEntry () ;
108     virtual ~ListEntry ();
109     
110   private:
111     ListEntry   *f_prev ;
112     ListEntry   *f_next ;
113 } ;
114
115 inline 
116 ListEntry::ListEntry() 
117 : f_prev(NULL),
118   f_next(NULL)
119 {
120 }
121
122 #endif                          /* _OrderListType_hh */