src/LinkedList.hh (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
// LinkedList.hh for Blackbox - an X11 Window manager // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. #ifndef LINKEDLIST_HH #define LINKEDLIST_HH class __llist_node { private: __llist_node *next; void *data; protected: public: __llist_node(void) { next = (__llist_node *) 0; data = (void *) 0; } inline __llist_node *getNext(void) { return next; } inline void *getData(void) { return data; } inline void setData(void *d) { data = d; } inline void setNext(__llist_node *n) { next = n; } }; // forward declaration class __llist; class __llist_iterator { private: __llist *list; __llist_node *node; friend class __llist; protected: __llist_iterator(__llist *); ~__llist_iterator(void); const int set(const int); void *current(void); void reset(void); void operator++(void); void operator++(int); }; class __llist { private: int elements; __llist_node *_first, *_last; __llist *iterators; friend class __llist_iterator; protected: __llist(void * = 0); ~__llist(void); inline const int &count(void) const { return elements; } inline const int empty(void) const { return (elements == 0); } const int insert(void *, int = -1); const int remove(void *); void *find(const int); void *remove(const int); void *first(void); void *last(void); }; template <class Z> class LinkedListIterator : public __llist_iterator { public: LinkedListIterator(__llist *d = 0) : __llist_iterator(d) { return; } inline Z *current(void) { return (Z *) __llist_iterator::current(); } inline const int set(const int i) { return __llist_iterator::set(i); } inline void reset(void) { __llist_iterator::reset(); } inline void operator++(void) { __llist_iterator::operator++(); } inline void operator++(int) { __llist_iterator::operator++(0); } }; template <class Z> class LinkedList : public __llist { public: LinkedList(Z *d = 0) : __llist(d) { return; } inline Z *find(const int i) { return (Z *) __llist::find(i); } inline Z *remove(const int i) { return (Z *) __llist::remove(i); } inline Z *first(void) { return (Z *) __llist::first(); } inline Z *last(void) { return (Z *) __llist::last(); } inline const int count(void) const { return __llist::count(); } inline const int empty(void) const { return __llist::empty(); } inline const int insert(Z *d, int i = -1) { return __llist::insert((void *) d, i); } inline const int remove(Z *d) { return __llist::remove((void *) d); } }; #endif // _LINKEDLIST_HH_ |