]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/stdalgo.h
Add ipv6 dnsbl support
[user/henk/code/inspircd.git] / include / stdalgo.h
index 3cbb8635021e05042ccd4611450567c1ff90983a..3e00a4cdcd93030cdb2d3c56e1b48dac24599261 100644 (file)
@@ -75,4 +75,53 @@ namespace stdalgo
                        delete o;
                }
        };
+
+       /**
+        * Deleter that adds the item to the cull list, that is, queues it for
+        * deletion at the end of the current mainloop iteration
+        */
+       struct culldeleter
+       {
+               void operator()(classbase* item);
+       };
+
+       /**
+        * Deletes all elements in a container using operator delete
+        * @param cont The container containing the elements to delete
+        */
+       template <template<typename, typename> class Cont, typename T, typename Alloc>
+       inline void delete_all(const Cont<T*, Alloc>& cont)
+       {
+               std::for_each(cont.begin(), cont.end(), defaultdeleter<T>());
+       }
+
+       /**
+        * Remove an element from a container
+        * @param cont Container to remove the element from
+        * @param val Value of the element to look for and remove
+        * @return True if the element was found and removed, false otherwise
+        */
+       template <template<typename, typename> class Cont, typename T, typename Alloc>
+       inline bool erase(Cont<T, Alloc>& cont, const T& val)
+       {
+               const typename Cont<T, Alloc>::iterator it = std::find(cont.begin(), cont.end(), val);
+               if (it != cont.end())
+               {
+                       cont.erase(it);
+                       return true;
+               }
+               return false;
+       }
+
+       /**
+        * Check if an element with the given value is in a container. Equivalent to (std::find(cont.begin(), cont.end(), val) != cont.end()).
+        * @param cont Container to find the element in
+        * @param val Value of the element to look for
+        * @return True if the element was found in the container, false otherwise
+        */
+       template <template<typename, typename> class Cont, typename T, typename Alloc>
+       inline bool isin(const Cont<T, Alloc>& cont, const T& val)
+       {
+               return (std::find(cont.begin(), cont.end(), val) != cont.end());
+       }
 }