const_iterator.hpp revision 169692
1118611Snjl// -*- C++ -*- 2118611Snjl 3118611Snjl// Copyright (C) 2005, 2006 Free Software Foundation, Inc. 4118611Snjl// 5118611Snjl// This file is part of the GNU ISO C++ Library. This library is free 6118611Snjl// software; you can redistribute it and/or modify it under the terms 7217365Sjkim// of the GNU General Public License as published by the Free Software 8281075Sdim// Foundation; either version 2, or (at your option) any later 9118611Snjl// version. 10118611Snjl 11217365Sjkim// This library is distributed in the hope that it will be useful, but 12217365Sjkim// WITHOUT ANY WARRANTY; without even the implied warranty of 13217365Sjkim// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14217365Sjkim// General Public License for more details. 15217365Sjkim 16217365Sjkim// You should have received a copy of the GNU General Public License 17217365Sjkim// along with this library; see the file COPYING. If not, write to 18217365Sjkim// the Free Software Foundation, 59 Temple Place - Suite 330, Boston, 19217365Sjkim// MA 02111-1307, USA. 20217365Sjkim 21217365Sjkim// As a special exception, you may use this file as part of a free 22217365Sjkim// software library without restriction. Specifically, if other files 23217365Sjkim// instantiate templates or use macros or inline functions from this 24217365Sjkim// file, or you compile this file and link it with other files to 25118611Snjl// produce an executable, this file does not by itself cause the 26217365Sjkim// resulting executable to be covered by the GNU General Public 27217365Sjkim// License. This exception does not however invalidate any other 28217365Sjkim// reasons why the executable file might be covered by the GNU General 29118611Snjl// Public License. 30217365Sjkim 31217365Sjkim// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 32217365Sjkim 33217365Sjkim// Permission to use, copy, modify, sell, and distribute this software 34217365Sjkim// is hereby granted without fee, provided that the above copyright 35217365Sjkim// notice appears in all copies, and that both that copyright notice 36217365Sjkim// and this permission notice appear in supporting documentation. None 37217365Sjkim// of the above authors, nor IBM Haifa Research Laboratories, make any 38217365Sjkim// representation about the suitability of this software for any 39217365Sjkim// purpose. It is provided "as is" without express or implied 40217365Sjkim// warranty. 41217365Sjkim 42217365Sjkim/** 43118611Snjl * @file const_iterator.hpp 44151937Sjkim * Contains an iterator class used for const ranging over the elements of the 45118611Snjl * table. 46118611Snjl */ 47193529Sjkim 48193529Sjkim// Const range-type iterator. 49193529Sjkimclass const_iterator_ : 50118611Snjl public const_point_iterator_ 51118611Snjl 52118611Snjl{ 53118611Snjl 54118611Snjlpublic: 55118611Snjl 56151937Sjkim // Category. 57118611Snjl typedef std::forward_iterator_tag iterator_category; 58151937Sjkim 59118611Snjl // Difference type. 60151937Sjkim typedef typename Allocator::difference_type difference_type; 61151937Sjkim 62151937Sjkim // Iterator's value type. 63151937Sjkim typedef value_type_ value_type; 64151937Sjkim 65151937Sjkim // Iterator's pointer type. 66151937Sjkim typedef pointer_ pointer; 67151937Sjkim 68151937Sjkim // Iterator's const pointer type. 69151937Sjkim typedef const_pointer_ const_pointer; 70151937Sjkim 71151937Sjkim // Iterator's reference type. 72151937Sjkim typedef reference_ reference; 73151937Sjkim 74151937Sjkim // Iterator's const reference type. 75151937Sjkim typedef const_reference_ const_reference; 76151937Sjkim 77151937Sjkimpublic: 78151937Sjkim 79151937Sjkim // Default constructor. 80151937Sjkim inline 81151937Sjkim const_iterator_() 82151937Sjkim 83151937Sjkim : m_p_tbl(NULL) 84151937Sjkim { } 85151937Sjkim 86151937Sjkim // Increments. 87151937Sjkim inline const_iterator_& 88151937Sjkim operator++() 89151937Sjkim { 90151937Sjkim m_p_tbl->inc_it_state(base_type::m_p_value, m_pos); 91118611Snjl 92118611Snjl return (*this); 93118611Snjl } 94118611Snjl 95118611Snjl // Increments. 96118611Snjl inline const_iterator_ 97118611Snjl operator++(int) 98118611Snjl { 99118611Snjl const_iterator_ ret =* this; 100118611Snjl 101118611Snjl m_p_tbl->inc_it_state(base_type::m_p_value, m_pos); 102118611Snjl 103118611Snjl return (ret); 104118611Snjl } 105118611Snjl 106118611Snjlprotected: 107118611Snjl 108118611Snjl typedef const_point_iterator_ base_type; 109118611Snjl 110151937Sjkimprotected: 111118611Snjl 112118611Snjl /** 113118611Snjl * Constructor used by the table to initiate the generalized 114118611Snjl * pointer and position (e.g., this is called from within a find() 115118611Snjl * of a table. 116118611Snjl * */ 117118611Snjl inline 118118611Snjl const_iterator_(const_pointer_ p_value, PB_DS_GEN_POS pos, const PB_DS_CLASS_C_DEC* p_tbl) : const_point_iterator_(p_value), 119118611Snjl m_p_tbl(p_tbl), 120118611Snjl m_pos(pos) 121118611Snjl { } 122118611Snjl 123118611Snjlprotected: 124118611Snjl 125167802Sjkim /** 126118611Snjl * Pointer to the table object which created the iterator (used for 127118611Snjl * incrementing its position. 128118611Snjl * */ 129241973Sjkim const PB_DS_CLASS_C_DEC* m_p_tbl; 130118611Snjl 131241973Sjkim PB_DS_GEN_POS m_pos; 132118611Snjl 133118611Snjl friend class PB_DS_CLASS_C_DEC; 134118611Snjl}; 135151937Sjkim 136151937Sjkim