libstdc++
iterator.hpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the terms
00007 // of the GNU General Public License as published by the Free Software
00008 // Foundation; either version 3, or (at your option) any later
00009 // version.
00010 
00011 // This library is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00026 
00027 // Permission to use, copy, modify, sell, and distribute this software
00028 // is hereby granted without fee, provided that the above copyright
00029 // notice appears in all copies, and that both that copyright notice
00030 // and this permission notice appear in supporting documentation. None
00031 // of the above authors, nor IBM Haifa Research Laboratories, make any
00032 // representation about the suitability of this software for any
00033 // purpose. It is provided "as is" without express or implied
00034 // warranty.
00035 
00036 /**
00037  * @file iterator.hpp
00038  * Contains an iterator_ class used for ranging over the elements of the
00039  *    table.
00040  */
00041 
00042 /// Range-type iterator.
00043 class iterator_
00044 : public const_iterator_
00045 {
00046 public:
00047   /// Category.
00048   typedef std::forward_iterator_tag iterator_category;
00049 
00050   /// Difference type.
00051   typedef typename _Alloc::difference_type difference_type;
00052 
00053   /// Iterator's value type.
00054   typedef value_type_ value_type;
00055 
00056   /// Iterator's pointer type.
00057   typedef pointer_ pointer;
00058 
00059   /// Iterator's const pointer type.
00060   typedef const_pointer_ const_pointer;
00061 
00062   /// Iterator's reference type.
00063   typedef reference_ reference;
00064 
00065   /// Iterator's const reference type.
00066   typedef const_reference_ const_reference;
00067 
00068   /// Default constructor.
00069   inline
00070   iterator_()
00071   : const_iterator_(0, PB_DS_GEN_POS(), 0) { }
00072 
00073   /// Conversion to a point-type iterator.
00074   inline
00075   operator point_iterator_()
00076   { return point_iterator_(const_cast<pointer>(const_iterator_::m_p_value)); }
00077 
00078   /// Conversion to a point-type iterator.
00079   inline
00080   operator const point_iterator_() const
00081   { return point_iterator_(const_cast<pointer>(const_iterator_::m_p_value)); }
00082 
00083   /// Access.
00084   pointer
00085   operator->() const
00086   {
00087     _GLIBCXX_DEBUG_ASSERT(base_type::m_p_value != 0);
00088     return (const_cast<pointer>(base_type::m_p_value));
00089   }
00090 
00091   /// Access.
00092   reference
00093   operator*() const
00094   {
00095     _GLIBCXX_DEBUG_ASSERT(base_type::m_p_value != 0);
00096     return (const_cast<reference>(*base_type::m_p_value));
00097   }
00098 
00099   /// Increments.
00100   iterator_&
00101   operator++()
00102   {
00103     base_type::m_p_tbl->inc_it_state(base_type::m_p_value, base_type::m_pos);
00104     return *this;
00105   }
00106 
00107   /// Increments.
00108   iterator_
00109   operator++(int)
00110   {
00111     iterator_ ret =* this;
00112     base_type::m_p_tbl->inc_it_state(base_type::m_p_value, base_type::m_pos);
00113     return ret;
00114   }
00115 
00116 protected:
00117   typedef const_iterator_ base_type;
00118 
00119   /**
00120    *  Constructor used by the table to initiate the generalized
00121    *      pointer and position (e.g., this is called from within a find()
00122    *      of a table.
00123    * */
00124   inline
00125   iterator_(pointer p_value, PB_DS_GEN_POS pos, PB_DS_CLASS_C_DEC* p_tbl)
00126   : const_iterator_(p_value, pos, p_tbl)
00127   { }
00128 
00129   friend class PB_DS_CLASS_C_DEC;
00130 };