Foundation classes for a basic GUI implementing simple widgets and events
Dependents: TouchScreenGUIDemo
Core/LinkedList.h@12:63db16fea709, 2016-05-08 (annotated)
- Committer:
- duncanFrance
- Date:
- Sun May 08 14:42:08 2016 +0000
- Revision:
- 12:63db16fea709
- Child:
- 15:e69fd74d42e4
Update to handle dirty pixels and geometric change/damage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
duncanFrance | 12:63db16fea709 | 1 | #ifndef SIMPLEGUI_LINKED_LIST_H |
duncanFrance | 12:63db16fea709 | 2 | #define SIMPLEGUI_LINKED_LIST_H |
duncanFrance | 12:63db16fea709 | 3 | |
duncanFrance | 12:63db16fea709 | 4 | #include "mbed.h" |
duncanFrance | 12:63db16fea709 | 5 | |
duncanFrance | 12:63db16fea709 | 6 | template<class T> |
duncanFrance | 12:63db16fea709 | 7 | class LinkedListNode |
duncanFrance | 12:63db16fea709 | 8 | { |
duncanFrance | 12:63db16fea709 | 9 | |
duncanFrance | 12:63db16fea709 | 10 | public: |
duncanFrance | 12:63db16fea709 | 11 | |
duncanFrance | 12:63db16fea709 | 12 | LinkedListNode(T* nodeData) : data(nodeData), next(NULL) {} |
duncanFrance | 12:63db16fea709 | 13 | ~LinkedListNode() {} |
duncanFrance | 12:63db16fea709 | 14 | |
duncanFrance | 12:63db16fea709 | 15 | T* data; |
duncanFrance | 12:63db16fea709 | 16 | LinkedListNode<T>* next; |
duncanFrance | 12:63db16fea709 | 17 | }; |
duncanFrance | 12:63db16fea709 | 18 | |
duncanFrance | 12:63db16fea709 | 19 | template<class T> |
duncanFrance | 12:63db16fea709 | 20 | class LinkedList |
duncanFrance | 12:63db16fea709 | 21 | { |
duncanFrance | 12:63db16fea709 | 22 | |
duncanFrance | 12:63db16fea709 | 23 | public: |
duncanFrance | 12:63db16fea709 | 24 | |
duncanFrance | 12:63db16fea709 | 25 | LinkedList() : _first(NULL), _next(NULL), _current(NULL) {} |
duncanFrance | 12:63db16fea709 | 26 | ~LinkedList() {} |
duncanFrance | 12:63db16fea709 | 27 | |
duncanFrance | 12:63db16fea709 | 28 | |
duncanFrance | 12:63db16fea709 | 29 | void append(T* data) { |
duncanFrance | 12:63db16fea709 | 30 | |
duncanFrance | 12:63db16fea709 | 31 | if(_first == NULL) { |
duncanFrance | 12:63db16fea709 | 32 | |
duncanFrance | 12:63db16fea709 | 33 | _first = new LinkedListNode<T>(data); |
duncanFrance | 12:63db16fea709 | 34 | |
duncanFrance | 12:63db16fea709 | 35 | } else { |
duncanFrance | 12:63db16fea709 | 36 | |
duncanFrance | 12:63db16fea709 | 37 | LinkedListNode<T>* p = _first; |
duncanFrance | 12:63db16fea709 | 38 | LinkedListNode<T>* d = new LinkedListNode<T>(data); |
duncanFrance | 12:63db16fea709 | 39 | |
duncanFrance | 12:63db16fea709 | 40 | while(p->next != NULL) { |
duncanFrance | 12:63db16fea709 | 41 | p = p->next; |
duncanFrance | 12:63db16fea709 | 42 | } |
duncanFrance | 12:63db16fea709 | 43 | |
duncanFrance | 12:63db16fea709 | 44 | p->next = d; |
duncanFrance | 12:63db16fea709 | 45 | } |
duncanFrance | 12:63db16fea709 | 46 | } |
duncanFrance | 12:63db16fea709 | 47 | |
duncanFrance | 12:63db16fea709 | 48 | void appendOnce(T* data) { |
duncanFrance | 12:63db16fea709 | 49 | |
duncanFrance | 12:63db16fea709 | 50 | if(_first == NULL) { |
duncanFrance | 12:63db16fea709 | 51 | |
duncanFrance | 12:63db16fea709 | 52 | _first = new LinkedListNode<T>(data); |
duncanFrance | 12:63db16fea709 | 53 | |
duncanFrance | 12:63db16fea709 | 54 | } else { |
duncanFrance | 12:63db16fea709 | 55 | |
duncanFrance | 12:63db16fea709 | 56 | LinkedListNode<T>* p = _first; |
duncanFrance | 12:63db16fea709 | 57 | LinkedListNode<T>* d = new LinkedListNode<T>(data); |
duncanFrance | 12:63db16fea709 | 58 | |
duncanFrance | 12:63db16fea709 | 59 | while(p->next != NULL) { |
duncanFrance | 12:63db16fea709 | 60 | |
duncanFrance | 12:63db16fea709 | 61 | if(p->data == data) { |
duncanFrance | 12:63db16fea709 | 62 | return; |
duncanFrance | 12:63db16fea709 | 63 | } |
duncanFrance | 12:63db16fea709 | 64 | |
duncanFrance | 12:63db16fea709 | 65 | p = p->next; |
duncanFrance | 12:63db16fea709 | 66 | } |
duncanFrance | 12:63db16fea709 | 67 | |
duncanFrance | 12:63db16fea709 | 68 | p->next = d; |
duncanFrance | 12:63db16fea709 | 69 | } |
duncanFrance | 12:63db16fea709 | 70 | } |
duncanFrance | 12:63db16fea709 | 71 | void remove(T* data) { |
duncanFrance | 12:63db16fea709 | 72 | |
duncanFrance | 12:63db16fea709 | 73 | if(_first == NULL) { |
duncanFrance | 12:63db16fea709 | 74 | return; |
duncanFrance | 12:63db16fea709 | 75 | } |
duncanFrance | 12:63db16fea709 | 76 | |
duncanFrance | 12:63db16fea709 | 77 | LinkedListNode<T>* next = _first; |
duncanFrance | 12:63db16fea709 | 78 | LinkedListNode<T>* prev = _first; |
duncanFrance | 12:63db16fea709 | 79 | |
duncanFrance | 12:63db16fea709 | 80 | if(_first->data == data) { |
duncanFrance | 12:63db16fea709 | 81 | _first = _first->next; |
duncanFrance | 12:63db16fea709 | 82 | delete next; |
duncanFrance | 12:63db16fea709 | 83 | } else { |
duncanFrance | 12:63db16fea709 | 84 | next = _first->next; |
duncanFrance | 12:63db16fea709 | 85 | while(next) { |
duncanFrance | 12:63db16fea709 | 86 | if(next->data == data) { |
duncanFrance | 12:63db16fea709 | 87 | prev->next = next->next; |
duncanFrance | 12:63db16fea709 | 88 | delete next; |
duncanFrance | 12:63db16fea709 | 89 | return; |
duncanFrance | 12:63db16fea709 | 90 | } |
duncanFrance | 12:63db16fea709 | 91 | prev = next; |
duncanFrance | 12:63db16fea709 | 92 | next = next->next; |
duncanFrance | 12:63db16fea709 | 93 | } |
duncanFrance | 12:63db16fea709 | 94 | } |
duncanFrance | 12:63db16fea709 | 95 | } |
duncanFrance | 12:63db16fea709 | 96 | |
duncanFrance | 12:63db16fea709 | 97 | void clear() { |
duncanFrance | 12:63db16fea709 | 98 | LinkedListNode<T>* here = _first; |
duncanFrance | 12:63db16fea709 | 99 | LinkedListNode<T>* next; |
duncanFrance | 12:63db16fea709 | 100 | while(here != NULL) { |
duncanFrance | 12:63db16fea709 | 101 | next = here->next; |
duncanFrance | 12:63db16fea709 | 102 | delete here; |
duncanFrance | 12:63db16fea709 | 103 | here = next; |
duncanFrance | 12:63db16fea709 | 104 | } |
duncanFrance | 12:63db16fea709 | 105 | _first = NULL; |
duncanFrance | 12:63db16fea709 | 106 | } |
duncanFrance | 12:63db16fea709 | 107 | |
duncanFrance | 12:63db16fea709 | 108 | void reset() { |
duncanFrance | 12:63db16fea709 | 109 | _current = _first; |
duncanFrance | 12:63db16fea709 | 110 | } |
duncanFrance | 12:63db16fea709 | 111 | |
duncanFrance | 12:63db16fea709 | 112 | T* next() { |
duncanFrance | 12:63db16fea709 | 113 | |
duncanFrance | 12:63db16fea709 | 114 | LinkedListNode<T>* p = _current; |
duncanFrance | 12:63db16fea709 | 115 | if(p != NULL) { |
duncanFrance | 12:63db16fea709 | 116 | _current = _current->next; |
duncanFrance | 12:63db16fea709 | 117 | return p->data; |
duncanFrance | 12:63db16fea709 | 118 | } |
duncanFrance | 12:63db16fea709 | 119 | |
duncanFrance | 12:63db16fea709 | 120 | return NULL; |
duncanFrance | 12:63db16fea709 | 121 | } |
duncanFrance | 12:63db16fea709 | 122 | |
duncanFrance | 12:63db16fea709 | 123 | bool contains(T *thing) { |
duncanFrance | 12:63db16fea709 | 124 | LinkedListNode<T>* here = _first; |
duncanFrance | 12:63db16fea709 | 125 | while(here != NULL) { |
duncanFrance | 12:63db16fea709 | 126 | if(here->data == thing) { |
duncanFrance | 12:63db16fea709 | 127 | return true; |
duncanFrance | 12:63db16fea709 | 128 | } |
duncanFrance | 12:63db16fea709 | 129 | here = here->next; |
duncanFrance | 12:63db16fea709 | 130 | } |
duncanFrance | 12:63db16fea709 | 131 | return false; |
duncanFrance | 12:63db16fea709 | 132 | } |
duncanFrance | 12:63db16fea709 | 133 | |
duncanFrance | 12:63db16fea709 | 134 | |
duncanFrance | 12:63db16fea709 | 135 | protected: |
duncanFrance | 12:63db16fea709 | 136 | |
duncanFrance | 12:63db16fea709 | 137 | LinkedListNode<T>* _first; |
duncanFrance | 12:63db16fea709 | 138 | LinkedListNode<T>* _next; |
duncanFrance | 12:63db16fea709 | 139 | LinkedListNode<T>* _current; |
duncanFrance | 12:63db16fea709 | 140 | |
duncanFrance | 12:63db16fea709 | 141 | }; |
duncanFrance | 12:63db16fea709 | 142 | |
duncanFrance | 12:63db16fea709 | 143 | #endif |