Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. /**
  2.     *   @brief Entity that holds a pointer to a link node and can be used in iteration structures.
  3.     */
  4.     struct LinkIterator {
  5.         LinkIterator(LinkNode* a_link) : m_link(a_link) {}
  6.         LinkNode*   m_link;                     /*LinkNode we're pointing at*/
  7.  
  8.         LinkIterator& operator--() {            /*PREFIX: Move to previous link node value*/
  9.             m_link = m_link->prev;
  10.             return *this;
  11.         }
  12.  
  13.         LinkIterator operator--(int) {          /*POSTFIX: Move to the previous link node value after leaving the expression*/
  14.             LinkNode result(*this);
  15.             --(*this);
  16.             return result;
  17.         }
  18.  
  19.         LinkIterator& operator++() {            /*PREFIX: Move to next link node value*/
  20.             m_link = m_link->m_next;
  21.             return *this;
  22.         }
  23.  
  24.         LinkIterator operator++(int) {          /*POSTFIX: Move to the next link node value after leaving the expression*/
  25.             LinkNode result(*this);
  26.             ++(*this);
  27.             return result;
  28.         }
  29.  
  30.         ///Check if the link node is the sentinel node by checking if its pointing to nullptr
  31.         bool operator==(LinkIterator a_iter) {
  32.             return (m_link == a_iter.GetLink());
  33.         }
  34.  
  35.         bool operator!=(LinkIterator a_iter) {
  36.             return (m_link != a_iter.GetLink());
  37.         }
  38.  
  39.         LinkNode* GetLink() { return m_link; }
  40.  
  41.         void EraseNode() {
  42.             delete m_link;
  43.             m_link = nullptr;
  44.         }
  45.  
  46.         T& operator*() {                        /*De-reference and return aliased value in LinkNode*/
  47.             return m_link->GetValue();
  48.         }
  49.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement