source: NonGTP/Boost/boost/multi_index/detail/index_iterator.hpp @ 857

Revision 857, 4.6 KB checked in by igarcia, 18 years ago (diff)
Line 
1/* Copyright 2003-2005 Joaquín M López Muñoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * See http://www.boost.org/libs/multi_index for library home page.
7 */
8
9#ifndef BOOST_MULTI_INDEX_DETAIL_INDEX_ITERATOR_HPP
10#define BOOST_MULTI_INDEX_DETAIL_INDEX_ITERATOR_HPP
11
12#if defined(_MSC_VER)&&(_MSC_VER>=1200)
13#pragma once
14#endif
15
16#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17#include <boost/detail/workaround.hpp>
18#include <boost/multi_index/detail/index_iterator_fwd.hpp>
19#include <boost/multi_index/detail/index_proxy.hpp>
20#include <boost/multi_index/detail/safe_mode.hpp>
21#include <boost/operators.hpp>
22
23#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
24#include <boost/serialization/nvp.hpp>
25#include <boost/serialization/split_member.hpp>
26#endif
27
28namespace boost{
29
30namespace multi_index{
31
32namespace detail{
33
34/* An iterator template for nodes of multi_index::detail::index.
35 * Built with the aid boost::bidirectional_iterator_helper from
36 * boost/operators.hpp.
37 */
38
39#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
40#if BOOST_WORKAROUND(BOOST_MSVC,<1300)
41template<typename Node>
42class index_iterator:
43  public boost::bidirectional_iterator_helper<
44    index_iterator<Node>,
45    typename Node::value_type,
46    std::ptrdiff_t,
47    const typename Node::value_type*,
48    const typename Node::value_type&>,
49  public safe_iterator<index_proxy<Node> >
50#else
51template<typename Node,typename Container>
52class index_iterator:
53  public boost::bidirectional_iterator_helper<
54    index_iterator<Node,Container>,
55    typename Node::value_type,
56    std::ptrdiff_t,
57    const typename Node::value_type*,
58    const typename Node::value_type&>,
59  public safe_iterator<Container>
60#endif
61#else
62template<typename Node>
63class index_iterator:
64  public boost::bidirectional_iterator_helper<
65    index_iterator<Node>,
66    typename Node::value_type,
67    std::ptrdiff_t,
68    const typename Node::value_type*,
69    const typename Node::value_type&>
70#endif
71
72{
73#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
74public:
75
76#if BOOST_WORKAROUND(BOOST_MSVC,<1300)
77  typedef index_proxy<Node> container_type;
78#else
79  typedef Container         container_type;
80#endif
81
82private:
83  typedef safe_iterator<container_type> safe_super;
84
85public:
86  index_iterator():node(0){}
87  index_iterator(Node* node_,container_type* cont_):
88    safe_super(cont_),node(node_){}
89
90  index_iterator& operator=(const index_iterator& x)
91  {
92    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(x);
93    safe_super::operator=(x);
94    node=x.node;
95    return *this;
96  }
97
98#else
99public:
100  index_iterator(){}
101  index_iterator(Node* node_):node(node_){}
102#endif
103
104  const typename Node::value_type& operator*()const
105  {
106    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(*this);
107    BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(*this);
108    return node->value;
109  }
110
111  index_iterator& operator++()
112  {
113    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(*this);
114    BOOST_MULTI_INDEX_CHECK_INCREMENTABLE_ITERATOR(*this);
115    Node::increment(node);
116    return *this;
117  }
118
119  index_iterator& operator--()
120  {
121    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(*this);
122    BOOST_MULTI_INDEX_CHECK_DECREMENTABLE_ITERATOR(*this);
123    Node::decrement(node);
124    return *this;
125  }
126
127  friend bool operator==(const index_iterator& x,const index_iterator& y)
128  {
129    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(x);
130    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(y);
131    BOOST_MULTI_INDEX_CHECK_SAME_OWNER(x,y);
132    return x.node==y.node;
133  }
134
135  /* get_node is not to be used by the user */
136
137  Node* get_node()const{return node;}
138
139private:
140  Node* node;
141
142#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
143  /* serialization */
144
145  friend class boost::serialization::access;
146
147  BOOST_SERIALIZATION_SPLIT_MEMBER()
148
149  typedef typename Node::base_type node_base_type;
150
151  template<class Archive>
152  void save(Archive& ar,const unsigned int version)const
153  {
154    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(*this);
155    node_base_type* bnode=node;
156    ar<<serialization::make_nvp("pointer",bnode);
157  }
158
159  template<class Archive>
160  void load(Archive& ar,const unsigned int version)
161  {
162    node_base_type* bnode;
163    ar>>serialization::make_nvp("pointer",bnode);
164    node=static_cast<Node*>(bnode);
165
166#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
167    safe_super::uncheck();
168#endif
169
170  }
171#endif
172};
173
174} /* namespace multi_index::detail */
175
176} /* namespace multi_index */
177
178} /* namespace boost */
179
180#endif
Note: See TracBrowser for help on using the repository browser.