libstdc++
binary_heap_/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 binary_heap_/const_iterator.hpp
00038  * Contains an iterator class returned by the table's const find and insert
00039  *     methods.
00040  */
00041 
00042 #ifndef PB_DS_BINARY_HEAP_CONST_ITERATOR_HPP
00043 #define PB_DS_BINARY_HEAP_CONST_ITERATOR_HPP
00044 
00045 #include <ext/pb_ds/detail/binary_heap_/point_const_iterator.hpp>
00046 #include <debug/debug.h>
00047 
00048 namespace __gnu_pbds
00049 {
00050   namespace detail
00051   {
00052 #define PB_DS_BIN_HEAP_CIT_BASE \
00053     binary_heap_point_const_iterator_<Value_Type, Entry, Simple, _Alloc>
00054 
00055     /// Const point-type iterator.
00056     template<typename Value_Type,
00057          typename Entry,
00058          bool Simple,
00059          typename _Alloc>
00060     class binary_heap_const_iterator_ : public PB_DS_BIN_HEAP_CIT_BASE
00061     {
00062     private:
00063       typedef PB_DS_BIN_HEAP_CIT_BASE               base_type;
00064       typedef typename base_type::entry_pointer     entry_pointer;
00065 
00066     public:
00067       /// Category.
00068       typedef std::forward_iterator_tag         iterator_category;
00069 
00070       /// Difference type.
00071       typedef typename _Alloc::difference_type      difference_type;
00072 
00073       /// Iterator's value type.
00074       typedef typename base_type::value_type        value_type;
00075 
00076       /// Iterator's pointer type.
00077       typedef typename base_type::pointer       pointer;
00078 
00079       /// Iterator's const pointer type.
00080       typedef typename base_type::const_pointer     const_pointer;
00081 
00082       /// Iterator's reference type.
00083       typedef typename base_type::reference         reference;
00084 
00085       /// Iterator's const reference type.
00086       typedef typename base_type::const_reference   const_reference;
00087 
00088       inline
00089       binary_heap_const_iterator_(entry_pointer p_e) : base_type(p_e)
00090       { }
00091 
00092       /// Default constructor.
00093       inline
00094       binary_heap_const_iterator_()
00095       { }
00096 
00097       /// Copy constructor.
00098       inline
00099       binary_heap_const_iterator_(const binary_heap_const_iterator_& other) 
00100       : base_type(other)
00101       { }
00102 
00103       /// Compares content to a different iterator object.
00104       inline bool
00105       operator==(const binary_heap_const_iterator_& other) const
00106       { return base_type::m_p_e == other.m_p_e; }
00107 
00108       /// Compares content (negatively) to a different iterator object.
00109       inline bool
00110       operator!=(const binary_heap_const_iterator_& other) const
00111       { return base_type::m_p_e != other.m_p_e; }
00112 
00113       inline binary_heap_const_iterator_& 
00114       operator++()
00115       {
00116     _GLIBCXX_DEBUG_ASSERT(base_type::m_p_e != 0);
00117     inc();
00118     return *this;
00119       }
00120 
00121       inline binary_heap_const_iterator_
00122       operator++(int)
00123       {
00124     binary_heap_const_iterator_ ret_it(base_type::m_p_e);
00125     operator++();
00126     return ret_it;
00127       }
00128 
00129     private:
00130       void
00131       inc()
00132       { ++base_type::m_p_e; }
00133     };
00134 
00135 #undef PB_DS_BIN_HEAP_CIT_BASE
00136   } // namespace detail
00137 } // namespace __gnu_pbds
00138 
00139 #endif