163d1a8abSmrg // -*- C++ -*-
263d1a8abSmrg 
3*ec02198aSmrg // Copyright (C) 2005-2020 Free Software Foundation, Inc.
463d1a8abSmrg //
563d1a8abSmrg // This file is part of the GNU ISO C++ Library.  This library is free
663d1a8abSmrg // software; you can redistribute it and/or modify it under the terms
763d1a8abSmrg // of the GNU General Public License as published by the Free Software
863d1a8abSmrg // Foundation; either version 3, or (at your option) any later
963d1a8abSmrg // version.
1063d1a8abSmrg 
1163d1a8abSmrg // This library is distributed in the hope that it will be useful, but
1263d1a8abSmrg // WITHOUT ANY WARRANTY; without even the implied warranty of
1363d1a8abSmrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1463d1a8abSmrg // General Public License for more details.
1563d1a8abSmrg 
1663d1a8abSmrg // Under Section 7 of GPL version 3, you are granted additional
1763d1a8abSmrg // permissions described in the GCC Runtime Library Exception, version
1863d1a8abSmrg // 3.1, as published by the Free Software Foundation.
1963d1a8abSmrg 
2063d1a8abSmrg // You should have received a copy of the GNU General Public License and
2163d1a8abSmrg // a copy of the GCC Runtime Library Exception along with this program;
2263d1a8abSmrg // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2363d1a8abSmrg // <http://www.gnu.org/licenses/>.
2463d1a8abSmrg 
2563d1a8abSmrg // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
2663d1a8abSmrg 
2763d1a8abSmrg // Permission to use, copy, modify, sell, and distribute this software
2863d1a8abSmrg // is hereby granted without fee, provided that the above copyright
2963d1a8abSmrg // notice appears in all copies, and that both that copyright notice
3063d1a8abSmrg // and this permission notice appear in supporting documentation. None
3163d1a8abSmrg // of the above authors, nor IBM Haifa Research Laboratories, make any
3263d1a8abSmrg // representation about the suitability of this software for any
3363d1a8abSmrg // purpose. It is provided "as is" without express or implied
3463d1a8abSmrg // warranty.
3563d1a8abSmrg 
3663d1a8abSmrg /**
3763d1a8abSmrg  * @file iterator.hpp
3863d1a8abSmrg  * Contains an iterator_ class used for ranging over the elements of the
3963d1a8abSmrg  * table.
40*ec02198aSmrg  *
41*ec02198aSmrg  * This file is intended to be included inside a class definition, with
42*ec02198aSmrg  * PB_DS_CLASS_C_DEC defined to the name of the enclosing class.
4363d1a8abSmrg  */
4463d1a8abSmrg 
45*ec02198aSmrg #ifdef PB_DS_CLASS_C_DEC
4663d1a8abSmrg /// Range-type iterator.
4763d1a8abSmrg class iterator_
4863d1a8abSmrg : public const_iterator_
4963d1a8abSmrg {
5063d1a8abSmrg public:
5163d1a8abSmrg   /// Category.
5263d1a8abSmrg   typedef std::forward_iterator_tag iterator_category;
5363d1a8abSmrg 
5463d1a8abSmrg   /// Difference type.
5563d1a8abSmrg   typedef typename _Alloc::difference_type difference_type;
5663d1a8abSmrg 
5763d1a8abSmrg   /// Iterator's value type.
5863d1a8abSmrg   typedef value_type_ value_type;
5963d1a8abSmrg 
6063d1a8abSmrg   /// Iterator's pointer type.
6163d1a8abSmrg   typedef pointer_ pointer;
6263d1a8abSmrg 
6363d1a8abSmrg   /// Iterator's const pointer type.
6463d1a8abSmrg   typedef const_pointer_ const_pointer;
6563d1a8abSmrg 
6663d1a8abSmrg   /// Iterator's reference type.
6763d1a8abSmrg   typedef reference_ reference;
6863d1a8abSmrg 
6963d1a8abSmrg   /// Iterator's const reference type.
7063d1a8abSmrg   typedef const_reference_ const_reference;
7163d1a8abSmrg 
7263d1a8abSmrg   /// Default constructor.
7363d1a8abSmrg   inline
iterator_()7463d1a8abSmrg   iterator_()
7563d1a8abSmrg   : const_iterator_(0, PB_DS_GEN_POS(), 0) { }
7663d1a8abSmrg 
7763d1a8abSmrg   /// Conversion to a point-type iterator.
7863d1a8abSmrg   inline
operator point_iterator_()7963d1a8abSmrg   operator point_iterator_()
8063d1a8abSmrg   { return point_iterator_(const_cast<pointer>(const_iterator_::m_p_value)); }
8163d1a8abSmrg 
8263d1a8abSmrg   /// Conversion to a point-type iterator.
8363d1a8abSmrg   inline
operator const point_iterator_() const8463d1a8abSmrg   operator const point_iterator_() const
8563d1a8abSmrg   { return point_iterator_(const_cast<pointer>(const_iterator_::m_p_value)); }
8663d1a8abSmrg 
8763d1a8abSmrg   /// Access.
8863d1a8abSmrg   pointer
operator ->() const8963d1a8abSmrg   operator->() const
9063d1a8abSmrg   {
9163d1a8abSmrg     _GLIBCXX_DEBUG_ASSERT(base_type::m_p_value != 0);
9263d1a8abSmrg     return (const_cast<pointer>(base_type::m_p_value));
9363d1a8abSmrg   }
9463d1a8abSmrg 
9563d1a8abSmrg   /// Access.
9663d1a8abSmrg   reference
operator *() const9763d1a8abSmrg   operator*() const
9863d1a8abSmrg   {
9963d1a8abSmrg     _GLIBCXX_DEBUG_ASSERT(base_type::m_p_value != 0);
10063d1a8abSmrg     return (const_cast<reference>(*base_type::m_p_value));
10163d1a8abSmrg   }
10263d1a8abSmrg 
10363d1a8abSmrg   /// Increments.
10463d1a8abSmrg   iterator_&
operator ++()10563d1a8abSmrg   operator++()
10663d1a8abSmrg   {
10763d1a8abSmrg     base_type::m_p_tbl->inc_it_state(base_type::m_p_value, base_type::m_pos);
10863d1a8abSmrg     return *this;
10963d1a8abSmrg   }
11063d1a8abSmrg 
11163d1a8abSmrg   /// Increments.
11263d1a8abSmrg   iterator_
operator ++(int)11363d1a8abSmrg   operator++(int)
11463d1a8abSmrg   {
11563d1a8abSmrg     iterator_ ret =* this;
11663d1a8abSmrg     base_type::m_p_tbl->inc_it_state(base_type::m_p_value, base_type::m_pos);
11763d1a8abSmrg     return ret;
11863d1a8abSmrg   }
11963d1a8abSmrg 
12063d1a8abSmrg protected:
12163d1a8abSmrg   typedef const_iterator_ base_type;
12263d1a8abSmrg 
12363d1a8abSmrg   /**
12463d1a8abSmrg    *  Constructor used by the table to initiate the generalized
12563d1a8abSmrg    *      pointer and position (e.g., this is called from within a find()
12663d1a8abSmrg    *      of a table.
12763d1a8abSmrg    * */
12863d1a8abSmrg   inline
iterator_(pointer p_value,PB_DS_GEN_POS pos,PB_DS_CLASS_C_DEC * p_tbl)12963d1a8abSmrg   iterator_(pointer p_value, PB_DS_GEN_POS pos, PB_DS_CLASS_C_DEC* p_tbl)
13063d1a8abSmrg   : const_iterator_(p_value, pos, p_tbl)
13163d1a8abSmrg   { }
13263d1a8abSmrg 
13363d1a8abSmrg   friend class PB_DS_CLASS_C_DEC;
13463d1a8abSmrg };
135*ec02198aSmrg #endif
136