libstdc++
binary_heap_/point_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_/point_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_FIND_ITERATOR_HPP
00043 #define PB_DS_BINARY_HEAP_CONST_FIND_ITERATOR_HPP
00044 
00045 #include <ext/pb_ds/tag_and_trait.hpp>
00046 #include <debug/debug.h>
00047 
00048 namespace __gnu_pbds
00049 {
00050   namespace detail
00051   {
00052     /// Const point-type iterator.
00053     template<typename Value_Type, typename Entry, bool Simple, 
00054          typename _Alloc>
00055     class binary_heap_point_const_iterator_
00056     {
00057     protected:
00058       typedef typename _Alloc::template rebind<Entry>::other::pointer entry_pointer;
00059 
00060     public:
00061       /// Category.
00062       typedef trivial_iterator_tag iterator_category;
00063 
00064       /// Difference type.
00065       typedef trivial_iterator_difference_type difference_type;
00066 
00067       /// Iterator's value type.
00068       typedef Value_Type value_type;
00069 
00070       /// Iterator's pointer type.
00071       typedef typename _Alloc::template rebind<value_type>::other::pointer
00072       pointer;
00073 
00074       /// Iterator's const pointer type.
00075       typedef
00076       typename _Alloc::template rebind<value_type>::other::const_pointer
00077       const_pointer;
00078 
00079       /// Iterator's reference type.
00080       typedef
00081       typename _Alloc::template rebind<value_type>::other::reference
00082       reference;
00083 
00084       /// Iterator's const reference type.
00085       typedef
00086       typename _Alloc::template rebind<value_type>::other::const_reference
00087       const_reference;
00088 
00089       inline
00090       binary_heap_point_const_iterator_(entry_pointer p_e) : m_p_e(p_e)
00091       { }
00092 
00093       /// Default constructor.
00094       inline
00095       binary_heap_point_const_iterator_() : m_p_e(0) { }
00096 
00097       /// Copy constructor.
00098       inline
00099       binary_heap_point_const_iterator_(const binary_heap_point_const_iterator_& other)
00100       : m_p_e(other.m_p_e)
00101       { }
00102 
00103       /// Access.
00104       inline const_pointer
00105       operator->() const
00106       {
00107     _GLIBCXX_DEBUG_ASSERT(m_p_e != 0);
00108     return to_ptr(integral_constant<int, Simple>());
00109       }
00110 
00111       /// Access.
00112       inline const_reference
00113       operator*() const
00114       {
00115     _GLIBCXX_DEBUG_ASSERT(m_p_e != 0);
00116     return *to_ptr(integral_constant<int, Simple>());
00117       }
00118 
00119       /// Compares content to a different iterator object.
00120       inline bool
00121       operator==(const binary_heap_point_const_iterator_& other) const
00122       { return m_p_e == other.m_p_e; }
00123 
00124       /// Compares content (negatively) to a different iterator object.
00125       inline bool
00126       operator!=(const binary_heap_point_const_iterator_& other) const
00127       { return m_p_e != other.m_p_e; }
00128 
00129     private:
00130       inline const_pointer
00131       to_ptr(true_type) const
00132       { return m_p_e; }
00133 
00134       inline const_pointer
00135       to_ptr(false_type) const
00136       { return *m_p_e; }
00137 
00138     public:
00139       entry_pointer m_p_e;
00140     };
00141   } // namespace detail
00142 } // namespace __gnu_pbds
00143 
00144 #endif