X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fintrusive_list_impl.h;h=7d71e3f78c1017b690e0b21b4a1c5b4c819a1f52;hb=131f659d91953c51823ef70c8314aa3170ce7a7e;hp=41fc72a1fa7aa7232db9924aa19f5efe3931a3f9;hpb=c7cc5558558d95b021687525d94a07476aee9fd2;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/intrusive_list_impl.h b/include/intrusive_list_impl.h index 41fc72a1f..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,6 +17,9 @@ */ +namespace insp +{ + template class INSPIRCD_INTRUSIVE_LIST_NAME { @@ -66,6 +69,9 @@ class INSPIRCD_INTRUSIVE_LIST_NAME INSPIRCD_INTRUSIVE_LIST_NAME() : listhead(NULL) +#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL + , listtail(NULL) +#endif , listsize(0) { } @@ -107,9 +113,37 @@ class INSPIRCD_INTRUSIVE_LIST_NAME 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 INSPIRCD_INTRUSIVE_LIST_NAME { 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