libstdc++
left_child_next_sibling_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 left_child_next_sibling_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_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_ITERATOR_HPP
00043 #define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_CONST_ITERATOR_HPP
00044 
00045 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/point_const_iterator.hpp>
00046 #include <debug/debug.h>
00047 
00048 namespace __gnu_pbds
00049 {
00050   namespace detail
00051   {
00052 #define PB_DS_CLASS_C_DEC  \
00053     left_child_next_sibling_heap_const_iterator_<Node, _Alloc>
00054 
00055 #define PB_DS_BASIC_HEAP_CIT_BASE \
00056     left_child_next_sibling_heap_node_point_const_iterator_<Node, _Alloc>
00057 
00058     /// Const point-type iterator.
00059     template<typename Node, typename _Alloc>
00060     class left_child_next_sibling_heap_const_iterator_
00061     : public PB_DS_BASIC_HEAP_CIT_BASE
00062     {
00063     private:
00064       typedef PB_DS_BASIC_HEAP_CIT_BASE             base_type;
00065       typedef typename base_type::node_pointer      node_pointer;
00066 
00067     public:
00068       /// Category.
00069       typedef std::forward_iterator_tag         iterator_category;
00070 
00071       /// Difference type.
00072       typedef typename _Alloc::difference_type      difference_type;
00073 
00074       /// Iterator's value type.
00075       typedef typename base_type::value_type        value_type;
00076 
00077       /// Iterator's pointer type.
00078       typedef typename base_type::pointer       pointer;
00079 
00080       /// Iterator's const pointer type.
00081       typedef typename base_type::const_pointer     const_pointer;
00082 
00083       /// Iterator's reference type.
00084       typedef typename base_type::reference         reference;
00085 
00086       /// Iterator's const reference type.
00087       typedef typename base_type::const_reference   const_reference;
00088 
00089       inline
00090       left_child_next_sibling_heap_const_iterator_(node_pointer p_nd)
00091       : base_type(p_nd)
00092       { }
00093 
00094       /// Default constructor.
00095       inline
00096       left_child_next_sibling_heap_const_iterator_()
00097       { }
00098 
00099       /// Copy constructor.
00100       inline
00101       left_child_next_sibling_heap_const_iterator_(const PB_DS_CLASS_C_DEC& other) : base_type(other)
00102       { }
00103 
00104       /// Compares content to a different iterator object.
00105       bool
00106       operator==(const PB_DS_CLASS_C_DEC& other) const
00107       { return (base_type::m_p_nd == other.m_p_nd); }
00108 
00109       /// Compares content (negatively) to a different iterator object.
00110       bool
00111       operator!=(const PB_DS_CLASS_C_DEC& other) const
00112       { return (base_type::m_p_nd != other.m_p_nd); }
00113 
00114       PB_DS_CLASS_C_DEC&
00115       operator++()
00116       {
00117     _GLIBCXX_DEBUG_ASSERT(base_type::m_p_nd != 0);
00118     inc();
00119     return (*this);
00120       }
00121 
00122       PB_DS_CLASS_C_DEC
00123       operator++(int)
00124       {
00125     PB_DS_CLASS_C_DEC ret_it(base_type::m_p_nd);
00126     operator++();
00127     return (ret_it);
00128       }
00129 
00130     private:
00131       void
00132       inc()
00133       {
00134     if (base_type::m_p_nd->m_p_next_sibling != 0)
00135       {
00136         base_type::m_p_nd = base_type::m_p_nd->m_p_next_sibling;
00137         while (base_type::m_p_nd->m_p_l_child != 0)
00138           base_type::m_p_nd = base_type::m_p_nd->m_p_l_child;
00139         return;
00140       }
00141 
00142     while (true)
00143       {
00144         node_pointer p_next = base_type::m_p_nd;
00145         base_type::m_p_nd = base_type::m_p_nd->m_p_prev_or_parent;
00146         if (base_type::m_p_nd == 0
00147         || base_type::m_p_nd->m_p_l_child == p_next)
00148           return;
00149       }
00150       }
00151     };
00152 
00153 #undef PB_DS_CLASS_C_DEC
00154 #undef PB_DS_BASIC_HEAP_CIT_BASE
00155 
00156   } // namespace detail
00157 } // namespace __gnu_pbds
00158 
00159 #endif