From dad59528ccd770301b29c7db8148ff8ab8e89c92 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 14 Mar 2018 19:59:06 +0300 Subject: reverse iterators for LIST<> --- include/m_system_cpp.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'include/m_system_cpp.h') diff --git a/include/m_system_cpp.h b/include/m_system_cpp.h index c6bd65a25d..10acdebde4 100644 --- a/include/m_system_cpp.h +++ b/include/m_system_cpp.h @@ -196,6 +196,35 @@ template struct LIST return (!List_GetIndex((SortedList*)this, p, &idx)) ? -1 : idx; } + class reverse_iterator + { + int index; + T **base; + + public: + reverse_iterator(const LIST &_lst) : + index(_lst.getCount()), + base(_lst.getArray()) + { + if (index > 0) + index--; + } + + class iterator + { + T** ptr; + + public: + iterator(T **_p) : ptr(_p) {} + iterator operator++() { --ptr; return *this; } + bool operator!=(const iterator &p) { return ptr != p.ptr; } + operator T**() const { return ptr; } + }; + + __inline iterator begin() const { return iterator(base + index); } + __inline iterator end() const { return iterator(base); } + }; + __inline void destroy(void) { List_Destroy((SortedList*)this); } __inline T* find(T *p) const { return (T*)List_Find((SortedList*)this, p); } __inline int indexOf(T *p) const { return List_IndexOf((SortedList*)this, p); } @@ -210,6 +239,8 @@ template struct LIST __inline T** begin() const { return items; } __inline T** end() const { return items + count; } + __inline reverse_iterator rev_iter() const { return reverse_iterator(*this); } + protected: T** items; int count, limit, increment; -- cgit v1.2.3