2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013-2014 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 template <typename T, typename Tag>
24 class INSPIRCD_INTRUSIVE_LIST_NAME
27 class iterator : public std::iterator<std::bidirectional_iterator_tag, T*>
37 iterator& operator++()
39 curr = curr->intrusive_list_node<T, Tag>::ptr_next;
43 iterator operator++(int)
50 iterator& operator--()
52 curr = curr->intrusive_list_node<T, Tag>::ptr_prev;
56 iterator operator--(int)
63 bool operator==(const iterator& other) const { return (curr == other.curr); }
64 bool operator!=(const iterator& other) const { return (curr != other.curr); }
65 T* operator*() const { return curr; }
68 typedef iterator const_iterator;
70 INSPIRCD_INTRUSIVE_LIST_NAME()
72 #ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
89 iterator begin() const
91 return iterator(listhead);
109 void push_front(T* x)
113 x->intrusive_list_node<T, Tag>::ptr_next = listhead;
114 listhead->intrusive_list_node<T, Tag>::ptr_prev = x;
116 #ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
123 #ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
133 x->intrusive_list_node<T, Tag>::ptr_prev = listtail;
134 listtail->intrusive_list_node<T, Tag>::ptr_next = x;
147 void erase(const iterator& it)
155 listhead = x->intrusive_list_node<T, Tag>::ptr_next;
156 #ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
158 listtail = x->intrusive_list_node<T, Tag>::ptr_prev;
160 x->intrusive_list_node<T, Tag>::unlink();
166 #ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL