]> 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 5e48442c55ea6813a856616f169b391b8ad907d5..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
  */
 
 
+namespace insp
+{
+
 template <typename T, typename Tag>
-class intrusive_list
+class INSPIRCD_INTRUSIVE_LIST_NAME
 {
  public:
        class iterator : public std::iterator<std::bidirectional_iterator_tag, T*>
@@ -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<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 intrusive_list
        {
                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