1d625430b11a185cba0bc2fa2b0c763bdd39efde
[senf.git] / boost / multi_index / detail / hash_index_iterator.hpp
1 /* Copyright 2003-2007 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/operators.hpp>
18
19 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
20 #include <boost/serialization/nvp.hpp>
21 #include <boost/serialization/split_member.hpp>
22 #endif
23
24 namespace boost{
25
26 namespace multi_index{
27
28 namespace detail{
29
30 /* Iterator class for hashed indices.
31  */
32
33 template<typename Node,typename BucketArray,typename Derived=mpl::na>
34 class hashed_index_iterator:
35   public forward_iterator_helper<
36     hashed_index_iterator<Node,BucketArray,Derived>,
37     typename Node::value_type,
38     std::ptrdiff_t,
39     const typename Node::value_type*,
40     const typename Node::value_type&>
41 {
42 public:
43   hashed_index_iterator(){}
44   hashed_index_iterator(Node* node_,BucketArray* buckets_):
45     node(node_),buckets(buckets_)
46   {}
47
48   const typename Node::value_type& operator*()const
49   {
50     return node->value();
51   }
52
53   hashed_index_iterator& operator++()
54   {
55     Node::increment(node,buckets->begin(),buckets->end());
56     return *this;
57   }
58
59 #if !defined(BOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
60   /* Serialization. As for why the following is public,
61    * see explanation in safe_mode_iterator notes in safe_mode.hpp.
62    */
63   
64   BOOST_SERIALIZATION_SPLIT_MEMBER()
65
66   typedef typename Node::base_type node_base_type;
67
68   template<class Archive>
69   void save(Archive& ar,const unsigned int)const
70   {
71     node_base_type* bnode=node;
72     ar<<serialization::make_nvp("pointer",bnode);
73     ar<<serialization::make_nvp("pointer",buckets);
74   }
75
76   template<class Archive>
77   void load(Archive& ar,const unsigned int)
78   {
79     node_base_type* bnode;
80     ar>>serialization::make_nvp("pointer",bnode);
81     node=static_cast<Node*>(bnode);
82     ar>>serialization::make_nvp("pointer",buckets);
83   }
84 #endif
85
86   /* get_node is not to be used by the user */
87
88   typedef Node node_type;
89
90   Node* get_node()const{return node;}
91
92 private:
93   Node*        node;
94   BucketArray* buckets;
95 };
96
97 template<typename Node,typename BucketArray,typename Derived>
98 bool operator==(
99   const hashed_index_iterator<Node,BucketArray,Derived>& x,
100   const hashed_index_iterator<Node,BucketArray,Derived>& y)
101 {
102   return x.get_node()==y.get_node();
103 }
104
105 } /* namespace multi_index::detail */
106
107 } /* namespace multi_index */
108
109 } /* namespace boost */
110
111 #endif