SoftFilters  0.1.0
Arduino framework and library of software data filters.
LinkedList.h
Go to the documentation of this file.
1 
11 #ifndef LINKEDLIST_H
12 #define LINKEDLIST_H
13 
14 template <typename VAL_T>
16 {
17 public:
18  VAL_T value;
20  LinkedListNode(VAL_T const &v): value(v), next(NULL) { }
21 };
22 
23 template <typename VAL_T>
25 {
26 public:
30  VAL_T operator*() { return ptr->value; }
39  void operator++() { ptr = ptr->next; }
46  bool operator!=(NodeIterator<VAL_T> const &it) { return ptr != it.ptr; }
47  NodeIterator(): ptr(NULL) { }
48  NodeIterator(LinkedListNode<VAL_T> *n): ptr(n) { }
49 private:
51 };
52 
53 template <typename VAL_T>
55 {
56 public:
57  LinkedList(): head(NULL), tail(NULL), last_ptr(NULL) { }
58  ~LinkedList()
59  {
60  LinkedListNode<VAL_T> *to_del;
61  while (head) {
62  to_del = head;
63  head = head->next;
64  delete to_del;
65  }
66  }
70  void append(VAL_T const &v)
71  {
73  if (head) {
74  *tail = new_node;
75  }
76  else {
77  head = new_node;
78  }
79  tail = &new_node->next;
80  last_ptr = new_node;
81  }
85  bool isEmpty() { return head == NULL; }
101 private:
102  LinkedListNode<VAL_T> *head;
103  LinkedListNode<VAL_T> **tail;
104  LinkedListNode<VAL_T> *last_ptr;
105 };
106 
107 #endif
bool operator!=(NodeIterator< VAL_T > const &it)
Comparison between two iterators.
Definition: LinkedList.h:46
Definition: LinkedList.h:24
bool isEmpty()
Tell whether the linked list is empty.
Definition: LinkedList.h:85
VAL_T operator*()
Dereference the iterator to obtain the value it points at.
Definition: LinkedList.h:30
void operator++()
Prefix increment operator.
Definition: LinkedList.h:39
Definition: LinkedList.h:15
NodeIterator< VAL_T > begin()
An iterator pointing at the beginning of the linked list.
Definition: LinkedList.h:91
Definition: LinkedList.h:54
NodeIterator< VAL_T > end()
An iterator pointing at the end of the linked list.
Definition: LinkedList.h:96
NodeIterator< VAL_T > last()
An iterator pointing at the last node.
Definition: LinkedList.h:100
void append(VAL_T const &v)
Append an element.
Definition: LinkedList.h:70