1#ifndef CHAIN_H 2#define CHAIN_H 3/* Chain - a chain implementation; it's used for the callback management 4** throughout the code (currently TreeIterator, and AttributeIterator). 5** 6** Initial version by Axel Dörfler, axeld@pinc-software.de 7** This file may be used under the terms of the OpenBeOS License. 8*/ 9 10 11/** The Link class you want to use with the Chain class needs to have 12 * a "fNext" member which is accessable from within the Chain class. 13 */ 14 15template<class Link> class Chain { 16 public: 17 Chain() 18 : 19 fFirst(NULL) 20 { 21 } 22 23 void Add(Link *link) 24 { 25 link->fNext = fFirst; 26 fFirst = link; 27 } 28 29 void Remove(Link *link) 30 { 31 // search list for the correct callback to remove 32 Link *last = NULL,*entry; 33 for (entry = fFirst;link != entry;entry = entry->fNext) 34 last = entry; 35 if (link == entry) { 36 if (last) 37 last->fNext = link->fNext; 38 else 39 fFirst = link->fNext; 40 } 41 } 42 43 Link *Next(Link *last) 44 { 45 if (last == NULL) 46 return fFirst; 47 48 return last->fNext; 49 } 50 51 private: 52 Link *fFirst; 53}; 54 55#endif /* CHAIN_H */ 56