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/>.
20 template <typename T, typename Tag>
21 class INSPIRCD_INTRUSIVE_LIST_NAME
24 class iterator : public std::iterator<std::bidirectional_iterator_tag, T*>
34 iterator& operator++()
36 curr = curr->intrusive_list_node<T, Tag>::ptr_next;
40 iterator operator++(int)
47 iterator& operator--()
49 curr = curr->intrusive_list_node<T, Tag>::ptr_prev;
53 iterator operator--(int)
60 bool operator==(const iterator& other) const { return (curr == other.curr); }
61 bool operator!=(const iterator& other) const { return (curr != other.curr); }
62 T* operator*() const { return curr; }
65 typedef iterator const_iterator;
67 INSPIRCD_INTRUSIVE_LIST_NAME()
69 #ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
86 iterator begin() const
88 return iterator(listhead);
106 void push_front(T* x)
110 x->intrusive_list_node<T, Tag>::ptr_next = listhead;
111 listhead->intrusive_list_node<T, Tag>::ptr_prev = x;
113 #ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
120 #ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
130 x->intrusive_list_node<T, Tag>::ptr_prev = listtail;
131 listtail->intrusive_list_node<T, Tag>::ptr_next = x;
144 void erase(const iterator& it)
152 listhead = x->intrusive_list_node<T, Tag>::ptr_next;
153 #ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
155 listtail = x->intrusive_list_node<T, Tag>::ptr_prev;
157 x->intrusive_list_node<T, Tag>::unlink();
163 #ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL