libstdc++
unordered_iterator/const_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 unordered_iterator/const_iterator.hpp
00038  * Contains an iterator class used for const ranging over the elements of the
00039  * table.
00040  */
00041 
00042 /// Const range-type iterator.
00043 class const_iterator_
00044 : public point_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   const_iterator_() : m_p_tbl(0)
00070   { }
00071 
00072   /// Increments.
00073   const_iterator_&
00074   operator++()
00075   {
00076     m_p_tbl->inc_it_state(base_type::m_p_value, m_pos);
00077     return *this;
00078   }
00079 
00080   /// Increments.
00081   const_iterator_
00082   operator++(int)
00083   {
00084     const_iterator_ ret =* this;
00085     m_p_tbl->inc_it_state(base_type::m_p_value, m_pos);
00086     return ret;
00087   }
00088 
00089 protected:
00090   typedef point_const_iterator_ base_type;
00091 
00092   /**
00093    *  Constructor used by the table to initiate the generalized
00094    *      pointer and position (e.g., this is called from within a find()
00095    *      of a table.
00096    * */
00097   const_iterator_(const_pointer_ p_value,  PB_DS_GEN_POS pos,
00098           const PB_DS_CLASS_C_DEC* p_tbl)
00099   : point_const_iterator_(p_value), m_p_tbl(p_tbl), m_pos(pos)
00100   { }
00101 
00102   /**
00103    *  Pointer to the table object which created the iterator (used for
00104    *      incrementing its position.
00105    * */
00106   const PB_DS_CLASS_C_DEC* m_p_tbl;
00107 
00108   PB_DS_GEN_POS m_pos;
00109 
00110   friend class PB_DS_CLASS_C_DEC;
00111 };