BWAPI
SPAR/AIModule/SparAIModule/Utils/SafeListAdaptor.h
Go to the documentation of this file.
00001 #pragma once
00002 #include "SafeList.h"
00003 #include <boost/iterator/filter_iterator.hpp>
00004 
00005 template <class T>
00006 class ConstSafeListAdaptor
00007 {
00008 private:
00009   struct NotDeleted
00010   {
00011     bool operator()(const typename SafeList<T>::Wrapper& wrapper) const
00012     {
00013       return !wrapper.isDeleted();
00014     }
00015   };
00016 public:
00017   typedef boost::filter_iterator<NotDeleted, typename SafeList<T>::const_iterator> const_iterator;
00018 
00019   ConstSafeListAdaptor(const SafeList<T>& safeList)
00020     : m_safeList(safeList)
00021   {
00022     assert(safeList.m_nbCurrentIterations == 0);
00023   }
00024   const_iterator unsafe_begin() const { return const_iterator(NotDeleted(), m_safeList.m_list.begin(), m_safeList.m_list.end()); }
00025   const_iterator unsafe_end() const { return const_iterator(NotDeleted(), m_safeList.m_list.end(), m_safeList.m_list.end()); }
00026 
00027 protected:
00028   const SafeList<T>& m_safeList;
00029 };
00030 
00031 template <class T>
00032 class SafeListAdaptor : public ConstSafeListAdaptor<T>
00033 {
00034 public:
00035   typedef boost::filter_iterator<NotDeleted, typename SafeList<T>::iterator> iterator;
00036 
00037   SafeListAdaptor(SafeList<T>& safeList)
00038     : ConstSafeListAdaptor(safeList)
00039     , m_safeList(safeList)
00040   {}
00041   iterator unsafe_begin() { return iterator(NotDeleted(), m_safeList.m_list.begin(), m_safeList.m_list.end()); }
00042   iterator unsafe_end() { return iterator(NotDeleted(), m_safeList.m_list.end(), m_safeList.m_list.end()); }
00043 
00044 protected:
00045   SafeList<T>& m_safeList;
00046 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines