X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fintrusive_list_impl.h;h=7d71e3f78c1017b690e0b21b4a1c5b4c819a1f52;hb=635cb9d65f6d7f6758ae8ed874da00c8d94b6e39;hp=5e48442c55ea6813a856616f169b391b8ad907d5;hpb=7282c2250e02c3ea2da57508d885c09c9881c4f0;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/intrusive_list_impl.h b/include/intrusive_list_impl.h index 5e48442c5..7d71e3f78 100644 --- a/include/intrusive_list_impl.h +++ b/include/intrusive_list_impl.h @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2013-2014 Attila Molnar + * Copyright (C) 2014 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -17,8 +17,11 @@ */ +namespace insp +{ + template -class intrusive_list +class INSPIRCD_INTRUSIVE_LIST_NAME { public: class iterator : public std::iterator @@ -64,8 +67,11 @@ class intrusive_list typedef iterator const_iterator; - intrusive_list() + INSPIRCD_INTRUSIVE_LIST_NAME() : listhead(NULL) +#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL + , listtail(NULL) +#endif , listsize(0) { } @@ -107,9 +113,37 @@ class intrusive_list x->intrusive_list_node::ptr_next = listhead; listhead->intrusive_list_node::ptr_prev = x; } +#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL + else + listtail = x; +#endif listhead = x; } +#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL + T* back() const + { + return listtail; + } + + void push_back(T* x) + { + if (listsize++) + { + x->intrusive_list_node::ptr_prev = listtail; + listtail->intrusive_list_node::ptr_next = x; + } + else + listhead = x; + listtail = x; + } + + void pop_back() + { + erase(listtail); + } +#endif + void erase(const iterator& it) { erase(*it); @@ -119,11 +153,20 @@ class intrusive_list { if (listhead == x) listhead = x->intrusive_list_node::ptr_next; +#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL + if (listtail == x) + listtail = x->intrusive_list_node::ptr_prev; +#endif x->intrusive_list_node::unlink(); listsize--; } private: T* listhead; +#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL + T* listtail; +#endif size_t listsize; }; + +} // namespace insp