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

Revision 857, 4.9 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_HASH_INDEX_ITERATOR_HPP
10#define BOOST_MULTI_INDEX_DETAIL_HASH_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/hash_index_proxy.hpp>
19#include <boost/multi_index/detail/safe_mode.hpp>
20#include <boost/operators.hpp>
21
22#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
23#include <boost/serialization/nvp.hpp>
24#include <boost/serialization/split_member.hpp>
25#endif
26
27namespace boost{
28
29namespace multi_index{
30
31namespace detail{
32
33/* An iterator template for nodes of multi_index::detail::hashed_index.
34 * Built with the aid boost::forward_iterator_helper from
35 * boost/operators.hpp.
36 */
37
38#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
39#if BOOST_WORKAROUND(BOOST_MSVC,<1300)
40template<typename Node,typename BucketArray>
41class hashed_index_iterator:
42  public boost::forward_iterator_helper<
43    hashed_index_iterator<Node,BucketArray>,
44    typename Node::value_type,
45    std::ptrdiff_t,
46    const typename Node::value_type*,
47    const typename Node::value_type&>,
48  public safe_iterator<hashed_index_proxy<Node,BucketArray> >
49#else
50template<typename Node,typename BucketArray,typename Container>
51class hashed_index_iterator:
52  public boost::forward_iterator_helper<
53    hashed_index_iterator<Node,BucketArray,Container>,
54    typename Node::value_type,
55    std::ptrdiff_t,
56    const typename Node::value_type*,
57    const typename Node::value_type&>,
58  public safe_iterator<Container>
59#endif
60#else
61template<typename Node,typename BucketArray>
62class hashed_index_iterator:
63  public boost::forward_iterator_helper<
64    hashed_index_iterator<Node,BucketArray>,
65    typename Node::value_type,
66    std::ptrdiff_t,
67    const typename Node::value_type*,
68    const typename Node::value_type&>
69#endif
70
71{
72#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
73public:
74
75#if BOOST_WORKAROUND(BOOST_MSVC,<1300)
76  typedef hashed_index_proxy<Node,BucketArray> container_type;
77#else
78  typedef Container                            container_type;
79#endif
80
81private:
82  typedef safe_iterator<container_type> safe_super;
83
84public:
85  hashed_index_iterator():node(0),buckets(0){}
86  hashed_index_iterator(
87    Node* node_,BucketArray& buckets_,container_type* cont_):
88    safe_super(cont_),node(node_),buckets(&buckets_){}
89
90  hashed_index_iterator& operator=(const hashed_index_iterator& x)
91  {
92    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(x);
93    safe_super::operator=(x);
94    node=x.node;
95    buckets=x.buckets;
96    return *this;
97  }
98
99#else
100public:
101  hashed_index_iterator(){}
102  hashed_index_iterator(Node* node_,BucketArray& buckets_):
103    node(node_),buckets(&buckets_){}
104#endif
105
106  const typename Node::value_type& operator*()const
107  {
108    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(*this);
109    BOOST_MULTI_INDEX_CHECK_DEREFERENCEABLE_ITERATOR(*this);
110    return node->value;
111  }
112
113  hashed_index_iterator& operator++()
114  {
115    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(*this);
116    BOOST_MULTI_INDEX_CHECK_INCREMENTABLE_ITERATOR(*this);
117    Node::increment(node,buckets->begin(),buckets->end());
118    return *this;
119  }
120
121  friend bool operator==(const hashed_index_iterator& x,const hashed_index_iterator& y)
122  {
123    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(x);
124    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(y);
125    BOOST_MULTI_INDEX_CHECK_SAME_OWNER(x,y);
126    return x.node==y.node;
127  }
128
129  /* get_node is not to be used by the user */
130
131  Node* get_node()const{return node;}
132
133private:
134  Node*        node;
135  BucketArray* buckets;
136
137#if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
138  /* serialization */
139
140  friend class boost::serialization::access;
141
142  BOOST_SERIALIZATION_SPLIT_MEMBER()
143
144  typedef typename Node::base_type node_base_type;
145
146  template<class Archive>
147  void save(Archive& ar,const unsigned int version)const
148  {
149    BOOST_MULTI_INDEX_CHECK_VALID_ITERATOR(*this);
150    node_base_type* bnode=node;
151    ar<<serialization::make_nvp("pointer",bnode);
152    ar<<serialization::make_nvp("pointer",buckets);
153  }
154
155  template<class Archive>
156  void load(Archive& ar,const unsigned int version)
157  {
158    node_base_type* bnode;
159    ar>>serialization::make_nvp("pointer",bnode);
160    node=static_cast<Node*>(bnode);
161    ar>>serialization::make_nvp("pointer",buckets);
162
163#if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE)
164    safe_super::uncheck();
165#endif
166
167  }
168#endif
169};
170
171} /* namespace multi_index::detail */
172
173} /* namespace multi_index */
174
175} /* namespace boost */
176
177#endif
Note: See TracBrowser for help on using the repository browser.