node_iterators.hpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005 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
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00031 
00032 // Permission to use, copy, modify, sell, and distribute this software
00033 // is hereby granted without fee, provided that the above copyright
00034 // notice appears in all copies, and that both that copyright notice and
00035 // this permission notice appear in supporting documentation. None of
00036 // the above authors, nor IBM Haifa Research Laboratories, make any
00037 // representation about the suitability of this software for any
00038 // purpose. It is provided "as is" without express or implied warranty.
00039 
00045 class const_node_iterator
00046 {
00047 
00048 public:
00049 
00050   typedef trivial_iterator_tag iterator_category;
00051 
00052   typedef trivial_iterator_difference_type difference_type;
00053 
00054   typedef const_iterator value_type;
00055 
00056   typedef const_iterator*  pointer;
00057 
00058   typedef const_iterator*  const_pointer;
00059 
00060   typedef const_iterator&  reference;
00061 
00062   typedef const iterator&  const_reference;
00063 
00064 public:
00065   inline
00066   const_node_iterator(value_pointer p_nd = NULL, value_pointer p_begin_nd = NULL, value_pointer p_end_nd = NULL) : m_p_value(p_nd),
00067                                                            m_p_begin_value(p_begin_nd),
00068                                                            m_p_end_value(p_end_nd)
00069   { }
00070 
00071   inline const_iterator
00072   operator*() const
00073   {
00074     return (m_p_value);
00075   }
00076 
00077   inline const_node_iterator
00078   l_child() const
00079   {
00080     if (m_p_begin_value == m_p_value)
00081       return (const_node_iterator(m_p_begin_value, m_p_begin_value, m_p_begin_value));
00082 
00083     return (const_node_iterator(
00084                 mid_pointer(m_p_begin_value, m_p_value),
00085                 m_p_begin_value,
00086                 m_p_value));
00087   }
00088 
00089   inline const_node_iterator
00090   r_child() const
00091   {
00092     if (m_p_value == m_p_end_value)
00093       return (const_node_iterator(m_p_end_value, m_p_end_value, m_p_end_value));
00094 
00095     return (const_node_iterator(
00096                 mid_pointer(m_p_value + 1, m_p_end_value),
00097                 m_p_value + 1,
00098                 m_p_end_value));
00099   }
00100 
00101   inline bool
00102   operator==(const const_node_iterator& r_other) const
00103   {
00104     const bool is_end = m_p_begin_value == m_p_end_value;
00105     const bool is_other_end = r_other.m_p_begin_value == r_other.m_p_end_value;
00106 
00107     if (is_end)
00108       return (is_other_end);
00109 
00110     if (is_other_end)
00111       return (is_end);
00112 
00113     if (r_other.m_p_begin_value == r_other.m_p_end_value)
00114       return (m_p_begin_value == m_p_end_value);
00115 
00116     return (m_p_value == r_other.m_p_value);
00117   }
00118 
00119   inline bool
00120   operator!=(const const_node_iterator& r_other) const
00121   {
00122     return (!operator==(r_other));
00123   }
00124 
00125 private:
00126   friend class PB_ASSOC_CLASS_C_DEC;
00127 
00128 public:
00129   value_pointer m_p_value;
00130   value_pointer m_p_begin_value;
00131   value_pointer m_p_end_value;
00132 };
00133 
00134 class node_iterator : 
00135   public const_node_iterator
00136 
00137 {
00138 
00139 public:
00140   inline
00141   node_iterator(value_pointer p_nd = NULL, value_pointer p_begin_nd = NULL, value_pointer p_end_nd = NULL) : const_node_iterator(p_nd, p_begin_nd, p_end_nd)
00142   { }
00143 
00144   inline iterator
00145   operator*() const
00146   {
00147     return (iterator(const_node_iterator::m_p_value));
00148   }
00149 
00150   inline node_iterator
00151   l_child() const
00152   {
00153     if (const_node_iterator::m_p_begin_value == const_node_iterator::m_p_value)
00154       return (node_iterator(const_node_iterator::m_p_begin_value, const_node_iterator::m_p_begin_value, const_node_iterator::m_p_begin_value));
00155 
00156     return (node_iterator(
00157               mid_pointer(const_node_iterator::m_p_begin_value, const_node_iterator::m_p_value),
00158               const_node_iterator::m_p_begin_value,
00159               const_node_iterator::m_p_value));
00160   }
00161 
00162   inline node_iterator
00163   r_child() const
00164   {
00165     if (const_node_iterator::m_p_value == const_node_iterator::m_p_end_value)
00166       return (node_iterator(const_node_iterator::m_p_end_value, const_node_iterator::m_p_end_value, const_node_iterator::m_p_end_value));
00167 
00168     return (node_iterator(
00169               mid_pointer(const_node_iterator::m_p_value + 1, const_node_iterator::m_p_end_value),
00170               const_node_iterator::m_p_value + 1,
00171               const_node_iterator::m_p_end_value));
00172   }
00173 
00174 private:
00175 
00176   friend class PB_ASSOC_CLASS_C_DEC;
00177 };
00178 

Generated on Tue Feb 2 16:56:20 2010 for GNU C++ STL by  doxygen 1.4.7