Rudiments
linkedlist.h
1 // Copyright (c) 2003 David Muse
2 // See the COPYING file for more information.
3 
4 #ifndef RUDIMENTS_LINKEDLIST_H
5 #define RUDIMENTS_LINKEDLIST_H
6 
7 #include <rudiments/private/linkedlistincludes.h>
8 
9 #ifdef RUDIMENTS_NAMESPACE
10 namespace rudiments {
11 #endif
12 
14 template <class datatype>
16  public:
19 
23  virtual ~linkedlistnode();
24 
26  void setData(datatype data);
27 
29  datatype getData() const;
30 
34  int32_t compare(datatype data) const;
35 
37  void setPrevious(linkedlistnode<datatype> *previous);
38 
40  void setNext(linkedlistnode<datatype> *next);
41 
43  linkedlistnode<datatype> *getPrevious();
44 
46  linkedlistnode<datatype> *getNext();
47 
49  void print() const;
50 
51  #include <rudiments/private/linkedlistnode.h>
52 };
53 
60 template < class datatype, class linkedlistnodetype=linkedlistnode<datatype> >
61 class linkedlist {
62  public:
64  linkedlist();
65 
69  virtual ~linkedlist();
70 
73  void append(datatype data);
74 
77  void append(linkedlistnodetype *node);
78 
83  bool insert(uint64_t index, datatype data);
84 
89  bool insert(uint64_t index, linkedlistnodetype *node);
90 
94  bool removeByIndex(uint64_t index);
95 
99  bool removeByData(datatype data);
100 
104  bool removeAllByData(datatype data);
105 
109  bool removeNode(linkedlistnodetype *node);
110 
115  bool setDataByIndex(uint64_t index, datatype data);
116 
121  bool getDataByIndex(uint64_t index, datatype *data);
122 
124  uint64_t getLength() const;
125 
127  linkedlistnodetype *getFirstNode();
128 
130  linkedlistnodetype *getLastNode();
131 
133  linkedlistnodetype *getNodeByIndex(uint64_t index);
134 
137  linkedlistnodetype *getNodeByData(datatype data);
138 
141  linkedlistnodetype *getNodeByData(
142  linkedlistnodetype *startnode,
143  datatype data);
144 
148  void clear();
149 
151  void print() const;
152 
153  #include <rudiments/private/linkedlist.h>
154 };
155 
158 
159 #ifdef RUDIMENTS_NAMESPACE
160 }
161 #endif
162 
163 #include <rudiments/private/linkedlistnodeinlines.h>
164 #include <rudiments/private/linkedlistinlines.h>
165 
166 #endif