correct version now... i guess i'm just tired :)
1 /* ======== SourceMM ========
2 * Copyright (C) 2004-2007 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): Pavol "PM OnoTo" Marko
8 * ============================
13 #ifndef _INCLUDE_SMM_LISTCAT_H
14 #define _INCLUDE_SMM_LISTCAT_H
21 // Only a very special-case forward iterator!
26 List<T> *m_pListRight;
27 typename List<T>::iterator m_Iter;
29 void CheckLeftEmptyOnBegin()
31 // If the left list is empty and right is valid, GoToBegin sets m_Iter to m_Left
32 // End() checks for equality to m_Right.end() so it returns false
33 // then Next() corrupts by incrementing!
35 // To avoid this, we skip left if it's empty.
36 if (m_pListLeft && m_pListLeft->empty() && m_pListRight)
38 m_Iter = m_pListRight->begin();
42 // At least one list has to be non-null!
43 ListCatIterator(List<T> *pListLeft, List<T> *pListRight) : m_pListLeft(pListLeft), m_pListRight(pListRight),
44 m_Iter(pListLeft ? pListLeft->begin() : pListRight->begin())
46 CheckLeftEmptyOnBegin();
51 m_Iter = m_pListLeft ? m_pListLeft->begin() : m_pListRight->begin();
52 CheckLeftEmptyOnBegin();
57 return m_pListRight ? (m_Iter == m_pListRight->end())
58 : (m_Iter == m_pListLeft->end());
62 ListCatIterator & operator++()
65 if (m_pListLeft && m_Iter == m_pListLeft->end())
68 m_Iter = m_pListRight->begin();
73 ListCatIterator operator++(int)
75 ListCatIterator old(*this);
78 if (m_pListLeft && m_Iter == m_pListLeft->end())
81 m_Iter = m_pListRight->begin();
87 const T & operator * () const
100 const T * operator -> () const
105 bool operator != (const typename List<T>::iterator &where) const
107 return (m_Iter != where);
109 bool operator ==(const typename List<T>::iterator &where) const
111 return (m_Iter == where);
114 ListCatIterator & operator = (const typename List<T>::iterator &where)
118 if (m_pListLeft && m_Iter == m_pListLeft->end())
121 m_Iter = m_pListRight->begin();
123 // :HACK HACK: RemoveHookById is not aware of ListCatIterator (yet? :TODO: Change it!)
124 // So we have to do this here... (look for the "Move all iterators pointing at this" section)
131 ListCatIterator & operator = (const ListCatIterator<T> &other)
133 m_Iter = other.m_Iter;
134 m_pListLeft = other.m_pListLeft;
135 m_pListRight = other.m_pListRight;
139 void SetListLeft(List<T> *pList)