]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/intrusive_list_impl.h
Remove the Kiwi links from the readme.
[user/henk/code/inspircd.git] / include / intrusive_list_impl.h
index 41fc72a1fa7aa7232db9924aa19f5efe3931a3f9..7d71e3f78c1017b690e0b21b4a1c5b4c819a1f52 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2013-2014 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
  *
  * 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 <typename T, typename Tag>
 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<T, Tag>::ptr_next = listhead;
                        listhead->intrusive_list_node<T, Tag>::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<T, Tag>::ptr_prev = listtail;
+                       listtail->intrusive_list_node<T, Tag>::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<T, Tag>::ptr_next;
+#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
+               if (listtail == x)
+                       listtail = x->intrusive_list_node<T, Tag>::ptr_prev;
+#endif
                x->intrusive_list_node<T, Tag>::unlink();
                listsize--;
        }
 
  private:
        T* listhead;
+#ifdef INSPIRCD_INTRUSIVE_LIST_HAS_TAIL
+       T* listtail;
+#endif
        size_t listsize;
 };
+
+} // namespace insp