iterator.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 #define PB_ASSOC_IT_C_DEC \
00046     it_< \
00047         It0, \
00048         It1, \
00049         Has_Data, \
00050         Const>
00051 
00052 #define PB_ASSOC_OIT_T_DEC \
00053     template<class OIt0, class OIt1, bool OHas_Data, bool OConst>
00054 
00055 #define PB_ASSOC_OIT_C_DEC \
00056     it_< \
00057         OIt0, \
00058         OIt1, \
00059         OHas_Data, \
00060         OConst>
00061 
00062 template<class It0, class It1, bool Has_Data, bool Const>
00063 class it_
00064 {
00065 public:
00066 
00067   typedef typename it_value_type_traits_t::value_type value_type;
00068 
00069   typedef typename it_value_type_traits_t::reference reference;
00070 
00071   typedef
00072   typename it_value_type_traits_t::const_reference
00073   const_reference;
00074 
00075   typedef typename it_value_type_traits_t::pointer pointer;
00076 
00077   typedef typename it_value_type_traits_t::const_pointer const_pointer;
00078 
00079 public:
00080   inline
00081   it_(It0 it0 = It0(),
00082       It0 end_it0 = It0(),
00083       It1 it1 = It1()) : m_it0(it0),
00084              m_end_it0(end_it0),
00085              m_it1(it1)
00086   { }
00087 
00088   inline
00089   it_(const PB_ASSOC_IT_C_DEC& r_other) : m_it0(r_other.m_it0),
00090                       m_end_it0(r_other.m_end_it0),
00091                       m_it1(r_other.m_it1)
00092   { }
00093 
00094   PB_ASSOC_OIT_T_DEC
00095   inline
00096   it_(const PB_ASSOC_OIT_C_DEC& r_other) : m_it0(r_other.m_it0),
00097                        m_end_it0(r_other.m_end_it0),
00098                        m_it1(r_other.m_it1)
00099   { }
00100 
00101   inline bool
00102   operator==(const PB_ASSOC_IT_C_DEC& r_other) const
00103   {
00104     if (m_it0 != r_other.m_it0)
00105       return (false);
00106 
00107     if (m_it0 == m_end_it0)
00108       return (true);
00109 
00110     return (m_it1 == r_other.m_it1);
00111   }
00112 
00113   inline bool
00114   operator!=(const PB_ASSOC_IT_C_DEC& r_other) const
00115   {
00116     return (!operator==(r_other));
00117   }
00118 
00119   inline PB_ASSOC_IT_C_DEC& 
00120   operator++()
00121   {
00122     ++m_it1;
00123 
00124     if (m_it1 == m_it0->second.end())
00125       do
00126     {
00127       ++m_it0;
00128     }
00129       while (m_it0 != m_end_it0&&  m_it0->second.empty());
00130 
00131     if (m_it0 != m_end_it0&&  !m_it0->second.empty())
00132       m_it1 = m_it0->second.begin();
00133 
00134     return (*this);
00135   }
00136 
00137   inline PB_ASSOC_IT_C_DEC
00138   operator++(int)
00139   {
00140     PB_ASSOC_IT_C_DEC ret =* this;
00141 
00142     operator++();
00143 
00144     return (ret);
00145   }
00146 
00147   inline const_pointer
00148   operator->() const
00149   {
00150     it_value_type_traits_t::make_valid(m_value_type_holder, m_it0->first, * m_it1);
00151 
00152     return (it_value_type_traits_t::recast(m_value_type_holder));
00153   }
00154 
00155   inline pointer
00156   operator->()
00157   {
00158     // Tmp Ami PB_ASSOC_STATIC_ASSERT(non_const, !Const);
00159 
00160     it_value_type_traits_t::make_valid(m_value_type_holder, m_it0->first, * m_it1);
00161 
00162     return (it_value_type_traits_t::recast(m_value_type_holder));
00163   }
00164 
00165   inline const_reference
00166   operator*() const
00167   {
00168     return (*operator->());
00169   }
00170 
00171   inline reference
00172   operator*()
00173   {
00174     PB_ASSOC_STATIC_ASSERT(non_const, !Const);
00175 
00176     return (*operator->());
00177   }
00178 
00179 public:
00180   mutable It0 m_it0;
00181   It0 m_end_it0;
00182 
00183   mutable It1 m_it1;
00184 
00185   int_to_type<Has_Data> m_has_data;
00186 
00187 private:
00188   mutable typename it_value_type_traits_t::value_type_holder m_value_type_holder;
00189 };
00190 
00191 #undef PB_ASSOC_IT_C_DEC
00192 
00193 #undef PB_ASSOC_OIT_T_DEC
00194 
00195 #undef PB_ASSOC_OIT_C_DEC
00196 

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